Brunot
Loading...
Searching...
No Matches
Board.h
Go to the documentation of this file.
1
13// ____ __ __ __
14// /\__ _\/\ \ /\ \/\ \
15// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
16// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
17// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
18// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
19// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
20
21
22#pragma once
23
24#include "Framework/Component.h"
25
26
27struct PlayerHand;
28class Card;
29
30class Selector;
31using CardGrid = std::vector<std::vector<Card>>;
32
37class Board : public Component
38{
39public:
40 Board(int width = 5, int height = 1)
41 : Component(cBoard, "Board")
42 , boardWidth(width)
43 , boardHeight(height)
44 {
45 }
46
47 Board(const Board& rhs) = default;
48 Board(Board&& rhs) noexcept = default;
49
50 auto operator=(const Board&) -> Board& = default;
51
52#pragma region overriden functions
53
54 ~Board() override = default;
55 auto clone() const -> std::unique_ptr<GameObject> override;
56 auto onEnterEngine() -> void override;
57 auto onUpdate(float dt) -> void override;
58 auto onRender() -> void override;
59 auto load(Stream& stream) -> void override;
60 auto save(Stream& stream) const -> void override;
61
62 auto endWindow() -> void override
63 {
64 } // for debug
65 auto componentShowMenu() -> void override;
66
67#pragma endregion
68
69
70#pragma region Gameplay Functions
71
76 auto clearBoard() const -> void;
77
82 auto fillBoard() -> void;
83
89 auto addCardToBoard(std::unique_ptr<Card> cardToAdd, const std::pair<int, int>& positionToAddAt) -> void;
90
97 auto getHandsFromCards(const std::vector<Card*>& cards) -> std::vector<PlayerHand>;
98
104 auto getHandsFromPlayedCards(const std::vector<Card*>& cards) -> std::vector<PlayerHand>;
105
106#pragma endregion
107
108#pragma region Json
109
110 friend auto to_json(json& j, const Board& b) -> void;
111 friend auto from_json(const json& j, Board& b) -> void;
112
113#pragma endregion
114
115private:
118 // Internal grid of where cards are placed, primarily used for scoring
120
121#pragma region Messages
122
123#pragma endregion
124
125#pragma region helper functions
126
131 auto collectCards() -> CardGrid;
132
137 auto rebuildGrid() -> void;
138
143 auto updateInternalGrid(const std::vector<Card*>& cards) -> void;
144
151 auto makePlayerHandFromColumn(int columnIndex) const -> std::vector<PlayerHand>;
152
159 auto makePlayerHandFromRow(int rowIndex) const -> std::vector<PlayerHand>;
160
161#pragma endregion
162
163};
sys::Json Stream
Definition AudioObject.h:20
std::vector< std::vector< Card > > CardGrid
Definition Board.h:31
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
Component that is responsible for managing the gameplay board, where cards are placed by Players.
Definition Board.h:38
auto componentShowMenu() -> void override
Definition Board.cpp:90
friend auto from_json(const json &j, Board &b) -> void
Definition Board.cpp:83
auto makePlayerHandFromRow(int rowIndex) const -> std::vector< PlayerHand >
Goes through a column in the card grid and finds all the player hands.
Definition Board.cpp:345
friend auto to_json(json &j, const Board &b) -> void
Definition Board.cpp:74
int boardWidth
Definition Board.h:116
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Board.h:62
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Board.cpp:50
auto clearBoard() const -> void
Deletes all elements inside of the board.
Definition Board.cpp:232
~Board() override=default
Board(int width=5, int height=1)
Definition Board.h:40
auto collectCards() -> CardGrid
returns a 2d vector of cards, with each card in it's position on the board.
Definition Board.cpp:280
auto updateInternalGrid(const std::vector< Card * > &cards) -> void
Adds new cards to the internal grid.
Definition Board.cpp:325
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Board.cpp:45
auto addCardToBoard(std::unique_ptr< Card > cardToAdd, const std::pair< int, int > &positionToAddAt) -> void
Adds a card component to an entity inside of the board menu.
Definition Board.cpp:118
int boardHeight
Definition Board.h:117
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Board.cpp:60
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Board.cpp:69
Board(const Board &rhs)=default
auto onUpdate(float dt) -> void override
called once every frame.
Definition Board.cpp:55
auto operator=(const Board &) -> Board &=default
Board(Board &&rhs) noexcept=default
CardGrid board
Definition Board.h:119
auto getHandsFromPlayedCards(const std::vector< Card * > &cards) -> std::vector< PlayerHand >
checks the rows and columns specifically from the played cards stored in Table
Definition Board.cpp:186
auto makePlayerHandFromColumn(int columnIndex) const -> std::vector< PlayerHand >
Goes through a column in the card grid and finds all the player hands.
Definition Board.cpp:340
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Board.cpp:64
auto rebuildGrid() -> void
Completely regenerates the internal card grid based on the cards below it.
Definition Board.cpp:301
auto getHandsFromCards(const std::vector< Card * > &cards) -> std::vector< PlayerHand >
Checks the rows and columns specifically from the played cards stored in Table.
Definition Board.cpp:140
auto fillBoard() -> void
Creates empty buttons under the board using the width and height, intended for initialization.
Definition Board.cpp:245
Definition Card.h:34
@ cBoard
Definition Component.h:47
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
An indicator that loops through a parents' nodes children and can "select" them on keypress.
Definition Selector.h:31
Definition HandFinder.h:20