summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/helper.cpp3
-rw-r--r--src/helper.hpp4
-rw-r--r--src/ur.cpp38
-rw-r--r--tasks.txt2
4 files changed, 36 insertions, 11 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);
}
diff --git a/tasks.txt b/tasks.txt
index 0b73751..f5468b3 100644
--- a/tasks.txt
+++ b/tasks.txt
@@ -1,5 +1,5 @@
[x] knocking back to start
-[ ] star second rolls
+[x] star second rolls
[x] star protection
[x] 0 passing
[x] scoring on final position