From 79b14ff948efe265a1d21d0f38a6371de8068b52 Mon Sep 17 00:00:00 2001 From: Stephen Enders Date: Thu, 28 Jan 2021 22:03:27 -0500 Subject: Reroll on star moves --- src/helper.cpp | 3 ++- src/helper.hpp | 4 +++- src/ur.cpp | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/helper.cpp b/src/helper.cpp index cdd9762..57e067e 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -346,7 +346,8 @@ canPlace(struct piece_t* piece, } void -clearPiece(std::shared_ptr> pieces, struct piece_t* piece) +clearPiece(std::shared_ptr> pieces, + struct piece_t* piece) { for (int i = 0; i < pieces->size(); i++) { auto& p = (*pieces)[i]; diff --git a/src/helper.hpp b/src/helper.hpp index 03d60fb..b56dc30 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -33,6 +33,7 @@ static const int NUMS_TILES[8] = { 8, 9, 10, 11, 12, 13, 14, 15 }; static const int ROLL_TILES[2] = { 20, 21 }; static const int PASS_TILES[3] = { 24, 25, 26 }; static const int START_TILES[3] = { 27, 28, 29 }; +static const int REROLL_POS[3] = { 3, 7, 13 }; static const char* TITLE = "Royal Game of Ur"; static const sf::Color GLOBAL_MASK(255, 0, 255, 255); @@ -132,6 +133,7 @@ canPlace(struct piece_t* piece, int& takenPieceId); void -clearPiece(std::shared_ptr> pieces, struct piece_t* piece); +clearPiece(std::shared_ptr> pieces, + struct piece_t* piece); #endif diff --git a/src/ur.cpp b/src/ur.cpp index c0a0c4f..68a630f 100644 --- a/src/ur.cpp +++ b/src/ur.cpp @@ -30,6 +30,13 @@ change_state(GameState next) state = next; } +inline void +change_color(std::shared_ptr> sprites, sf::Color color) +{ + for (auto& s : *sprites) + s.setColor(color); +} + // tracks the turn pids int turn_pid = P1_ID; int rolling_frame = 0; @@ -41,15 +48,20 @@ next(int* i, int max) } inline void -next_turn(std::shared_ptr> roll_sprites) +reset_turn(std::shared_ptr> roll_sprites) { turn_roll = 0; - turn_pid = turn_pid == P1_ID ? P2_ID : P1_ID; - for (auto& s : (*roll_sprites)) - s.setColor(sf::Color::White); + change_color(roll_sprites, sf::Color::White); change_state(GameState::WAITING); } +inline void +next_turn(std::shared_ptr> roll_sprites) +{ + turn_pid = turn_pid == P1_ID ? P2_ID : P1_ID; + reset_turn(roll_sprites); +} + inline bool p1_turn() { @@ -258,9 +270,7 @@ main() // setup for rolling rolling_animation_timer.start(); change_state(GameState::ROLLING); - for (auto& rs : (*roll_sprites)) { - rs.setColor(SEMI_TRANSPARENT); - } + change_color(roll_sprites, SEMI_TRANSPARENT); for (int i = 0; i < 8; i++) { (*dice)[i].show = i % 2 == 0; // only show the 0s } @@ -341,6 +351,7 @@ main() } if (in_place) { + bool reroll = false; if (grabbed_piece->position == EXIT_SPACE) { if (p1_turn()) { makeNum(&p1Score, ++p1->score, textures); @@ -349,8 +360,19 @@ main() makeNum(&p2Score, ++p2->score, textures); clearPiece(p2->pieces, grabbed_piece); } + } else { + // check if reroll + for (int p : REROLL_POS) { + if (grabbed_piece->position == p) { + reroll = true; + } + } + } + if (!reroll) { + next_turn(roll_sprites); + } else { + reset_turn(roll_sprites); } - next_turn(roll_sprites); } else { grabbed_piece->sprite.setPosition(grabbed_piece_origin); } -- cgit v1.2.3-54-g00ecf