summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Enders <smenders@gmail.com>2021-01-28 22:03:27 -0500
committerStephen Enders <smenders@gmail.com>2021-01-28 22:03:27 -0500
commit79b14ff948efe265a1d21d0f38a6371de8068b52 (patch)
tree749c7041fd9d66e4954fe2b5df2be26ab821e46d /src
parent8f02054674b582f575371702cb1ec15359b5bce5 (diff)
Reroll on star moves
Diffstat (limited to 'src')
-rw-r--r--src/helper.cpp3
-rw-r--r--src/helper.hpp4
-rw-r--r--src/ur.cpp38
3 files changed, 35 insertions, 10 deletions
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<std::vector<struct piece_t>> pieces, struct piece_t* piece)
+clearPiece(std::shared_ptr<std::vector<struct piece_t>> 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<std::vector<struct piece_t>> pieces, struct piece_t* piece);
+clearPiece(std::shared_ptr<std::vector<struct piece_t>> 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<std::vector<sf::Sprite>> 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<std::vector<sf::Sprite>> roll_sprites)
+reset_turn(std::shared_ptr<std::vector<sf::Sprite>> 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<std::vector<sf::Sprite>> 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);
}