-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
116 lines (104 loc) · 3.66 KB
/
Game.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
#include "Game.h"
#include <fstream>
#include <random>
#include <sstream>
using namespace std;
Game::Game() {}
Game::Game(const string &f) {}
void Game::loadFile(const string &f) {
vector<string> readLine;
ifstream file;
file.open(f);
if (file.is_open()) {
for (string buf; getline(file, buf);) {
readLine.push_back(buf);
}
file.close();
}
if (!readLine.empty()) {
stringstream ss;
bool buildMap = true;
for (uint16_t i = 0; i < readLine.size(); i++) {
string line = readLine[i];
ss << line;
if (i == 0) { // first line
ss << readLine[0];
ss >> mapName >> rounds >> numOfPlayers;
continue;
} else if (line[0] == 'p' && line[1] == 'l') { // player state
buildMap = false;
string ignore;
ss >> ignore >> nowPlaying;
continue;
}
// build map input
if (buildMap) {
int32_t loc, type, price;
string name;
ss >> loc >> name >> type;
if (type >= 0) { // std build
ss >> price;
vector<int32_t> tax;
for (int32_t taxBuf; ss >> taxBuf;) {
tax.push_back(taxBuf);
}
Building b(loc, name, type, price, 0, -1, tax);
map.push_back(b);
} else { // fate or chance
Building b(loc, name, type);
map.push_back(b);
}
} else { // player input
/* TODO */
}
}
}
}
void Game::saveFile() const {}
const bool Game::isEnd() const { return false; }
const int32_t Game::rollDice() const {
random_device seed;
mt19937_64 gen(seed());
uniform_int_distribution<int> distribute(1, 6);
return distribute(gen);
}
void Game::draw() const { /* TODO */
}
void Game::rollDicePhase() {
// get player
Player &now = playerList[nowPlaying];
// move
//now.setLoc((now.getLoc += rollDice()) % map.size());
}
void Game::estatePhase(const string &action) {
Player &now = playerList[nowPlaying];
/* if (map[now.getLoc()].getType < 0) { // fate or chance
fateChancePhase();
} else { // buy or give tax
if (map[now.getLoc()].getOwner() > 0) { // building belongs to a player
// current player is not the owner
if (map[now.getLoc()].getOwner() != now.getID()) {
// give tax to another player
Player &owner = playerList[map[now.getLoc].getOwner()];
now.setDeposit(now.getDeposit() - map[now.getLoc()].getTax());
owner.setDeposit(owner.getDeposit() + map[now.getLoc()].getTax());
} else {
if (action == "Y") {
}
}
} else {
if (action == "Y") { // player buy the building
map[now.getLoc()].setOwner(now.getID());
now.setDeposit(now.getDeposit() - map[now.getLoc()].getPrice());
}
}
}*/
}
void Game::fateChancePhase() {}
const int32_t Game::getRounds() const { return rounds; }
const int32_t Game::getNumOfPlayers() const { return numOfPlayers; }
Player &Game::getPlayer() { return playerList[nowPlaying]; }
Player &Game::getPlayer(const int32_t &p) { return playerList[p]; }
void Game::setRounds(const int32_t &r) { rounds = r; }
void Game::setPlayers(const int32_t &p) { numOfPlayers = p; }
void Game::setNowPlaying(const int32_t &p) { nowPlaying = p; }