-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
120 lines (100 loc) · 3.85 KB
/
main.cc
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
#include <memory>
#include <iostream>
#include <vector>
#include "pieces/board.h"
#include "display/game.h"
#include "players/human.h"
#include "players/levelOne.h"
#include "players/levelTwo.h"
#include "shared.h"
#include "display/textObserver.h"
#include "display/graphicalObserver.h"
#include "pieces/piece.h"
#include <iostream>
#include <string>
int main() {
auto b = std::make_unique<Board>();
std::vector<Player *> players;
std::vector<Observer*> observers;
bool draw = false;
auto g = std::make_shared<Game>(b.get());
auto text = std::make_unique<TextObserver>(g, 8, 8);
auto window = std::make_unique<Xwindow>();
auto graph = std::make_unique<GraphicalObserver>(g, std::move(window), 8, 8);
auto human = std::make_unique<Human>();
auto levelOne = std::make_unique<LevelOne>(b.get());
auto levelTwo = std::make_unique<LevelTwo>(b.get());
auto playerOne = std::make_unique<Player>(WHITE, human.get()); //default
auto playerTwo = std::make_unique<Player>(BLACK, human.get()); //default
players.push_back(playerOne.get());
players.push_back(playerTwo.get());
std::string cmd;
std::cout << "WELCOME TO CHESS!" << std::endl;
std::cout << "To play a game, enter 'game [human/one/two] [human/one/two]'." << std::endl;
std::cout << "To setup the board, enter 'setup'." << std::endl;
std::cout << "Please enter your commands:" << std::endl;
while (std::cin >> cmd) {
if (cmd == "setup") {
g->customSetup();
}
else if (cmd == "game") {
std::string playerOneStr, playerTwoStr;
std::cin >> playerOneStr >> playerTwoStr;
try {
//add the player behaviour pointers
if (playerOneStr == "human") {
playerOne->setBehaviour(human.get());
}
else if (playerOneStr == "one") {
playerOne->setBehaviour(levelOne.get());
}
else if (playerOneStr == "two") {
playerOne->setBehaviour(levelTwo.get());
} else {
throw InvalidInput{"Not a type of player."};
}
if (playerTwoStr == "human") {
playerTwo->setBehaviour(human.get());
}
else if (playerTwoStr == "one") {
playerTwo->setBehaviour(levelOne.get());
}
else if (playerTwoStr == "two") {
playerTwo->setBehaviour(levelTwo.get());
} else {
throw InvalidInput{"Not a type of player."};
}
//play game
Colour winner = g->playGame(draw, players);
//determine result
if(draw) {
//increase everyone by 0.5
for (int i = 0 ; i < players.size(); i++) {
players[i]->increaseWin(0.5);
}
} else {
//increase winner points
for (int i = 0 ; i < players.size(); i++) {
if (players[i]->getColour() == winner) {
players[i]->increaseWin(1);
}
}
}
std::cout << "You're back at the main menu!" << std::endl;
} catch (InvalidInput err) {
err.printMessage();
}
}
else if (cmd == "done") {
break;
}
else {
std::cout << "Invalid command, try again." << std::endl;
}
}
std::cout << "Final score:" << std::endl;
//print out everyone's final scores
for (int i = 0 ; i < players.size(); i++) {
std::cout << getColourStr(players[i]->getColour()) << ": " << players[i]->getWins() << std::endl;
}
}