GigaPasjans
Loading...
Searching...
No Matches
Deck.h
1// Wykonane przez Piotra ChudziƄskiego w dniu 14.04.2025
2#pragma once
3
4#include <phosphorus/GameObject.h>
5#include "Card.h"
6#include "CardConstants.h"
7
8namespace Game
9{
13 class CardStack : public Phosphorus::ParentGameObject
14 {
15 private:
16 friend class Deck;
17
21 Phosphorus::Int8Parameter m_BaseStackSize;
22
23 public:
24 explicit CardStack(int32 baseStackSize);
25 ~CardStack() override = default;
26
30 void Insert(const uint32 &position, Card *card);
31
35 void Remove(Card *card);
36
40 int32 FindIndex(Card *card) const;
41
45 [[nodiscard]] Card *Top() const;
46
50 [[nodiscard]] Card *Get(int32 index) const;
51
55 [[nodiscard]] int32 GetSize() const;
56
60 [[nodiscard]] int32 GetBaseSize() const;
61
63 GameObject *clone() override;
64
66 String GetIdentifer() const override;
67
71 void Add(GameObject *object) override;
72 };
73
77 class Deck
78 {
79 private:
80 friend class GameplayScreen;
81
85 std::vector<Card *> m_Cards;
86
90 std::vector<Card *> m_OriginalLayoutCards;
91
92 int32 m_MovesRequiredToWin = -1;
93
95 struct LastMove
96 {
97 Card *card = nullptr;
98 CardStack *from = nullptr;
99 CardStack *to = nullptr;
100 };
101
102 struct LastMove m_LastMove;
104
105 public:
109 Deck() = default;
110
114 ~Deck();
115
120
124 std::array<CardStack *, TABLEAU_STACKS> Tableau;
125
129 std::array<CardStack *, TABLEAU_FOUNDATIONS> Foundations;
130
134 static Deck Random(bool useSeed = false, int32 seed = 0);
135
139 static Deck Solved();
140
144 static int32 SolvableLongMode();
145
149 static Deck Load(Phosphorus::GameObjectRegistry *registry);
150
154 void RegisterDeck(Phosphorus::GameObjectRegistry *registry) const;
155
159 bool Solve();
160
164 bool IsAllFlipped();
165
169 bool EnsureSolvable(int32 *moves = nullptr);
170 };
171} // namespace Game
Represents a playing card in a game. This class defines a card with properties such as color,...
Definition Card.h:61
Represents a stack of cards in the game.
Definition Deck.h:14
int32 GetSize() const
Returns the number of cards in the stack.
Definition Card.cpp:113
Card * Top() const
Returns the top card of the stack.
Definition Card.cpp:83
int32 FindIndex(Card *card) const
Finds the index of a specific card in the stack.
Definition Card.cpp:91
int32 GetBaseSize() const
Returns the base size of the stack.
Definition Card.cpp:176
void Remove(Card *card)
Removes the specified card from the stack.
Definition Card.cpp:81
Card * Get(int32 index) const
Returns the card at the given index.
Definition Card.cpp:93
void Add(GameObject *object) override
Adds a game object to the card stack.
Definition Card.cpp:104
void Insert(const uint32 &position, Card *card)
Inserts a card at the specified position in the stack.
Definition Card.cpp:69
GameObject * clone() override
Definition Card.cpp:179
String GetIdentifer() const override
Definition Card.cpp:181
void RegisterDeck(Phosphorus::GameObjectRegistry *registry) const
Registers the deck and its stacks to a registry.
Definition Card.cpp:372
static Deck Load(Phosphorus::GameObjectRegistry *registry)
Loads a deck from a game object registry.
Definition Card.cpp:338
bool Solve()
Attempts to solve deck (old solver).
Definition Card.cpp:395
Deck()=default
Constructs an empty deck.
std::array< CardStack *, TABLEAU_STACKS > Tableau
Array of tableau card stacks.
Definition Deck.h:124
std::array< CardStack *, TABLEAU_FOUNDATIONS > Foundations
Array of foundation card stacks.
Definition Deck.h:129
CardStack * Stock
Pointer to the stock card stack.
Definition Deck.h:119
bool IsAllFlipped()
Checks whether all cards are flipped.
Definition Card.cpp:386
bool EnsureSolvable(int32 *moves=nullptr)
Tries to solve deck.
Definition Card.cpp:115
static int32 SolvableLongMode()
Returns a seed for a solvable deck.
Definition Card.cpp:221
~Deck()
Destructor for the deck.
Definition Card.cpp:559
static Deck Solved()
Creates a solved deck with cards in right order.
Definition Card.cpp:183
static Deck Random(bool useSeed=false, int32 seed=0)
Creates a deck with cards in random order.
Definition Card.cpp:282
Storage of GameObjects (scene). GameObjectRegistry take over ownership of object.
Definition GameObject.h:372
Represents GameObject with children.
Definition GameObject.h:449
Represents a mutable sequence of characters, providing various member functions for string manipulati...
Definition String.h:16