summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Enders <smenders@gmail.com>2021-01-28 21:14:33 -0500
committerStephen Enders <smenders@gmail.com>2021-01-28 21:14:33 -0500
commit8f02054674b582f575371702cb1ec15359b5bce5 (patch)
tree5d6ecb75437e62d5d28629ad7ac9328ea1e4bb9d
parent6efca6678e777edacfc0bae4bf9f201d22a73860 (diff)
Score on final position
Will score and remove the piece upon moving into the final pos
-rw-r--r--src/helper.cpp12
-rw-r--r--src/helper.hpp3
-rw-r--r--src/ur.cpp12
-rw-r--r--tasks.txt2
4 files changed, 27 insertions, 2 deletions
diff --git a/src/helper.cpp b/src/helper.cpp
index ff5ed61..cdd9762 100644
--- a/src/helper.cpp
+++ b/src/helper.cpp
@@ -344,3 +344,15 @@ canPlace(struct piece_t* piece,
return true;
}
+
+void
+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];
+ if (p.id == piece->id) {
+ pieces->erase(pieces->begin() + i);
+ break;
+ }
+ }
+}
diff --git a/src/helper.hpp b/src/helper.hpp
index 41383d1..03d60fb 100644
--- a/src/helper.hpp
+++ b/src/helper.hpp
@@ -131,4 +131,7 @@ canPlace(struct piece_t* piece,
std::shared_ptr<std::vector<struct piece_t>> opponentPieces,
int& takenPieceId);
+void
+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 fac0a5f..c0a0c4f 100644
--- a/src/ur.cpp
+++ b/src/ur.cpp
@@ -45,7 +45,8 @@ next_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);
+ for (auto& s : (*roll_sprites))
+ s.setColor(sf::Color::White);
change_state(GameState::WAITING);
}
@@ -340,6 +341,15 @@ main()
}
if (in_place) {
+ if (grabbed_piece->position == EXIT_SPACE) {
+ if (p1_turn()) {
+ makeNum(&p1Score, ++p1->score, textures);
+ clearPiece(p1->pieces, grabbed_piece);
+ } else {
+ makeNum(&p2Score, ++p2->score, textures);
+ clearPiece(p2->pieces, grabbed_piece);
+ }
+ }
next_turn(roll_sprites);
} else {
grabbed_piece->sprite.setPosition(grabbed_piece_origin);
diff --git a/tasks.txt b/tasks.txt
index 538d117..0b73751 100644
--- a/tasks.txt
+++ b/tasks.txt
@@ -2,6 +2,6 @@
[ ] star second rolls
[x] star protection
[x] 0 passing
-[ ] scoring on final position
+[x] scoring on final position
[x] no overlap