-
Notifications
You must be signed in to change notification settings - Fork 0
/
BattleBoat.h
75 lines (53 loc) · 2.7 KB
/
BattleBoat.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
#pragma once
#include <iostream>
// Class for keeping track of the state of a single boat
class BattleBoat
{
public:
// Constructor: takes length as a parameter
BattleBoat(unsigned int length = 6);
// Gets the length of the boat
unsigned int getLength() const;
// Gets the x-coordinate of the left-most space occupied by the boat.
unsigned int getStartX() const;
// Gets the y-coordinate of the left-most space occupied by the boat.
unsigned int getStartY() const;
// Gets whether the boat is aligned vertically (extending downward from the starting space)
// or horizontally (extending to the right from the starting space).
bool isVertical() const;
// Prints out a single segment of the boat using ASCII art.
std::ostream& printSegment(std::ostream& out, unsigned int x, unsigned int y) const;
// Sets the x-coordinate of the left-most space occupied by the boat.
void setStartX(unsigned int startX);
// Sets the y-coordinate of the left-most space occupied by the boat.
void setStartY(unsigned int startY);
// Sets whether the boat is aligned vertically (extending downward from the starting space)
// or horizontally (extending to the right from the starting space).
void setVertical(bool vertical);
// Returns true if this boat overlaps the other boat, false otherwise.
// This can be used to check if two boats can simulataneously exist on the same board legally.
bool intersects(const BattleBoat& other) const;
// Check if the boat has been hit at a particular (x,y) coordinate
bool isHit(unsigned int x, unsigned int y) const;
//Check if the boat is able to be hit at a particular (x,y) coordinate
bool isHitable(unsigned int x, unsigned int y) const;
// Set a single segment of the boat as "hit" at a particular (x,y) coordinate
void hit(unsigned int x, unsigned int y);
// Check if the boat is sunk (all segments have been hit)
bool isSunk() const;
// The maximum possible boat length
const static unsigned int MAX_LENGTH = 6;
private:
// Stores the length of the boat.
unsigned int length;
// Stores the x-coordinate of the left-most space occupied by the boat.
unsigned int startX = 0;
// Stores the y-coordinate of the upper-most space occupied by the boat.
unsigned int startY = 0;
// Stores whether the boat is aligned vertically (extending downward from the starting space)
// or horizontally (extending to the right from the starting space).
bool vertical = false;
// An array to keep track of the locations of hits when the boat is targeted during the game.
bool hits[MAX_LENGTH] = { };
// Add any other private variables you need here.
};