-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGrid.h
118 lines (77 loc) · 4.96 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#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)
int NumberOfLadders; // To keep track of no. of ladders on the grid
GameObject** LadderArr; // An array used when saving
int NumberOfSnakes; // To keep track of no. of snakes on the grid
GameObject** SnakeArr; // An array used when saving
int NumberOfCards; // To keep track of no. of cards on the grid
GameObject** CardArr; // An array used when saving
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
int 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 RemoveAllObjects(); // Removes all gameobjects (used when loading grid)
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
bool isOverlapping(GameObject* newGameObj) const;
// ========= Setters and Getters Functions =========
Input * GetInput() const; // Gets a Pointer to the Input
Output * GetOutput() const; // Gets a Pointer to the Output
void SetClipboard(CellPosition pos); // A setter to be used in copy/cut (in order NOT to break class responsibilities)
void SetClipboard(Card* pCard);
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
bool HasLadder(int V, int H);
bool HasSnake(int V, int H);
int GetNumberOfCards() const;
bool HasCard(CellPosition pos);
Player* getPoorestPlayer() const;
void SavetoFile(ofstream& OutFile);
void AdvanceCurrentPlayer(); // Increments the currPlayerNum and if reaches MaxPlayerCount reset to 0 (using %)
///TODO: add any needed setter/getter "EXCEPT" ANY setters or getters of "CellList" or "PlayerList" (Forbidden for class Responsibilities)
// ========= Other Getters =========
Player * GetCurrentPlayer() const; // Gets a Pointer to the Current Player
Ladder * GetNextLadder(const CellPosition & position); // Gets a Pointer to the first Ladder after the passed "position"
Player* getNextPlayer(Player* pPlayer) const;
void LocateAllGameObjects();
int getCurrPlayerNumber() 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 Restart();
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
~Grid(); // A destructor for any needed deallcations
};