Hearts: Move round initialization into a separate method
This commit is contained in:
parent
4e3a1f2da9
commit
9a6c6a98e5
Notes:
sideshowbarker
2024-07-18 17:24:42 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/9a6c6a98e5d Pull-request: https://github.com/SerenityOS/serenity/pull/7443
2 changed files with 19 additions and 7 deletions
|
@ -73,18 +73,16 @@ Game::Game()
|
|||
m_players[3].name_alignment = Gfx::TextAlignment::TopRight;
|
||||
m_players[3].name = "Lisa";
|
||||
m_players[3].taken_cards_target = { width, height / 2 - Card::height / 2 };
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
}
|
||||
|
||||
void Game::setup(String player_name)
|
||||
void Game::reset()
|
||||
{
|
||||
m_players[0].name = move(player_name);
|
||||
|
||||
NonnullRefPtrVector<Card> deck;
|
||||
|
||||
dbgln_if(HEARTS_DEBUG, "=====");
|
||||
dbgln_if(HEARTS_DEBUG, "Resetting game");
|
||||
|
||||
|
@ -93,6 +91,20 @@ void Game::setup(String player_name)
|
|||
m_trick.clear_with_capacity();
|
||||
m_trick_number = 0;
|
||||
|
||||
for (auto& player : m_players) {
|
||||
player.hand.clear_with_capacity();
|
||||
player.cards_taken.clear_with_capacity();
|
||||
}
|
||||
}
|
||||
|
||||
void Game::setup(String player_name)
|
||||
{
|
||||
m_players[0].name = move(player_name);
|
||||
|
||||
reset();
|
||||
|
||||
NonnullRefPtrVector<Card> deck;
|
||||
|
||||
for (int i = 0; i < Card::card_count; ++i) {
|
||||
deck.append(Card::construct(Card::Type::Clubs, i));
|
||||
deck.append(Card::construct(Card::Type::Spades, i));
|
||||
|
@ -101,8 +113,6 @@ void Game::setup(String player_name)
|
|||
}
|
||||
|
||||
for (auto& player : m_players) {
|
||||
player.hand.clear_with_capacity();
|
||||
player.cards_taken.clear_with_capacity();
|
||||
for (uint8_t i = 0; i < Card::card_count; ++i) {
|
||||
auto card = deck.take(rand() % deck.size());
|
||||
if constexpr (!HEARTS_DEBUG) {
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
private:
|
||||
Game();
|
||||
|
||||
void reset();
|
||||
|
||||
void dump_state() const;
|
||||
|
||||
void play_card(Player& player, size_t card_index);
|
||||
|
|
Loading…
Add table
Reference in a new issue