Brunot
Loading...
Searching...
No Matches
Table.h
Go to the documentation of this file.
1
20// ____ __ __ __
21// /\__ _\/\ \ /\ \/\ \
22// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
23// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
24// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
25// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
26// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
27
28
29#pragma once
30
31#include "Board.h"
32#include "Card.h"
33#include "Player.h"
34#include "Framework/Component.h"
35#include "Utility/GameRules.h"
36
41class Table : public Component
42{
43public:
44#pragma region static_functions
45
46#pragma endregion
47
48 Table();
49
50 Table(const Table&);
51 Table(Table&& other) noexcept;
52 auto operator=(const Table&) -> Table& = default;
53 auto operator=(Table&& other) noexcept -> Table& = default;
54 ~Table() override = default;
55
56#pragma region overriden_functions
57
58 auto clone() const -> std::unique_ptr<GameObject> override
59 {
60 return std::make_unique<Table>(*this);
61 }
62
63 auto componentShowMenu() -> void override;
64 // for debug ImGUI
65 auto onUpdate(float dt) -> void override;
66
67 auto endWindow() -> void override
68 {
69 } // for debug ImGUI
70 auto onRender() -> void override;
71 auto onEnterEngine() -> void override;
72 auto load(Stream& stream) -> void override;
73 auto save(Stream& stream) const -> void override;
74
75 friend auto to_json(json& j, const Table& t) -> void;
76 friend auto from_json(const json& j, Table& t) -> void;
77
78
79#pragma endregion
80
81#pragma region Table_functions
82
83
87 auto reloadCache() -> void;
88
93 auto dealCardToPlayer(int playerNumber) const -> void;
94
99 auto dealCardToPlayer(Player* player) const -> void;
100
105 auto fillPlayerHand(int playerNumber) const -> void;
106
111 auto fillPlayerHand(Player* player) -> void;
112
116 auto fillAllPlayerHands() -> void;
117
121 auto moveTurnForward() -> void;
122
126 auto goToWinScreen() const -> void;
127
128
129#pragma endregion
130
131private:
132#pragma region member_variables
133
135 std::vector<Player*> players;
142
144 std::vector<Card*> cardsPlayedThisTurn;
145
147 std::vector<int> playerScores;
148
150 int turn;
151
154
157
160
161
164#pragma endregion
165
166#pragma region helper_functions
167
169 auto moveSelectorToBoard() -> void;
174 auto moveSelectorToPlayer(int playerNumber) const -> void;
179 auto moveSelectorToPlayer(Player* player) const -> void;
183 auto moveSelectorToLastPlayedCard() -> void;
184
188 auto moveSelectorToLastSelectedTile() -> void;
189
194 auto updatePlayerScoreText(int playerNumber) -> void;
195
200 auto updatedCardsPlayedThisTurn() -> void;
201
205 auto updateCardsPlayedText() -> void;
206
210 auto updateCardsInDeckText() -> void;
211
217 auto getCurrentPlayerNumber() const -> int;
218
223 auto getCurrentPlayer() const -> Player*;
224
225 auto getWinningPlayer() const -> Player*;
226
231 auto arePlayersEmpty() const -> bool;
232
236 auto reloadPlayers() -> void;
237
241 auto reloadBoard() -> void;
242
246 auto reloadDeck() -> void;
247
252 auto reloadSelector() -> void;
253
257 auto resetScores() -> void;
258
259
263 auto resetTable() -> void;
264
268 auto playHandScoredSound() -> void;
269
274 auto generatePlayerScoresData() const -> Stream;
275#pragma endregion
276
277#pragma region messaging_functions
278
280 auto receiveResetTable(const Message* message) -> Message;
282 auto receiveCardSelected(const Message* message) -> Message;
284 auto receiveCardDeselected(const Message* message) -> Message;
286 auto receiveCardPlayedOnBoard(const Message* message) -> Message;
288 auto receiveEndTurn(const Message* message) -> Message;
289
290
291 /* ----------- Cheat codes ----------- */
292
294 auto receiveAddScore(const Message* message) -> Message;
296 auto receiveDrawCard(const Message* message) -> Message;
298 auto receiveGoToWinScreen(const Message* message) -> Message;
299
300 auto linkMessages() -> void;
301
302
303#pragma endregion
304
305#pragma region static_variables
306
307#pragma endregion
308
309};
sys::Json Stream
Definition AudioObject.h:20
Component that is responsible for managing the gameplay board, where cards are placed by Players.
The card component that is moved around on the board.
The base class for components, holding all of their shared All components should inherit from this.
A helper struct that contains all relevant rules for gameplay for the Table.
nlohmann::json json
Definition Json.cpp:19
The component responsible for storing information relevant to the player.
Component that is responsible for managing the gameplay board, where cards are placed by Players.
Definition Board.h:38
Definition Card.h:34
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
Component that represents a deck of playing cards.
Definition Deck.h:31
friend Entity
Definition GameObject.h:84
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
The component responsible for storing information relevant to the player.
Definition Player.h:31
The component responsible for facilitating the gameplay.
Definition Table.h:42
auto fillPlayerHand(int playerNumber) const -> void
Tells a player to draw cards until their hand is full.
Definition Table.cpp:216
Table()
Definition Table.cpp:62
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Table.cpp:167
auto playHandScoredSound() -> void
Plays the sound effect for scoring a hand.
Definition Table.cpp:537
auto arePlayersEmpty() const -> bool
Checks if all players have empty hands.
Definition Table.cpp:348
Card * lastSelectedCard
Tracker of the last selected card, so we know what we're playing.
Definition Table.h:156
auto updateCardsPlayedText() -> void
Sets the text on screen to match the "numberOfCardsPlayedThisTurn" variable.
Definition Table.cpp:435
auto receiveCardSelected(const Message *message) -> Message
Moves the selector from the player hand to the board.
Definition Table.cpp:583
std::vector< int > playerScores
Scores for each player for the current game.
Definition Table.h:147
int turn
Tracker of how many times a player has played their cards on the board. Starts at 0.
Definition Table.h:150
auto receiveResetTable(const Message *message) -> Message
Resets the table to prepare it for a new game.
Definition Table.cpp:572
auto updateCardsInDeckText() -> void
Updates the text on screen to be the size of the Deck.
Definition Table.cpp:443
auto operator=(const Table &) -> Table &=default
int numberOfCardsPlayedThisTurn
Tracker for if the player can play more cards or not.
Definition Table.h:153
auto moveTurnForward() -> void
Increments the turn counter and moves the selector to the right player.
Definition Table.cpp:242
Board * board
We cache the board so we don't need to get it all the time.
Definition Table.h:137
auto reloadCache() -> void
Re-gets the players, board, and deck pointers.
Definition Table.cpp:196
auto updatePlayerScoreText(int playerNumber) -> void
Updates the text displayed for a players score.
Definition Table.cpp:419
auto linkMessages() -> void
Definition Table.cpp:702
auto receiveGoToWinScreen(const Message *message) -> Message
Cheat code that ends the game immediately and goes to the win screen.
Definition Table.cpp:695
auto receiveAddScore(const Message *message) -> Message
Cheat code that adds score to the current player.
Definition Table.cpp:668
friend auto from_json(const json &j, Table &t) -> void
Definition Table.cpp:182
auto getCurrentPlayer() const -> Player *
Gets who the current player should be based on the turn.
Definition Table.cpp:329
std::vector< Card * > cardsPlayedThisTurn
Vector of all cards that have been played, primarily used for updating the "playedThisTurn" variable ...
Definition Table.h:144
auto updatedCardsPlayedThisTurn() -> void
Sets "playedThisTurn" for cards played this turn to false, then empties the vector Typically called a...
Definition Table.cpp:426
auto moveSelectorToLastSelectedTile() -> void
Moves the selector to the last selected tile, which is set every time a card is played on the board.
Definition Table.cpp:408
auto componentShowMenu() -> void override
Definition Table.cpp:96
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Table.h:67
auto resetScores() -> void
Sets all the scores to 0.
Definition Table.cpp:500
GameRules gameRules
Ruleset to follow for things like cards in hand, size of board, etc.
Definition Table.h:163
auto receiveEndTurn(const Message *message) -> Message
Ends the current player's turn.
Definition Table.cpp:661
auto moveSelectorToLastPlayedCard() -> void
Moves the selector to lastSelectedCard, which is set every time a card is selected in a players hand.
Definition Table.cpp:397
auto reloadPlayers() -> void
Gets all the pointers of the Player components for "players" in the cache.
Definition Table.cpp:450
std::vector< Player * > players
We cache the players so we don't need to get it all the time.
Definition Table.h:135
~Table() override=default
auto fillAllPlayerHands() -> void
Tells all players to fill their hands until they reach the limit.
Definition Table.cpp:234
auto generatePlayerScoresData() const -> Stream
Generates a Stream (json object) that has the player number and their corresponding score in descendi...
Definition Table.cpp:547
friend auto to_json(json &j, const Table &t) -> void
Definition Table.cpp:172
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Table.cpp:136
auto dealCardToPlayer(int playerNumber) const -> void
Draws a card from the deck and gives it to the player.
Definition Table.cpp:203
auto reloadBoard() -> void
Gets the pointer to the board component for "board" in the cache.
Definition Table.cpp:461
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Table.cpp:162
auto getWinningPlayer() const -> Player *
Definition Table.cpp:334
auto moveSelectorToPlayer(int playerNumber) const -> void
Moves the selector to a player based on their index in the players vector.
Definition Table.cpp:378
Entity * lastSelectedTile
Tracker of the last selected board tile, so the player doesn't start in the bottom left every time.
Definition Table.h:159
auto receiveCardPlayedOnBoard(const Message *message) -> Message
Moves the selector back to the player hand, unless it is the next players turn.
Definition Table.cpp:610
auto resetTable() -> void
Resets everything on the table to the start of a new round.
Definition Table.cpp:517
auto moveSelectorToBoard() -> void
Moves selector to the board. Used when a card is selected in a players hand.
Definition Table.cpp:362
auto reloadSelector() -> void
Gets the pointer to the selector entity being used for gameplay for the cache Currently checks player...
Definition Table.cpp:472
auto reloadDeck() -> void
Gets the pointer to the deck component for "deck" in the cache.
Definition Table.cpp:467
auto receiveDrawCard(const Message *message) -> Message
Cheat code that draws a card to the current player.
Definition Table.cpp:678
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Table.h:58
auto onUpdate(float dt) -> void override
called once every frame.
Definition Table.cpp:127
Deck * deck
We cache the deck so we don't need to get it all the time.
Definition Table.h:139
Entity * selector
We cache the Selector so we don't need to get it all the time.
Definition Table.h:141
auto getCurrentPlayerNumber() const -> int
Gets who the current player should be based on the turn.
Definition Table.cpp:324
auto receiveCardDeselected(const Message *message) -> Message
Moves the selector from the board to the player hand.
Definition Table.cpp:601
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Table.cpp:132
auto operator=(Table &&other) noexcept -> Table &=default
auto goToWinScreen() const -> void
Moves the game to the win screen.
Definition Table.cpp:306
An indicator that loops through a parents' nodes children and can "select" them on keypress.
Definition GameRules.h:30
Definition Message.h:34