-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tank.h
79 lines (64 loc) · 1.41 KB
/
Tank.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef TANKH_GUARD
#define TANKH_GUARD
#include "TankConst.h"
#include "MapObject.h"
#include <QPoint>
#include <QString>
class QPainter;
class QKeyEvent;
class QRect;
class TankWindow;
class QImage;
class Blast;
class Tank :public MapObject
{
public:
Tank(QPoint startPoint, TankWindow *tankWindow,
const TankType& type,Direction::Direction dir= Direction::up);
virtual ~Tank();
/* move */
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
/* shoot missiles */
void shoot();
/* called when its missle died */
void downMissile();
/* is it alive? */
bool isAlive();
/* return true if killed */
virtual bool kill();
/* draw itself */
virtual void drawTank(QPainter &painter);
/* if Tank is not allowed to move */
void undo();
/* set max_missile */
void upgrade();
protected:
/* move in certail direction
* return true if successfully moved
*/
virtual bool move(Direction::Direction dir);
/* move in old direction */
virtual bool move();
/* helper method to draw Tank */
void drawTankPict(QPainter &painter, QImage &tank);
/* Is tank hit other tanks? */
bool hitOtherTank();
/* Tank direction */
Direction::Direction dir;
QPoint position;
QString name;
/* how many missiles can a tank have */
int max_missile;
/* missile number */
int missile_num;
private:
QPoint old_position;
TankWindow *tankWindow;
int speed;
bool hitBarrier();
bool alive;
};
#endif