-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellPosition.h
More file actions
69 lines (52 loc) · 3.22 KB
/
Copy pathCellPosition.h
File metadata and controls
69 lines (52 loc) · 3.22 KB
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
#pragma once
#include "DEFS.h"
class CellPosition
{
int vCell; // the vertical cell number: starts from 0 to NumVerticalCells - 1
int hCell; // the horizontal cell number: starts from 0 to NumHorizontalCells - 1
public:
CellPosition (); // Initializes the cell to (-1,-1) indicating not initialized with valid values
CellPosition (int v, int h); // Sets vCell and hCell if valid
CellPosition (int cellNum); // Sets vCell and hCell from the passed cellNum if valid
// Note: this class does NOT deal with real coordinates, it deals with the "vCell", "hCell" and "cellNum" instead
// assuming NumVerticalCells = 5 and NumHorizontalCells = 11
// Cell Numbers (CellNum) should be from 1 to 55
// Numbered from [left-to-right] [bottom-up], as follows:
// hCell nx(right): 0 1 ... 10
// vCell ny(below):
// 0 C45 C46 ... C55
// 1 C34 C35 ... C44
// ... ... ... ... ...
// 3 C12 C13 ... C22
// 4 C1 C2 ... C11
// In the Grid above, C13 has vCell = 3 and hCell = 1
///########DONE TODO: IMPLEMENT THE FOLLOWING FUNCTION
bool SetVCell(int v); // The setter of vCell (the setter here sets only if "v" is in grid range)
// It returns true, if the parameter is valid and the setting is applied,
// Otherwise, return false with no setting
///########Done TODO: IMPLEMENT THE FOLLOWING FUNCTION
bool SetHCell(int h); // The setter of hCell (the setter here sets only if the "h" is in grid range)
// It returns true, if the parameter is valid and the setting is applied,
// Otherwise, return false with no setting
int VCell() const; // The getter of vCell
int HCell() const; // The getter of hCell
///#########DONE TODO: IMPLEMENT THE FOLLOWING FUNCTION
bool IsValidCell() const; // Checks if the current cell position (vCell and hCell) both are valid then return true
// Otherwise, return false
int GetCellNum() const; // Gets the cellNum from the vCell and hCell of the cell position
///#########DONE TODO: IMPLEMENT THE FOLLOWING FUNCTION
static int GetCellNumFromPosition(const CellPosition & cellPosition); // Calculates the cellNum of the passed "cellPosition"
// It is a static function (no need for a calling obj)
///######### Done TODO: IMPLEMENT THE FOLLOWING FUNCTION
static CellPosition GetCellPositionFromNum(int cellNum); // Returns the corresponding CellPosition (vCell, hCell) of the passed cellNum
// It is a static function (no need for a calling obj)
///######## Done TODO: IMPLEMENT THE FOLLOWING FUNCTION
/* Adds the passed "addedNum" to the "cellNum" of the current cell position based on the passed direction
and updates the data members (vCell and hCell) accordingly
for example, if cellNum = 11 (vCell = 4, hCell = 10) and the passed num = 2 and direction is up,
this will make cellNum = 33 which corresponds to vCell = 2 and hCell = 10
(assuming NumVerticalCells = 5 and NumHorizontalCells = 11 )
Note: Make sure to make any necessary validations
*/
void AddCellNum(int addedNum, Direction direction);
};