-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.hh
109 lines (86 loc) · 1.76 KB
/
Action.hh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef Action_hh
#define Action_hh
#include "Utils.hh"
#include "PosDir.hh"
using namespace std;
/**
* Enum type for all possible actions.
*/
enum AType {
Undefined, Moving, Attacking
};
inline bool ok(AType a) {
return a == Undefined or a == Moving or a == Attacking;
}
/**
* Conversion from AType to char.
*/
inline char a2c (AType a) {
switch (a) {
case Undefined: return 'u';
case Moving: return 'm';
case Attacking: return 'a';
}
_unreachable();
}
/**
* Conversion from char to AType.
*/
inline AType c2a (char c) {
switch (c) {
case 'u': return Undefined;
case 'm': return Moving;
case 'a': return Attacking;
}
return Undefined;
}
/**
* Class that stores the actions requested by a player in a round.
*/
class Action {
friend class Game;
friend class SecGame;
friend class Board;
AType type;
Dir dir;
/**
* Constructor reading one action from a stream.
*/
Action (istream& is);
/**
* Print the action to a stream.
*/
void print (ostream& os) const;
public:
/**
* Creates an empty action.
*/
Action () : type(Undefined), dir(None)
{ }
/**
* Moves the poquemon of the player in a given direction.
*/
void move (Dir d) {
if (d != None and d != Top and d != Bottom and d != Left and d != Right) return;
if (type == Undefined) {
type = Moving;
dir = d;
} else {
cerr << "warning: another action already requested for this poquémon." << endl;
}
}
/**
* Throws an attack in a given direction.
*
*/
void attack (Dir d) {
if (d != None and d != Top and d != Bottom and d != Left and d != Right) return;
if (type == Undefined) {
type = Attacking;
dir = d;
} else {
cerr << "warning: another action already requested for this poquémon." << endl;
}
}
};
#endif