mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
Hearts: Move round initialization into a separate method
This commit is contained in:
parent
4e3a1f2da9
commit
9a6c6a98e5
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_alignment = Gfx::TextAlignment::TopRight;
|
||||||
m_players[3].name = "Lisa";
|
m_players[3].name = "Lisa";
|
||||||
m_players[3].taken_cards_target = { width, height / 2 - Card::height / 2 };
|
m_players[3].taken_cards_target = { width, height / 2 - Card::height / 2 };
|
||||||
|
|
||||||
|
reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
Game::~Game()
|
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, "=====");
|
||||||
dbgln_if(HEARTS_DEBUG, "Resetting game");
|
dbgln_if(HEARTS_DEBUG, "Resetting game");
|
||||||
|
|
||||||
|
@ -93,6 +91,20 @@ void Game::setup(String player_name)
|
||||||
m_trick.clear_with_capacity();
|
m_trick.clear_with_capacity();
|
||||||
m_trick_number = 0;
|
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) {
|
for (int i = 0; i < Card::card_count; ++i) {
|
||||||
deck.append(Card::construct(Card::Type::Clubs, i));
|
deck.append(Card::construct(Card::Type::Clubs, i));
|
||||||
deck.append(Card::construct(Card::Type::Spades, i));
|
deck.append(Card::construct(Card::Type::Spades, i));
|
||||||
|
@ -101,8 +113,6 @@ void Game::setup(String player_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& player : m_players) {
|
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) {
|
for (uint8_t i = 0; i < Card::card_count; ++i) {
|
||||||
auto card = deck.take(rand() % deck.size());
|
auto card = deck.take(rand() % deck.size());
|
||||||
if constexpr (!HEARTS_DEBUG) {
|
if constexpr (!HEARTS_DEBUG) {
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
private:
|
private:
|
||||||
Game();
|
Game();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
void dump_state() const;
|
void dump_state() const;
|
||||||
|
|
||||||
void play_card(Player& player, size_t card_index);
|
void play_card(Player& player, size_t card_index);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue