Hearts: Move card click handler into a separate method
This commit is contained in:
parent
89d38b7e94
commit
fab073f33c
Notes:
sideshowbarker
2024-07-18 17:24:31 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/fab073f33ce Pull-request: https://github.com/SerenityOS/serenity/pull/7443
2 changed files with 15 additions and 8 deletions
|
@ -464,6 +464,18 @@ bool Game::are_hearts_broken() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void Game::card_clicked(size_t card_index, Card& card)
|
||||
{
|
||||
String explanation;
|
||||
if (!is_valid_play(m_players[0], card, &explanation)) {
|
||||
on_status_change(String::formatted("You can't play this card: {}", explanation));
|
||||
continue_game_after_delay();
|
||||
return;
|
||||
}
|
||||
play_card(m_players[0], card_index);
|
||||
update();
|
||||
}
|
||||
|
||||
void Game::mouseup_event(GUI::MouseEvent& event)
|
||||
{
|
||||
GUI::Frame::mouseup_event(event);
|
||||
|
@ -479,14 +491,7 @@ void Game::mouseup_event(GUI::MouseEvent& event)
|
|||
if (card.is_null())
|
||||
continue;
|
||||
if (card->rect().contains(event.position())) {
|
||||
String explanation;
|
||||
if (!is_valid_play(m_players[0], *card, &explanation)) {
|
||||
on_status_change(String::formatted("You can't play this card: {}", explanation));
|
||||
continue_game_after_delay();
|
||||
return;
|
||||
}
|
||||
play_card(m_players[0], i);
|
||||
update();
|
||||
card_clicked(i, *card);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ private:
|
|||
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||
virtual void timer_event(Core::TimerEvent&) override;
|
||||
|
||||
void card_clicked(size_t card_index, Card& card);
|
||||
|
||||
Player m_players[4];
|
||||
NonnullRefPtrVector<Card> m_trick;
|
||||
Player* m_leading_player { nullptr };
|
||||
|
|
Loading…
Add table
Reference in a new issue