-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.cpp
More file actions
70 lines (56 loc) · 1.54 KB
/
Copy pathGrid.cpp
File metadata and controls
70 lines (56 loc) · 1.54 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
//
// Created by Raunak Anand on 2019-06-01.
//
#include "BattleShip.hpp"
BattleShip::Grid::Grid(char contents, const char marker, const char hit, const char miss): contents(contents), marker(marker), hit(hit), miss(miss) {
firedAt = false;
}
BattleShip::Grid::Grid(char contents) : contents(contents), marker('*'), hit('X'), miss('O') {
firedAt = false;
}
char BattleShip::Grid::getContents() const {
return contents; // to retrieve the status of the board whether places have a hit, miss or normal marker
}
void BattleShip::Grid::setContents(char blankChar) {
(*this).contents = blankChar; // normal marker '*'
}
char BattleShip::Grid::visibleContents() const {
if (firedAt) {
if (shipIsThere()) {
return hit;
} else {
return miss;
}
} else {
return contents;
}
}
char BattleShip::Grid::hiddenContents() const {
if (firedAt) {
if (shipIsThere()) {
return hit;
} else {
return miss;
}
} else {
return marker;
}
}
char BattleShip::Grid::gethit() const {
return hit;
} // if the ship has been hit return hit 'X'
char BattleShip::Grid::getmarker() const {
return marker;
} // return the normal marker '*'
char BattleShip::Grid::getmiss() const {
return miss;
} // if missed, return the marker 'O'
bool BattleShip::Grid::alreadyFiredAt() const {
return firedAt;
}
void BattleShip::Grid::setalreadyFiredAt(bool alreadyFiredAt) {
(*this).firedAt = alreadyFiredAt;
}
bool BattleShip::Grid::shipIsThere() const {
return (contents != marker && contents != hit && contents != miss);
}