Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
地图初步
  • Loading branch information
handsomebsn authored May 19, 2017
1 parent cc4d385 commit 213b2f8
Show file tree
Hide file tree
Showing 21 changed files with 655 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Tank.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-05-19T10:29:41
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Tank
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
wanwu.cpp \
tank.cpp \
bullet.cpp \
boom.cpp \
mapcell.cpp \
gamemap.cpp

HEADERS += mainwindow.h \
wanwu.h \
tank.h \
bullet.h \
boom.h \
mapcell.h \
gamemap.h \
main.h

RESOURCES += \
mytank.qrc
259 changes: 259 additions & 0 deletions Tank.pro.user

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions boom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "boom.h"

boom::boom()
{

}

11 changes: 11 additions & 0 deletions boom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BOOM_H
#define BOOM_H
#include"wanwu.h"

class boom : public Wanwu
{
public:
boom();
};

#endif // BOOM_H
7 changes: 7 additions & 0 deletions bullet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "bullet.h"

bullet::bullet()
{

}

11 changes: 11 additions & 0 deletions bullet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BULLET_H
#define BULLET_H

#include"wanwu.h"
class bullet : public Wanwu
{
public:
bullet();
};

#endif // BULLET_H
32 changes: 32 additions & 0 deletions gamemap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "gamemap.h"

GameMap::GameMap()
{
for(int i=0;i<INUM;i++)
for(int j=0;j<JNUM;j++)
cells[i][j]=NULL;
for(int i=0;i<INUM;i++)
for(int j=0;j<JNUM;j++)

cells[i][j]=new Mapcell(i,j);

}\
GameMap::~GameMap(){
for(int i=0;i<INUM;i++)
for(int j=0;j<JNUM;j++)
{delete cells[i][j] ;cells[i][j]=NULL;}
}

void GameMap::Display(QPainter &paint){

paint.drawImage(QRect(0,0,WIDTH,HEIGHT),QImage(":/images/images/background.bmp"));
for(int i=0;i<INUM;i++)
for(int j=0;j<JNUM;j++)
{
if(cells[i][j]!=NULL)
cells[i][j]->Display(paint);

}

}

17 changes: 17 additions & 0 deletions gamemap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef GAMEMAP_H
#define GAMEMAP_H

#include"mapcell.h"
#include<QRect>
#include"main.h"
class GameMap
{
private:
Mapcell *cells[INUM][JNUM];
public:
GameMap();
~GameMap();
void Display(QPainter &paint);
};

#endif // GAMEMAP_H
11 changes: 11 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}
14 changes: 14 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef MAIN
#define MAIN
#define JNUM 23
#define INUM 19
#define PICWIDTH 40
#define PICHEIGHT 40
#define CELLWIDTH 40
#define CELLHEIGHT 40
#define WIDTH 40*23
#define HEIGHT 40*19


#endif // MAIN

30 changes: 30 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "mainwindow.h"
#include"QRect"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
}

MainWindow::~MainWindow()
{

}
void MainWindow::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);

setFixedSize(WIDTH,HEIGHT);
QPainter paint(this);
paint.begin(this);
gamemap.Display(paint);
paint.end();
}




void MainWindow::keyPressEvent(QKeyEvent *event){



}
26 changes: 26 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include<QKeyEvent>
#include<QPainter>
#include"main.h"
#include "gamemap.h"

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void keyPressEvent(QKeyEvent *event);
void paintEvent(QPaintEvent *event);
private:
GameMap gamemap;


};

#endif // MAINWINDOW_H
20 changes: 20 additions & 0 deletions mapcell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "mapcell.h"
QImage Mapcell::blockimage=QImage(":/images/images/map_block.bmp");

Mapcell::Mapcell()
{

}

void Mapcell::Display(QPainter &paint){

if(!this->IsDisappear())
paint.drawImage(m_rectSphere,blockimage,QRect(0,0,PICWIDTH,PICHEIGHT));
//paint.drawImage(m_rectSphere,QImage(":/images/images/map_block.bmp"),QRect(0,0,PICWIDTH,PICHEIGHT));优化代码,速度飞一般

}
void Mapcell::Move(){



}
34 changes: 34 additions & 0 deletions mapcell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef MAPCELL_H
#define MAPCELL_H

#include"wanwu.h"
#include"main.h"
class Mapcell : public Wanwu
{
public:

Mapcell();
Mapcell(int iIndex,int jIndex){


this->m_pos.setX(jIndex*CELLWIDTH+CELLWIDTH/2);
this->m_pos.setY(iIndex*CELLHEIGHT+CELLHEIGHT/2);
this->CalculateSphere();

}
// 绘图
void Display(QPainter &paint);

// 移动
void Move();
private:
static QImage blockimage;
void CalculateSphere(){
this->m_rectSphere.setRect(m_pos.x()-CELLWIDTH/2,m_pos.y()-CELLHEIGHT/2,CELLWIDTH,CELLHEIGHT);

}


};

#endif // MAPCELL_H
17 changes: 17 additions & 0 deletions mytank.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<RCC>
<qresource prefix="/images">
<file>images/background.bmp</file>
<file>images/bullet.bmp</file>
<file>images/fire.bmp</file>
<file>images/map_block.bmp</file>
<file>images/player_tank.bmp</file>
</qresource>
<qresource prefix="/sounds">
<file>sounds/death.wav</file>
<file>sounds/hit.wav</file>
<file>sounds/motor.wav</file>
<file>sounds/shoot.wav</file>
<file>sounds/start.wav</file>
<file>sounds/turret.wav</file>
</qresource>
</RCC>
7 changes: 7 additions & 0 deletions object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "object.h"

MyObject::MyObject()
{

}

37 changes: 37 additions & 0 deletions object.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef OBJECT_H
#define OBJECT_H
#include<QPoint>
#include<QRect>
enum Dir { UP, DOWN, LEFT, RIGHT };

class MyObject
{
public:
// 绘图
virtual void Display() = 0;

// 移动
virtual void Move() = 0;

// 判断是否消失
virtual bool IsDisappear() = 0;

protected:
// 计算势力范围
virtual void CalculateSphere() = 0;

// 位置
Point m_pos;
// 势力范围
Rect m_rectSphere;
// 颜色
COLORREF m_color;
// 方向
Dir m_dir;
// 存在状态
bool m_bDisappear;
// 单次前进步长
int m_step;
};

#endif // OBJECT_H
7 changes: 7 additions & 0 deletions tank.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "tank.h"

Tank::Tank()
{

}

10 changes: 10 additions & 0 deletions tank.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef TANK_H
#define TANK_H
#include"wanwu.h"
class Tank : public Wanwu
{
public:
Tank();
};

#endif // TANK_H
11 changes: 11 additions & 0 deletions wanwu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "wanwu.h"

bool Wanwu::IsBoom(const Wanwu &wanwu)const{
bool isok=true;
if(wanwu.m_rectSphere.left()>m_rectSphere.right()
||wanwu.m_rectSphere.right()<m_rectSphere.left()||wanwu.m_rectSphere.top()<m_rectSphere.bottom()||wanwu.m_rectSphere.bottom()>m_rectSphere.top())
isok=false;

return isok;
}

Loading

0 comments on commit 213b2f8

Please sign in to comment.