-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.cpp
182 lines (139 loc) · 3.78 KB
/
Demo.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
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
/*
* Email: sam.lazareanu@gmail.com
* ID: ****6281
* @SamuraiPolix - Samuel Lazareanu
*/
/*
* Demo file for Ex3.
*/
#include <iostream>
#include <stdexcept>
#include <vector>
#include "Catan.hpp"
#include "Player.hpp"
using std::exception, std::cout, std::endl, std::vector, std::string;
using namespace ariel;
#define NUM_OF_PLAYER 3
int main()
{
const size_t numbers[18] = {29, 29, 30, 20, 20, 21, 33, 33, 34, 24, 24, 25, 10, 10, 9, 41, 41, 42};
size_t index = 0;
// Create players
Player p1("Sam");
Player p2("Benjamin");
Player p3("Dana");
// Create Catan game
Catan catan(p1, p2, p3);
// Get Board
Board* board = catan.getBoard();
// Choose starting player
catan.ChooseStartingPlayer(0); // should print the name of the starting player, set to Sam for demo purposes.
// Print board and players
catan.printBoard();
// Place first settlements and roads
p1.placeSettlement(29, board);
p1.placeRoad(29, 30, board);
p1.endTurn(catan);
catan.printBoard();
p2.placeSettlement(20, board);
p2.placeRoad(20, 21, board);
p2.endTurn(catan);
catan.printBoard();
p3.placeSettlement(33, board);
p3.placeRoad(33, 34, board);
p3.endTurn(catan);
catan.printBoard();
p1.placeSettlement(24, board);
p1.placeRoad(24, 25, board);
p1.endTurn(catan);
catan.printBoard();
// p2 tries to place a settlement in the same location as p1 - should throw exception
try {
p2.placeSettlement(24, board);
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
// good placement
p2.placeSettlement(10, board);
// p2 tries to place a road in the same location as p1 - should throw exception
try {
p2.placeRoad(24, 25, board);
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
// p2 tries to place a road not connected to his settlement - should throw exception
try {
p2.placeRoad(0, 1, board);
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
// good placement
p2.placeRoad(10, 9, board);
p2.endTurn(catan);
catan.printBoard();
// p1 tries to place a settlement on another player's turn - should throw exception
try {
p1.placeSettlement(20, board);
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
p3.placeSettlement(41, board);
p3.placeRoad(41, 42, board);
p3.endTurn(catan);
catan.printBoard();
// p1 turn
p1.rollDice(catan);
p1.buyDevelopmentCard(catan);
p1.endTurn(catan);
catan.printBoard();
// p2 turn
p2.rollDice(catan);
p2.endTurn(catan);
catan.printBoard();
// p3 turn
p3.rollDice(catan);
p3.endTurn(catan);
catan.printBoard();
// p2 tries to roll the dice again, but it's not his turn - should throw exception
try {
p2.rollDice(catan);
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
// p1 turn
p1.rollDice(catan);
catan.printPlayers();
cout << "TRADE" << endl;
p1.trade(p2, ResourceType::Brick, ResourceType::Wood, 1, 1);
p1.endTurn(catan);
catan.printPlayers();
// p2 turn
p2.rollDice(catan);
// p2 tries to trade with p1, but doesn't have enough resources - should throw exception
try{
p2.buyDevelopmentCard(catan);
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
p2.endTurn(catan);
p1.printPoints();
p2.printPoints();
p3.printPoints();
catan.printBoard();
catan.printWinner(); // Should print None because no player reached 10 points.
// Print winner
cout << "Winner is: " << catan.printWinner() << endl;
return 0;
}