forked from AA789-ai/WarzoneGame-COMP345
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameEngineDriver.cpp
More file actions
141 lines (118 loc) · 5.26 KB
/
GameEngineDriver.cpp
File metadata and controls
141 lines (118 loc) · 5.26 KB
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
#include "GameEngine.h"
#include <iostream>
using namespace std;
// free function to test the game engine
void testGameStates(){
// Create the game engine and add the valid states
std::unique_ptr<GameEngine> game(new GameEngine());
// Register valid game states
game->registerGameState<StartState>(GameStateType::START);
game->registerGameState<MapLoadedState>(GameStateType::MAP_LOADED);
game->registerGameState<MapValidatedState>(GameStateType::MAP_VALIDATED);
game->registerGameState<PlayersAddedState>(GameStateType::PLAYERS_ADDED);
game->registerGameState<AssignReinforcementState>(GameStateType::ASSIGN_REINFORCEMENT);
game->registerGameState<IssueOrdersState>(GameStateType::ISSUE_ORDERS);
game->registerGameState<ExecuteOrdersState>(GameStateType::EXECUTE_ORDERS);
game->registerGameState<WinState>(GameStateType::WIN);
game->registerGameState<EndState>(GameStateType::END);
// Set the starting state
game->setCurrentGameState(GameStateType::START);
// loop until the end state has not been reached
while ((game->getCurrentGameState()).getGameStateId() != GameStateType::END)
{
cout << "status is " << ((game->getCurrentGameState()).getGameStateId() != GameStateType::END) ;
Command& command = game->getCommandProcessor().getCommand();
cout << "reach 1";
if (game->getCommandProcessor().validate(command, game->getCurrentGameState().getGameStateId())){
game->update(command);
} else {
printInvalidCommandError();
}
}
};
void testStartupPhase(){
// Create the game engine and add the valid states
std::unique_ptr<GameEngine> game(new GameEngine());
// Register valid game states
game->registerGameState<StartState>(GameStateType::START);
game->registerGameState<MapLoadedState>(GameStateType::MAP_LOADED);
game->registerGameState<MapValidatedState>(GameStateType::MAP_VALIDATED);
game->registerGameState<PlayersAddedState>(GameStateType::PLAYERS_ADDED);
game->registerGameState<AssignReinforcementState>(GameStateType::ASSIGN_REINFORCEMENT);
game->registerGameState<IssueOrdersState>(GameStateType::ISSUE_ORDERS);
game->registerGameState<ExecuteOrdersState>(GameStateType::EXECUTE_ORDERS);
game->registerGameState<WinState>(GameStateType::WIN);
game->registerGameState<EndState>(GameStateType::END);
// Set the starting state
game->setCurrentGameState(GameStateType::START);
game->startupPhase();
}
// free function to test the main game loop
void testMainGameLoop(){
// Create the game engine
std::unique_ptr<GameEngine> game(new GameEngine());
// Initializing North America
Continent* northAmerica = new Continent("northAmerica" , 5);
Territory* usa = new Territory("usa", 0, 0);
usa->setNumberOfArmies(0);
Territory* mexico = new Territory("mexico", 0, 0);
mexico->setNumberOfArmies(0);
northAmerica->addTerritory(usa);
northAmerica->addTerritory(mexico);
// Initializing South America
Continent* southAmerica = new Continent("southAmerica" , 10);
Territory* colombia = new Territory("colombia", 0, 0);
colombia->setNumberOfArmies(0);
Territory* brazil = new Territory("brazil", 0, 0);
brazil->setNumberOfArmies(0);
southAmerica->addTerritory(colombia);
southAmerica->addTerritory(brazil);
// Setting adjacency between territories
usa->addAdjacentTerritory(mexico);
mexico->addAdjacentTerritory(usa);
mexico->addAdjacentTerritory(colombia);
colombia->addAdjacentTerritory(mexico);
colombia->addAdjacentTerritory(brazil);
brazil->addAdjacentTerritory(colombia);
// Initializing temporary map
Map* map = new Map("test", "test", "test", "test", true, true);
map->addTerritory(usa);
map->addTerritory(mexico);
map->addTerritory(colombia);
map->addTerritory(brazil);
map->addContinent(northAmerica);
map->addContinent(southAmerica);
game->gameMap=map;
// Initializing 2 players
// Player* player1 = new Player("Aggr1", StrategyType::AggressivePlayer);
// Player* player2 = new Player("Aggr2", StrategyType::AggressivePlayer);
Player* player1 = new Player("Aggr1", StrategyType::AggressivePlayer);
Player* player2 = new Player("Bene1", StrategyType::BenevolentPlayer);
std::vector<Player*> playerList;
playerList.push_back(player1);
playerList.push_back(player2);
game->players=playerList;
// Manually assigning territories to players
player1->addTerritory(usa);
player1->addTerritory(mexico);
player2->addTerritory(colombia);
player2->addTerritory(brazil);
// Manually setting reinforcement pool to 50 for each player
player1->setReinforcementPool(50);
player2->setReinforcementPool(50);
// Manually drawing 2 cards for each player
game->deck = new Deck();
game->deck->draw(player1->getHand());
game->deck->draw(player1->getHand());
game->deck->draw(player2->getHand());
game->deck->draw(player2->getHand());
// Calling the mainGameLoop()
game->mainGameLoop(3);
}
//int main()
//{
//// testGameStates();
//// testStartupPhase();
// testMainGameLoop();
// return 0;
//};