summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/game.cpp52
-rw-r--r--server/player.cpp1
2 files changed, 25 insertions, 28 deletions
diff --git a/server/game.cpp b/server/game.cpp
index cdfaf4f..72183bf 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -35,13 +35,10 @@ void Game::handle_ready() {
void Game::round_start() {
players[0]->round_start();
- players[0]->id = 0;
players[1]->round_start();
- players[1]->id = 1;
players[2]->round_start();
- players[2]->id = 2;
players[3]->round_start();
- players[3]->id = 3;
+
// Sett opp runden sin state
//game_state = make_shared<State>();
@@ -68,14 +65,8 @@ void Game::round_start() {
}
void Game::round_update() {
-
-
-
- if ( draw_phase ) {
-
-
-
+ if ( draw_phase ) {
if ( current_player == 3) {
current_player = 0;
} else {
@@ -106,13 +97,12 @@ void Game::round_update() {
num_player_actions++;
} else { // Run if we're in the discard phase
-
- // TODO
- // Add code for calculation of possible chi, pon, kan and ron.
- }
-
-
+ // TODO
+ // Add code for calculation of possible chi, pon, kan and ron.
+ }
+
+
// Send RoundState, inkl. liste av mulige actions.
for(int i = 0; i <= 3; i++) {
if ( i != current_player ) {
@@ -148,7 +138,6 @@ void Game::handle_action(Action action) {
#endif
-
switch ( action.type ) {
case Action::Pass: {
@@ -156,8 +145,10 @@ void Game::handle_action(Action action) {
} break;
case Action::Discard: {
- game_state.players[current_player].pond.push_back(game_state.players[current_player].hand[action.target]);
- game_state.players[current_player].hand.erase(game_state.players[current_player].hand.begin() + action.target);
+ Tile discarded_tile = game_state.players[action.player].hand[action.target];
+ game_state.players[action.player].pond.push_back(discarded_tile);
+ game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + action.target);
+
} break;
case Action::Riichi: {
@@ -195,18 +186,18 @@ void Game::handle_action(Action action) {
default:
break;
}
-
-
+
+
num_player_actions--;
-
+
+
+ if(num_player_actions == 0) {
+ round_update();
+ }
+
// Sjekk action, sjekk om endelig action er avgjort
// Oppdater state
// Evt. round_end()
- if (num_player_actions == 0) {
- // TODO
- // Add code for when someone has done a chi, pon, ron and kan.
- round_update();
- }
}
void Game::round_end() {
@@ -221,6 +212,11 @@ void Game::start() {
<< players[2]->nick() << " and "
<< players[3]->nick() << "." << std::endl;
+ players[0]->id = 0;
+ players[1]->id = 1;
+ players[2]->id = 2;
+ players[3]->id = 3;
+
waiting_players = 4;
players[0]->game_start(boost::bind(&Game::handle_ready, shared_from_this()), players);
diff --git a/server/player.cpp b/server/player.cpp
index 437d78d..6e1a7d3 100644
--- a/server/player.cpp
+++ b/server/player.cpp
@@ -72,6 +72,7 @@ void Player::game_start(boost::function<void ()> callback, std::vector<Player::p
for(std::vector<Player::p>::iterator i = players.begin(); i != players.end(); i++) {
msg->players.push_back((*i)->nick());
}
+ msg->player_id = id;
connection->send(msg);