-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
225 lines (190 loc) · 8.19 KB
/
Game.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//------------------------------------------------------------------------------
// Game.h
//
// Group: Group 13717, study assistant: Pascal Nasahl
//
// Authors: Benjamin Wullschleger 0773092
// Stefan Maier 1014203
// Christopher Kopel 0730613
//------------------------------------------------------------------------------
//
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#include <iostream>
#include <vector> // Can't forward declare templates
#include <fstream>
#include "Command.h" // necessary to access Status constants
using std::string;
using std::vector;
class Field;
class Coordinates;
//------------------------------------------------------------------------------
// Class for performing the game, i.e., moving, checking the
// validity of a move, and checking if a game has been won.
//
class Game
{
private:
vector<vector<Field* > >* board_;
Coordinates* origin_;
Coordinates* pos_now_; //x and y coordinates of player
int remaining_turns_;
int max_turns_;
string finished_turns_; //these turns have already been played
bool finished_;
static const string REMAINING_STEPS_;
static const string MOVED_STEPS_;
//--------------------------------------------------------------------------
// Private standard constructor
//
Game();
//--------------------------------------------------------------------------
// Private copy constructor
//
Game(const Game& original);
//--------------------------------------------------------------------------
// This private Method executes a single move and is a helper method for
// the move AND the fastmove command.
//
// @param tmp_pos a variable which holds the coordinates of the momentary
// position
// @param go_to a variable which holds and returns the coordinates where
// the player wants to move next
// @param go_to_str a string which holds the letter which indicates the
// direction of this move (l, r, u, d)
// @param bonus saves and returns the bonus (or quicksand) points that were
// collected in this move
//
// @return int indicates if the move is valid or not
//
int singleMove(Coordinates& tmp_pos, Coordinates& go_to,
vector <Coordinates>& bonus_list, string go_to_str, int& bonus);
//--------------------------------------------------------------------------
// This methods takes the momentary coordinates and a move string and
// calculates the coordinates in which the player ends up after this move.
//
// @param position the momentary position of the player
// @param go_to returns the position where the player ends up after
// this move
// @param leaving_to the direction in which the player is leaving the
// field (l, r, u. d)
//
// @return int indicates if next field is a teleport field, any other
// regular field or an invalid field
//
int calculateNextField(Coordinates& position,
Coordinates &go_to, string go_to_str);
//--------------------------------------------------------------------------
// This method checks if the player is standing on the finished field and
// sets the finished_ member variable accordingly.
//
void setGameIsFinished();
//--------------------------------------------------------------------------
// This method converts a string from the move notation to the
// fastmove notation. For example "up" to "u" or "left" to "l"
//
// @param long_string long notation of move string
//
void longToShortMoveString(string &move_string);
//--------------------------------------------------------------------------
// This method finds the exit to a teleport field that the player is about
// to enter.
//
// @param teleport_letter the letter of the teleport field
// @param position the position of the teleport field the player is about
// to enter
// @param teleport_exit the position where the player appears after
// entering the teleport field
//
void findTeleportLocation(const string teleport_letter,
const Coordinates& position, Coordinates& teleport_exit);
//--------------------------------------------------------------------------
// This method deletes all fields of the game board.
//
void deleteFields();
public:
//--------------------------------------------------------------------------
// This is the Costructor of the Game class.
//
// @param new_board the gameboard that hoalds all the different fields
// @param turns_string strings of all turns that were already played in the
// loaded file
// @param total_turns maximum number of turns in the game
// @param start_point the position of the start field
//
Game(vector<vector<Field* > >* new_board, string turns_string,
int total_turns, Coordinates* start_point);
//--------------------------------------------------------------------------
// Destructor
//
virtual ~Game() throw();
//--------------------------------------------------------------------------
// Setter: This Method assigns a new game board to the appropriate member
// variable.
//
// @param new_board the game board which is passed to the corresponding
// member variable
//
void setBoard(vector<vector<Field*> >* new_board);
//--------------------------------------------------------------------------
// Setter: sets/updates the all the turns that were already executed
// in the game (fastmove notation)
//
// @param turns_string the string which contains all the executed turns
//
void setFinishedTurns(string turns_string);
//--------------------------------------------------------------------------
// Getter: Returns the maximum turns for the game
//
// @return int the maximum turns in this game
//
int getMaxTurns() const;
//--------------------------------------------------------------------------
// Getter: Returns the game board of the current game
//
// @return vector <vector<Field*> > the returned board
//
vector <vector<Field*> >* getBoard() const;
//--------------------------------------------------------------------------
// Getter: returns a string of commands that were already executed in this
// game (in fastmove notation)
//
// @return string the commands that were successfully executed in this game
//
string getFinishedTurns() const;
//--------------------------------------------------------------------------
// This method is executed when the player uses the move-command. It makes
// use of the single_move() method and updates the member variables of this
// class (position of player, remaining turns etc.) if the move is valid.
//
// @param go_to_string the move string that was entered by the player
//
// @return Status constant of class Command: OK or INVALID_MOVE
//
Command::Status move(string direction);
//--------------------------------------------------------------------------
// This method is executed when the player uses the fastmove-command.
// It makes
// use of the single_move() method for every letter in the string. If the
// series of single moves is valid, it updates the member variables of this
// class (position of player, remaining turns etc.).
//
// @param all_moves_str the fastmove string entered by the player
//
// @return Status constant of class Command: OK or INVALID_MOVE
//
Command::Status fastMove(string direction);
//--------------------------------------------------------------------------
// This method resets the game, i.e., deletes all turns and sets
// the player onto the start field.
//
void reset();
//--------------------------------------------------------------------------
// This method prints the game board to the console
//
// @param more true when remaining turns and finished moves should also be
// displayed
//
void show(bool more) const;
};
#endif