-
Notifications
You must be signed in to change notification settings - Fork 1
/
CellPosition.h
59 lines (42 loc) · 2.78 KB
/
CellPosition.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
#pragma once
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 = 9 and NumHorizontalCells = 11
// Cell Numbers (CellNum) should be from 1 to 99
// Numbered from [left-to-right] [bottom-up], as follows:
// hCell (right): 0 1 ... 10
// vCell (below):
// 0 C89 C90 ... C99
// 1 C78 C79 ... C88
// ... ... ... ... ...
// 7 C12 C13 ... C22
// 8 C1 C2 ... C11
// In the Grid above, C13 has vCell = 7 and hCell = 1
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
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
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
static int GetCellNumFromPosition(const CellPosition & cellPosition); // Calculates the cellNum of the passed "cellPosition"
// It is a static function (no need for a calling obj)
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)
void AddCellNum (int addedNum); // Adds the passed "addedNum" to the "cellNum" of the current cell position
// and updates the data members (vCell and hCell) accordingly
// for example, if cellNum = 50 and the passed num = 6
// this will make cellNum = 56 which updates the data members: vCell = 3 and hCell = 0
// (assuming NumVerticalCells = 9 and NumHorizontalCells = 11 )
};