-
Notifications
You must be signed in to change notification settings - Fork 1
/
Grid.h
97 lines (69 loc) · 4.8 KB
/
Grid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include "UI_Info.h"
#include "DEFS.h"
#include "Input.h"
#include "Output.h"
#include "CellPosition.h"
// forward declarations (the includes are in the cpp)
class Cell;
class GameObject;
class Ladder;
class Card;
class Player;
class Grid
{
Output * pOut; // A pointer to the Output object
Input * pIn; // A pointer to the Input object
Cell * CellList[NumVerticalCells][NumHorizontalCells]; // An array of "Pointers" to All Cells of the Grid Cells
// We make it array of pointers not objects because
// there are NO default constructor for class Cell
Player* PlayerList[MaxPlayerCount]; // An array of "Pointers" to the Players of the Game (MaxPlayerCount Players)
int currPlayerNumber; // The player number that has the turn to play
// currPlayerNumber is: from 0 to MaxPlayerCount - 1
Card * Clipboard; // This is used in copy/cut/paste card (should be set in copy/cut and got in paste)
bool endGame; // A boolean indicating if the Game is ended or not (a player reaches the end cell of the grid or not)
public:
Grid(Input * pIn, Output * pOut); // Gives the Grid a Pointer to the Output Object and the Input Object
// and makes any needed initializations
// ========= Adding or Removing GameObjects to Cells =========
bool AddObjectToCell(GameObject * pNewObject); // Adds a GameObject to the Cell of its "position" data member
// only if the Cell does NOT already contain an object,
// otherwise return false and don't add
bool RemoveObjectFromCell(const CellPosition & pos); // Removes the GameObject of the Cell of the passed "position"
// Note: You may need to change the return type of this function (Think) **
void UpdatePlayerCell(Player * player, const CellPosition & newPosition); // Update the player's pCell with the CellList's Cell pointer of the "newPosition",
// Clears the player's circle from the previous cell
// and Draws it in the new cell
// ========= Setters and Getters Functions =========
Input * GetInput() const; // Gets a Pointer to the Input
Output * GetOutput() const; // Gets a Pointer to the Output
void SetClipboard(Card * card); // A setter to be used in copy/cut (in order NOT to break class responsibilities)
Card * GetClipboard() const; // A getter to be used in paste (in order NOT to break class responsibilities)
void SetEndGame(bool endGame); // A setter for endGame data member
bool GetEndGame() const; // A getter for endGame data member
void AdvanceCurrentPlayer(); // Increments the currPlayerNum and if reaches MaxPlayerCount reset to 0 (using %)
bool SetCurrentPlayer(int p);
void GetNextPlayer(Player* currentPlayer, Player* NextPlayers[]);
void ClearGrid(); // Clears the grid
void ResetGrid(); // Resets the grid to its initial state
// ========= Other Getters =========
Player * GetCurrentPlayer() const; // Gets a Pointer to the Current Player
Card* GetCardFromPosition(const CellPosition& position);
Ladder * GetNextLadder(const CellPosition & position); // Gets a Pointer to the first Ladder after the passed "position"
int GetNumberOfObjects(ObjectType ObjType); // Gets the total number of a specific game object
Player * GetPlayerWithLeastCoins() const; // Gets a pointer to the player with the least amount of coins in his wallet
Player * GetPlayerByPlayerNum(int num); // Gets a pointer to the player with a specific playerNum
Cell* GetCellFromCellPosition(const CellPosition& position) const;
bool thisColumnHasLadder(const CellPosition& startPos,const CellPosition & endPos) const;
bool thisColumnHasSnake(const CellPosition& startPos, const CellPosition& endPos) const;
// ========= User Interface Functions =========
void UpdateInterface() const; // It Updates the Grid according to the last state of the game
// In Design mode, it draws all cells/cards THEN all ladders/snakes THEN all players
// In Play mode, it only draws the player's info on the right side of the toolbar
// Note: UpdatePlayerCell() function --> already update drawing players in Play Mode
// and the cards/snakes/ladders positions do NOT change already in Play Mode
void PrintErrorMessage(string msg); // Prints an error message on statusbar, Waits for mouse click then clears statusbar
// We added this function once here because it is used many times by other classes
void SaveAll(ofstream& outFile, ObjectType ObjType);
~Grid(); // A destructor for any needed deallcations
};