Skip to content

Commit cee3f43

Browse files
committed
Added a player vector to the gameboard
1 parent 010d1d8 commit cee3f43

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

include/GameBoard.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class GameBoard {
2323
std::map<Coordinate, std::unique_ptr<GamePiece>> corners;
2424
std::map<Coordinate, std::unique_ptr<GamePiece>> resources;
2525
std::vector<std::unique_ptr<Road>> roads;
26+
std::vector<std::unique_ptr<Player>> players;
2627

2728
public:
28-
GameBoard();
29+
GameBoard(std::vector<std::unique_ptr<Player>>&& players);
2930
GameBoard(std::istream& in);
3031
GameBoard(GameBoard&) = delete;
3132
~GameBoard();

src/GameBoard.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ using std::map;
2121
using std::unique_ptr;
2222
using std::istream;
2323
using std::ostream;
24+
using std::vector;
2425

25-
GameBoard::GameBoard() {
26+
GameBoard::GameBoard(vector<unique_ptr<Player>>&& players) : players(std::move(players)) {
2627
init_resources();
2728
}
2829

src/main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010
#include <iostream>
1111
#include <utility>
12+
#include <vector>
13+
#include <memory>
1214

1315
#include "GameBoard.h"
1416
#include "UserInput.h"
1517
#include "Player.h"
1618
#include "Renderer.h"
1719

20+
using std::vector;
21+
using std::unique_ptr;
22+
1823
void initGame() {
1924

2025
}
@@ -58,8 +63,12 @@ int main(int argc, char *argv[]) {
5863

5964
updateViewport(1024, 768);
6065

61-
Player testPlayer("test");
62-
GameBoard testBoard;
66+
vector<unique_ptr<Player>> players;
67+
players.emplace_back(unique_ptr<Player>(new Player("test")));
68+
69+
Player& testPlayer = *(players[0]);
70+
71+
GameBoard testBoard(std::move(players));
6372

6473
bool running = true;
6574
while(running) {

tests/testSerialization.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88

99
#include <iostream>
1010
#include <sstream>
11+
#include <memory>
12+
#include <vector>
1113

14+
using std::vector;
15+
using std::unique_ptr;
1216
using std::stringstream;
1317

1418
TEST(emptyBoardSerialization) {
15-
GameBoard testBoard;
19+
vector<unique_ptr<Player>> players;
20+
players.emplace_back(unique_ptr<Player>(new Player("test")));
21+
22+
GameBoard testBoard(std::move(players));
1623

1724
stringstream stream;
1825
testBoard.save(stream);

0 commit comments

Comments
 (0)