-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathDemoGame.cpp
65 lines (51 loc) · 1.91 KB
/
DemoGame.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
/**
* This is a game that demonstrates how to use the Board class.
* You can modify it and build your own games.
*
* @author Oz Levi
* @author Erel Segal-Halevi
* @since 2020-05
*/
#include "DemoGame.hpp"
#include "FootSoldier.hpp"
#include "FootCommander.hpp"
#include <cassert>
namespace WarGame {
DemoGame::DemoGame(): board (numRows, numCols) {
// Add soldiers for player 1:
//assert(!board.has_soldiers(1));
board[{0,1}] = new FootSoldier(1);
board[{0,3}] = new FootCommander(1);
board[{0,5}] = new FootSoldier(1);
//assert(board.has_soldiers(1));
// Add soldiers for player 2:
//assert(!board.has_soldiers(2));
board[{7,1}] = new FootSoldier(2);
board[{7,3}] = new FootCommander(2);
board[{7,5}] = new FootSoldier(2);
//assert(board.has_soldiers(2));
// In your game, you can put more soldier types, such as the sniper and the paramedic types.
}
uint DemoGame::play() {
board.move(1, {0,1}, Board::MoveDIR::Up); // FootSoldier of player 1 moves forward and attacks from {0,1} to {1,1}.
if (!board.has_soldiers(2)) return 1;
board.move(2, {7,1}, Board::MoveDIR::Down); // FootSoldier of player 2 moves forward and attacks from {7,1} to {6,1}.
if (!board.has_soldiers(1)) return 2;
board.move(1, {0,3}, Board::MoveDIR::Up); // FootCommander of player 1 moves forward from {0,3} to {1,3}, and all soldiers of player 1 attack.
if (!board.has_soldiers(2)) return 1;
board.move(2, {7,3}, Board::MoveDIR::Left); // FootCommander of player 2 moves left from {7,3} to {7,2}, and all soldiers of player 2 attack.
if (!board.has_soldiers(1)) return 2;
/// Write more moves here..
// If no player won, return "tie":
return 0;
}
DemoGame::~DemoGame() {
for (int iRow=0; iRow<numRows; ++iRow) {
for (int iCol=0; iCol<numCols; ++iCol) {
Soldier* soldier = board[{iRow,iCol}];
if (soldier)
delete soldier;
}
}
}
}