1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:57:45 +00:00

Hearts: Add key combinations to letting the AI play for you

A single card can be played with F10 while Shift-F10 toggles the AI
for the current as well as all future tricks.
This commit is contained in:
Gunnar Beutner 2021-05-23 15:48:42 +02:00 committed by Andreas Kling
parent 2dfced2501
commit 6a194869cf
3 changed files with 11 additions and 4 deletions

View file

@ -41,6 +41,7 @@ Game::Game()
};
m_players[0].name_alignment = Gfx::TextAlignment::BottomRight;
m_players[0].name = "Gunnar";
m_players[0].is_human = true;
m_players[0].taken_cards_target = { width / 2 - Card::width / 2, height };
m_players[1].first_card_position = { outer_border_size, (height - player_deck_height) / 2 };
@ -252,7 +253,7 @@ void Game::let_player_play_card()
else
on_status_change(String::formatted("Waiting for {} to play a card...", player));
if (is_human(player)) {
if (player.is_human) {
m_human_can_play = true;
update();
return;
@ -351,13 +352,19 @@ void Game::advance_game()
void Game::keydown_event(GUI::KeyEvent& event)
{
if (event.shift() && event.key() == KeyCode::Key_F11)
if (event.shift() && event.key() == KeyCode::Key_F10) {
m_players[0].is_human = !m_players[0].is_human;
advance_game();
} else if (event.key() == KeyCode::Key_F10) {
if (m_human_can_play)
play_card(m_players[0], pick_card(m_players[0]));
} else if (event.shift() && event.key() == KeyCode::Key_F11)
dump_state();
}
void Game::play_card(Player& player, size_t card_index)
{
if (is_human(player))
if (player.is_human)
m_human_can_play = false;
VERIFY(player.hand[card_index]);
VERIFY(m_trick.size() < 4);