-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.h
104 lines (71 loc) · 4.56 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
#pragma once
#include "UI_Info.h"
#include "DEFS.h"
#include "Input.h"
#include "Output.h"
#include "CellPosition.h"
#include <fstream>
// forward declarations (the includes are in the cpp)
class Cell;
class GameObject;
class Ladder;
class Snake;
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
void RemoveObjectFromCell(const CellPosition & pos); // Removes the GameObject of the Cell of the passed "position"
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 %)
///TODO: add any needed setter/getter "EXCEPT" ANY setters or getters of "CellList" or "PlayerList" (Forbidden for class Responsibilities)
Card* GetCopyOfCardInCell(CellPosition position);
GameObject* GetObjectFromCell(CellPosition position);
// ========= 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"
Snake * GetNextSnake(const CellPosition& position); // Gets a Pointer to the first Snake after the passed "position"
// ========= 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
Ladder* GetLadderFromPosition(const CellPosition position);
Snake* GetSnakeFromPosition(const CellPosition position);
bool IsOverLapping(GameObject* obj);
void SaveAll(ofstream& OutFile, int type);
int CountLadders();
int CountSnakes();
int CountCards();
void RemoveAll();
~Grid(); // A destructor for any needed deallcations
};
//fadel l save all wa overlapping