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 "Component/Card.h"
26#include "Framework/Engine.h"
27#include "Framework/System.h"
28#include "Utility/GameRules.h"
29#include "Component/Player.h"
30
31namespace sys
32{
33class Table;
34
35class PlayerTurn : public System
36{
37public:
38#pragma region static_functions
39
43 static auto getEnum() -> Type
44 {
45 return Type::PlayerTurn;
46 }
47
48#pragma endregion
49
50 PlayerTurn();
51 ~PlayerTurn() override = default;
52 PlayerTurn(const PlayerTurn& other) = default;
53 PlayerTurn(PlayerTurn&& other) noexcept = default;
54 auto operator=(const PlayerTurn& other) -> PlayerTurn&;
55 auto operator=(PlayerTurn&& other) noexcept -> PlayerTurn& = default;
56
57
58#pragma region overridden_functions
59
60 auto clone() const -> std::unique_ptr<GameObject> override
61 {
62 return std::make_unique<PlayerTurn>(*this);
63 }
64
65 auto onUpdate(float dt) -> void override;
66 auto systemShowMenu() -> void override;
67
68 auto endWindow() -> void override
69 {
70 }; // for debug ImGUI
71 auto onRender() -> void override;
72 auto onSceneStart(const std::string& sceneName) -> void override;
73 auto onSceneExit(const std::string& sceneName) -> void override;
74 auto load(const Stream& stream) -> void override;
75 auto save(Stream& stream) const -> void override;
76
77#pragma endregion
78
79#pragma region PlayerTurn_Functions
80
84 auto moveTurnForward() -> void;
85
90 auto movePlayerCards(float direction, float cardDelay) -> void;
91
95 auto cardSelected(const Message* message) -> void;
96
100 auto cardDeselected() -> void;
101
105 auto cardPlayedOnBoard(const Message* message) -> void;
106
111 auto updatedCardsPlayedThisTurn() -> void;
112
116 auto playScoredSound() const -> void;
117
121 auto resetScores() -> void;
122
126 auto generatePlayerScoresData() const -> Stream;
127
131 auto resetTable() -> void;
132
137 auto getWinningPlayer() const -> Player*;
138
143 auto getCurrentPlayerNumber() const -> int;
144
149 auto getCurrentPlayer() const -> Player*;
150
155 auto arePlayersEmpty() const -> bool;
156
160 auto goToWinScreen() const -> void;
161
166 auto setPlayerInputIDs(const std::vector<int>& IDs) -> void;
167
169 auto getPlayerInputIDs() const -> const std::vector<int>&;
170
171 /* ---------- Cheat codes ---------- */
172
176 auto addScore() -> void;
177
181 auto drawCard() -> void;
182
183
184#pragma endregion
185
186private:
187#pragma region member_variables
188
190 Table* table = nullptr;
191
194
196 std::vector<Card*> cardsPlayedThisTurn;
197
200
202 std::vector<int> playerScores = {0};
203
206
208 int turn = 0;
209
211 std::vector<int> playerInputIDs = {0};
212
213#pragma endregion
214
215#pragma region helper_functions
216
217#pragma endregion
218
219#pragma region static_variables
220
221#pragma endregion
222
223 friend class Table;
224
225};
226}
sys::Json Stream
Definition AudioObject.h:20
The card component that is moved around on the board.
The class that holds the top node, and manages the main game loop, as well as startup and shutdown.
A helper struct that contains all relevant rules for gameplay for the 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:23
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
auto addScore() -> void
A cheat code that adds 100 to a player's score.
Definition PlayerTurn.cpp:502
auto goToWinScreen() const -> void
Moves the game to the win screen.
Definition PlayerTurn.cpp:474
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition PlayerTurn.h:60
static auto getEnum() -> Type
function required by all systems
Definition PlayerTurn.h:43
Table * table
A cache of Table so we can call its functions.
Definition PlayerTurn.h:190
auto cardDeselected() -> void
Brings previously selected card back to hand.
Definition PlayerTurn.cpp:304
auto generatePlayerScoresData() const -> Stream
Resets all caches and values for table.
Definition PlayerTurn.cpp:407
PlayerTurn()
Definition PlayerTurn.cpp:49
std::vector< int > playerInputIDs
Vector used to track which input device IDs correspond to what player.
Definition PlayerTurn.h:211
std::vector< Card * > cardsPlayedThisTurn
Vector of all cards that have been played, primarily used for updating the "playedThisTurn" variable ...
Definition PlayerTurn.h:196
auto cardSelected(const Message *message) -> void
Moves selected card to be placed on board.
Definition PlayerTurn.cpp:293
auto getWinningPlayer() const -> Player *
Gets the current winning player based off score.
Definition PlayerTurn.cpp:441
auto playScoredSound() const -> void
Plays a sound effect when scoring.
Definition PlayerTurn.cpp:381
auto moveTurnForward() -> void
Scores the board, resets the "playedThisTurn" flag, and gives next player control.
Definition PlayerTurn.cpp:124
auto drawCard() -> void
A cheat code that manually draws a card to a player's hand.
Definition PlayerTurn.cpp:367
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:95
auto getCurrentPlayer() const -> Player *
Gets who the current player should be based on the turn.
Definition PlayerTurn.cpp:460
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition PlayerTurn.h:68
int turn
Tracker of how many times a player has played their cards on the board. Starts at 0.
Definition PlayerTurn.h:208
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition PlayerTurn.cpp:109
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:492
auto arePlayersEmpty() const -> bool
Checks if all players have empty hands.
Definition PlayerTurn.cpp:465
Card * lastSelectedCard
Tracker of the last selected card, so we know what we're playing.
Definition PlayerTurn.h:193
auto movePlayerCards(float direction, float cardDelay) -> void
+1 for the direction will move player cards up and highlight them, -1 for the direction will move pla...
Definition PlayerTurn.cpp:205
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition PlayerTurn.cpp:114
PlayerTurn(PlayerTurn &&other) noexcept=default
auto resetScores() -> void
Sets all scores to 0.
Definition PlayerTurn.cpp:391
auto onRender() -> void override
called every frame after update has been called for every object.
Definition PlayerTurn.cpp:79
auto getCurrentPlayerNumber() const -> int
Gets who the current player should be based on the turn.
Definition PlayerTurn.cpp:455
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...
Definition PlayerTurn.cpp:358
~PlayerTurn() override=default
std::vector< int > playerScores
Scores for each player for the current game.
Definition PlayerTurn.h:202
auto getPlayerInputIDs() const -> const std::vector< int > &
Gets all the IDs of the players participating in the game.
Definition PlayerTurn.cpp:497
auto cardPlayedOnBoard(const Message *message) -> void
Checks if card placement was valid.
Definition PlayerTurn.cpp:309
auto onUpdate(float dt) -> void override
called once every frame.
Definition PlayerTurn.cpp:69
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:83
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition PlayerTurn.cpp:74
auto operator=(const PlayerTurn &other) -> PlayerTurn &
Definition PlayerTurn.cpp:55
int playerCardsPlaced
Keeps track of how many cards have been placed to see if limit has been hit.
Definition PlayerTurn.h:199
GameRules gameRules
Ruleset to follow for things like cards in hand, size of board, etc.
Definition PlayerTurn.h:205
auto resetTable() -> void
Resets all caches and values for table.
Definition PlayerTurn.cpp:432
friend class Table
Definition PlayerTurn.h:223
PlayerTurn(const PlayerTurn &other)=default
The system responsible for facilitating communication between gameplay components (Players,...
Definition Table.h:47
the type of elements in a basic_json container
Definition GameObject.h:32
An indicator that loops through a parents' nodes children and can "select" them on keypress.
Definition GameRules.h:30
Definition Message.h:34