Brunot
Loading...
Searching...
No Matches
PlayerTurn.h
Go to the documentation of this file.
1
14// ____ __ __ __
15// /\__ _\/\ \ /\ \/\ \
16// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
17// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
18// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
19// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
20// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
21
22#pragma once
23
24
25#include <stack>
26
27#include "Component/Card.h"
28#include "Framework/Engine.h"
29#include "Framework/System.h"
31#include "Component/Player.h"
33
34namespace sys
35{
36class GameRules;
37class Table;
38
39class PlayerTurn : public System
40{
41public:
42#pragma region static_functions
43
47 static auto getEnum() -> Type
48 {
49 return Type::PlayerTurn;
50 }
51
52#pragma endregion
53
54 PlayerTurn();
55 ~PlayerTurn() override = default;
56 PlayerTurn(const PlayerTurn& other) = default;
57 PlayerTurn(PlayerTurn&& other) noexcept = default;
58 auto operator=(const PlayerTurn& other) -> PlayerTurn&;
59 auto operator=(PlayerTurn&& other) noexcept -> PlayerTurn& = default;
60
61
62#pragma region overridden_functions
63
64 auto clone() const -> std::unique_ptr<GameObject> override
65 {
66 return std::make_unique<PlayerTurn>(*this);
67 }
68
69 auto onUpdate(float dt) -> void override;
70 auto systemShowMenu() -> void override;
71
72 auto endWindow() -> void override
73 {
74 }; // for debug ImGUI
75 auto onRender() -> void override;
76 auto onSceneStart(const std::string& sceneName) -> void override;
77 auto onSceneExit(const std::string& sceneName) -> void override;
78 auto load(const Stream& stream) -> void override;
79 auto save(Stream& stream) const -> void override;
80
81#pragma endregion
82
83#pragma region PlayerTurn_Functions
84
88 auto moveTurnForward() -> void;
89
93 auto changePlayers() -> void;
94
98 auto getPlayersChanging() -> bool;
99
103 auto cardSelected(const Message* message) -> void;
104
108 auto cardDeselected() const -> void;
109
113 auto cardPlayedOnBoard(const Message* message) -> void;
114
115 auto playerTimerRanOut(int playerNumber) -> void;
116
120 auto undoLastPlayedCard() const -> void;
121
125 auto redoLastPlayedCard() -> void;
126
132
133 auto getCardsPlayedThisTurn() -> std::vector<Card*>;
134
135 auto getLastSelectedCard() -> Card*;
136
137
138
142 auto resetScores() -> void;
143
147 auto generatePlayerScoresData() const -> Stream;
148
152 auto resetTable() -> void;
153
158 auto getWinningPlayer() const -> Player*;
159
164 auto getCurrentPlayerNumber() const -> int;
165
170 auto getCurrentPlayer() const -> Player*;
171
176 auto getPlayerScores() const -> std::vector<int>;
177
182 auto arePlayersEmpty() const -> bool;
183
187 auto goToWinScreen() const -> void;
188
193 auto setPlayerInputIDs(const std::vector<int>& IDs) -> void;
194
196 auto getPlayerInputIDs() const -> const std::vector<int>&;
197
198 /* ---------- Cheat codes ---------- */
199
203 auto addScore() -> void;
204
208 auto drawCard() -> void;
209
210#pragma endregion
211
212private:
213#pragma region member_variables
214
216 Table* table = nullptr;
217
220
222 std::vector<Card*> cardsPlayedThisTurn;
223
226
228 std::vector<int> playerScores = {0};
229
232
234 int turn = 0;
235
237 std::vector<int> playerInputIDs = {0};
238
240 std::stack<std::pair<Card*,std::pair<int,int>>> redoBuffer;
241
243 bool playersChanging = false;
244
245#pragma endregion
246
247#pragma region helper_functions
248
249#pragma endregion
250
251#pragma region static_variables
252
253#pragma endregion
254
255 friend class Table;
256 friend class GameRules;
257};
258}
sys::Json Stream
Definition AudioObject.h:20
The card component that is moved around on the board.
Holds a hand after it has been ranked, storing both the entire hand and the important cards.
The class that holds the top node, and manages the main game loop, as well as startup and shutdown.
The system that handles gameplay functions to communicate back to Table.
The component responsible for storing information relevant to the player.
Definition Card.h:34
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
The component responsible for storing information relevant to the player.
Definition Player.h:31
Type
Definition System.h:20
@ PlayerTurn
Definition System.h:32
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
Definition GameRules.h:29
auto addScore() -> void
A cheat code that adds 100 to a player's score.
Definition PlayerTurn.cpp:530
auto goToWinScreen() const -> void
Moves the game to the win screen.
Definition PlayerTurn.cpp:502
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition PlayerTurn.h:64
static auto getEnum() -> Type
function required by all systems
Definition PlayerTurn.h:47
Table * table
A cache of Table so we can call its functions.
Definition PlayerTurn.h:216
auto undoLastPlayedCard() const -> void
Moves the last played card back to the players hand.
Definition PlayerTurn.cpp:361
auto generatePlayerScoresData() const -> Stream
Resets all caches and values for table.
Definition PlayerTurn.cpp:430
PlayerTurn()
Definition PlayerTurn.cpp:51
std::vector< int > playerInputIDs
Vector used to track which input device IDs correspond to what player.
Definition PlayerTurn.h:237
auto changePlayers() -> void
Gives next player control.
Definition PlayerTurn.cpp:160
std::vector< Card * > cardsPlayedThisTurn
Vector of all cards that have been played, primarily used for updating the "playedThisTurn" variable ...
Definition PlayerTurn.h:222
std::stack< std::pair< Card *, std::pair< int, int > > > redoBuffer
Buffer that stores where cards were intended to be placed, then undone.
Definition PlayerTurn.h:240
GameRules * gameRules
Ruleset to follow for things like cards in hand, size of board, etc.
Definition PlayerTurn.h:231
auto cardSelected(const Message *message) -> void
Moves selected card to be placed on board.
Definition PlayerTurn.cpp:281
auto getWinningPlayer() const -> Player *
Gets the current winning player based off score.
Definition PlayerTurn.cpp:464
auto moveTurnForward() -> void
Scores the board, resets the "playedThisTurn" flag.
Definition PlayerTurn.cpp:129
auto cardDeselected() const -> void
Brings previously selected card back to hand.
Definition PlayerTurn.cpp:292
auto drawCard() -> void
A cheat code that manually draws a card to a player's hand.
Definition PlayerTurn.cpp:398
auto onSceneExit(const std::string &sceneName) -> void override
Hook that is called right before a scene is unloaded To receive the hook, simply override the functio...
Definition PlayerTurn.cpp:100
auto getCurrentPlayer() const -> Player *
Gets who the current player should be based on the turn.
Definition PlayerTurn.cpp:483
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition PlayerTurn.h:72
int turn
Tracker of how many times a player has played their cards on the board. Starts at 0.
Definition PlayerTurn.h:234
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition PlayerTurn.cpp:114
auto setPlayerInputIDs(const std::vector< int > &IDs) -> void
Sets the IDs for all the players that will be participating in the game, in turn order.
Definition PlayerTurn.cpp:520
auto redoLastPlayedCard() -> void
Moves the last undone card back onto the board.
Definition PlayerTurn.cpp:370
auto arePlayersEmpty() const -> bool
Checks if all players have empty hands.
Definition PlayerTurn.cpp:493
Card * lastSelectedCard
Tracker of the last selected card, so we know what we're playing.
Definition PlayerTurn.h:219
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition PlayerTurn.cpp:119
PlayerTurn(PlayerTurn &&other) noexcept=default
auto resetScores() -> void
Sets all scores to 0.
Definition PlayerTurn.cpp:414
auto onRender() -> void override
called every frame after update has been called for every object.
Definition PlayerTurn.cpp:82
auto getCurrentPlayerNumber() const -> int
Gets who the current player should be based on the turn.
Definition PlayerTurn.cpp:478
auto operator=(PlayerTurn &&other) noexcept -> PlayerTurn &=default
auto updatedCardsPlayedThisTurn() -> void
Sets "playedThisTurn" for cards played this turn to false, then empties the vector Typically called a...
friend class GameRules
Definition PlayerTurn.h:256
~PlayerTurn() override=default
std::vector< int > playerScores
Scores for each player for the current game.
Definition PlayerTurn.h:228
auto getCardsPlayedThisTurn() -> std::vector< Card * >
Definition PlayerTurn.cpp:388
auto getPlayerInputIDs() const -> const std::vector< int > &
Gets all the IDs of the players participating in the game.
Definition PlayerTurn.cpp:525
auto cardPlayedOnBoard(const Message *message) -> void
Checks if card placement was valid.
Definition PlayerTurn.cpp:300
auto onUpdate(float dt) -> void override
called once every frame.
Definition PlayerTurn.cpp:72
auto onSceneStart(const std::string &sceneName) -> void override
Hook that is called before the first frame a scene is run, but after the entire scene is loaded into ...
Definition PlayerTurn.cpp:86
bool playersChanging
Bool that keeps track of whether or not players are changing.
Definition PlayerTurn.h:243
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition PlayerTurn.cpp:77
auto operator=(const PlayerTurn &other) -> PlayerTurn &
Definition PlayerTurn.cpp:58
int playerCardsPlaced
Keeps track of how many cards have been placed to see if limit has been hit.
Definition PlayerTurn.h:225
auto getLastSelectedCard() -> Card *
Definition PlayerTurn.cpp:393
auto resetTable() -> void
Resets all caches and values for table.
Definition PlayerTurn.cpp:455
auto getPlayersChanging() -> bool
If players are currently being changed or not.
Definition PlayerTurn.cpp:276
auto playerTimerRanOut(int playerNumber) -> void
Definition PlayerTurn.cpp:348
friend class Table
Definition PlayerTurn.h:255
PlayerTurn(const PlayerTurn &other)=default
auto getPlayerScores() const -> std::vector< int >
Gets who the current player should be based on the turn.
Definition PlayerTurn.cpp:488
The system responsible for facilitating communication between gameplay components (Players,...
Definition Table.h:48
the type of elements in a basic_json container
Definition GameObject.h:37
Definition Message.h:35