summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-05-25 12:27:53 -0400
committerAndreas Kling <kling@serenityos.org>2021-05-25 21:20:50 +0200
commit0f80e9e4dbb33e4d6988bdf5f7d23e61d6765cb9 (patch)
treec393aeb07d5b8861f26c719b1590c8fcf258e712 /Userland/Games
parentcf9094cf46755e15923e9801ee303a5fe463462e (diff)
downloadserenity-0f80e9e4dbb33e4d6988bdf5f7d23e61d6765cb9.zip
Solitaire: Tweak scoring for three-card draw mode
Currently, the player loses 100 points each time the waste stack is recycled. In three-card draw mode, it's standard to only lose 20 points after the third recycle event.
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Solitaire/Game.cpp7
-rw-r--r--Userland/Games/Solitaire/Game.h24
2 files changed, 30 insertions, 1 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp
index e63750b6c4..e794e98806 100644
--- a/Userland/Games/Solitaire/Game.cpp
+++ b/Userland/Games/Solitaire/Game.cpp
@@ -110,6 +110,7 @@ void Game::setup(Mode mode)
m_new_deck.clear();
m_new_game_animation_pile = 0;
+ m_passes_left_before_punishment = recycle_rules().passes_allowed_before_punishment;
m_score = 0;
update_score(0);
@@ -182,7 +183,11 @@ void Game::mousedown_event(GUI::MouseEvent& event)
stock.push(card);
}
- update_score(-100);
+ if (m_passes_left_before_punishment == 0)
+ update_score(recycle_rules().punishment);
+ else
+ --m_passes_left_before_punishment;
+
update(stock.bounding_box());
} else {
auto play_bounding_box = play.bounding_box();
diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h
index 72d1ed78df..b9164610ba 100644
--- a/Userland/Games/Solitaire/Game.h
+++ b/Userland/Games/Solitaire/Game.h
@@ -6,6 +6,7 @@
#pragma once
+#include <AK/Array.h>
#include <LibCards/CardStack.h>
#include <LibGUI/Frame.h>
#include <LibGUI/Painter.h>
@@ -97,6 +98,11 @@ private:
bool m_dirty { false };
};
+ struct WasteRecycleRules {
+ uint8_t passes_allowed_before_punishment { 0 };
+ int8_t punishment { 0 };
+ };
+
enum StackLocation {
Stock,
Waste,
@@ -116,6 +122,23 @@ private:
};
static constexpr Array piles = { Pile1, Pile2, Pile3, Pile4, Pile5, Pile6, Pile7 };
+ ALWAYS_INLINE const WasteRecycleRules& recycle_rules()
+ {
+ static constexpr Array<WasteRecycleRules, 2> rules { {
+ { 0, -100 },
+ { 2, -20 },
+ } };
+
+ switch (m_mode) {
+ case Mode::SingleCardDraw:
+ return rules[0];
+ case Mode::ThreeCardDraw:
+ return rules[1];
+ default:
+ VERIFY_NOT_REACHED();
+ }
+ }
+
void mark_intersecting_stacks_dirty(Card& intersecting_card);
void update_score(int to_add);
void move_card(CardStack& from, CardStack& to);
@@ -156,6 +179,7 @@ private:
uint8_t m_new_game_animation_delay { 0 };
uint32_t m_score { 0 };
+ uint8_t m_passes_left_before_punishment { 0 };
};
}