-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "boom.h" | ||
|
||
boom::boom() | ||
{ | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "bullet.h" | ||
|
||
bullet::bullet() | ||
{ | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){ | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "object.h" | ||
|
||
MyObject::MyObject() | ||
{ | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "tank.h" | ||
|
||
Tank::Tank() | ||
{ | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
Oops, something went wrong.