-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.cpp
38 lines (32 loc) · 962 Bytes
/
board.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
#include "board.hpp"
using namespace std;
board *board::Board = nullptr;
board::board()
: snakes({{25, 3}, {42, 1}, {56, 48}, {61, 43}, {92, 67}, {95, 12}, {98, 80}}),
ladders({{7, 30}, {16, 33}, {20, 38}, {36, 83}, {50, 68}, {63, 81}, {71, 89}, {86, 97}}),
winner(false) {
cout << "Game starts !!!" << endl;
}
board *board::getBoard() {
if (Board == nullptr) {
Board = new board();
}
return Board;
}
int board::snake_ladder(int pos, players *player) {
if (snakes.find(pos) != snakes.end()) {
cout << player->get_name() << " Bit by a snake!!!" << endl;
return snakes[pos];
} else if (ladders.find(pos) != ladders.end()) {
cout << player->get_name() << " climbed a ladder!!!" << endl;
return ladders[pos];
} else {
return pos;
}
}
int board::roll() {
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(1, 6);
return dis(gen);
}