summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorMatthew B. Jones <matthewbjones85@gmail.com>2021-06-02 16:07:12 -0600
committerGitHub <noreply@github.com>2021-06-02 23:07:12 +0100
commit3ad7a1e944106b23098f9097f12bcdc475789b61 (patch)
tree2b9049c713afa59e52928ae721f8a13746a48529 /Userland/Games
parent6f38ce8f47f3c086720eb1adc7a855a3bf91a7d1 (diff)
downloadserenity-3ad7a1e944106b23098f9097f12bcdc475789b61.zip
Hearts: Play the first valid card (left-to-right) when pressing space
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Hearts/Game.cpp16
-rw-r--r--Userland/Games/Hearts/Game.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp
index 69b68e49f4..4b10ff16fe 100644
--- a/Userland/Games/Hearts/Game.cpp
+++ b/Userland/Games/Hearts/Game.cpp
@@ -392,6 +392,19 @@ size_t Game::pick_card(Player& player)
return player.pick_max_points_card(move(ignore_card));
}
+size_t Game::pick_first_card_ltr(Player& player)
+{
+ for (size_t i = 0; i < player.hand.size(); i++) {
+ auto& card = player.hand[i];
+ if (card.is_null())
+ continue;
+ if (is_valid_play(player, *card)) {
+ return i;
+ }
+ }
+ VERIFY_NOT_REACHED();
+}
+
void Game::let_player_play_card()
{
auto& player = current_player();
@@ -567,6 +580,9 @@ void Game::keydown_event(GUI::KeyEvent& event)
play_card(m_players[0], pick_card(m_players[0]));
else if (m_state == State::PassingSelect)
select_cards_for_passing();
+ } else if (event.key() == KeyCode::Key_Space) {
+ if (m_human_can_play && m_state == State::Play)
+ play_card(m_players[0], pick_first_card_ltr(m_players[0]));
} else if (event.shift() && event.key() == KeyCode::Key_F11)
dump_state();
}
diff --git a/Userland/Games/Hearts/Game.h b/Userland/Games/Hearts/Game.h
index e9e71e1313..dfb4bdbce6 100644
--- a/Userland/Games/Hearts/Game.h
+++ b/Userland/Games/Hearts/Game.h
@@ -44,6 +44,7 @@ private:
void continue_game_after_delay(int interval_ms = 750);
void advance_game();
size_t pick_card(Player& player);
+ size_t pick_first_card_ltr(Player& player);
size_t player_index(Player& player);
Player& current_player();
bool game_ended() const { return m_trick_number == 13; }