-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTank.cpp
80 lines (74 loc) · 972 Bytes
/
Tank.cpp
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
80
#include "stdafx.h"
#include "Tank.h"
Tank::Tank(int x, int y, TankType type):
type(type)
{
_x = x;
_y = y;
speed = 0;
life = 0;
Distance = SQUARE_LENGTH;
currentDir = NONE;
IsCanLauncher = true;
}
void Tank::Move(TankMoveDir dir)
{
switch (dir)
{
case LEFT:
_x -= SQUARE_LENGTH;
break;
case UP:
_y -= SQUARE_LENGTH;
break;
case RIGHT:
_x += SQUARE_LENGTH;
break;
case DOWN:
_y += SQUARE_LENGTH;
break;
case NONE:
break;
default:
break;
}
}
void Tank::setCurrentDir(TankMoveDir dir)
{
switch (dir)
{
case LEFT:
currentDir = LEFT;
break;
case UP:
currentDir = UP;
break;
case RIGHT:
currentDir = RIGHT;
break;
case DOWN:
currentDir = DOWN;
break;
case NONE:
break;
default:
break;
}
}
bool Tank::Launch()
{
static int LaunchTime = rand() % 100;
LaunchTime--;
if (LaunchTime < 0)
{
LaunchTime = rand() % 100;
return true;
}
else{
return false;
}
}
Tank::~Tank(void)
{
// nothing to do
}