-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwater_vehicle.cpp
More file actions
63 lines (58 loc) · 1.54 KB
/
Copy pathwater_vehicle.cpp
File metadata and controls
63 lines (58 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
/********************************************************************
* Name : Kevin Shaffer
* Student ID : 106069743
* Class : CSCI 2312-001
* HW# : 3
* Due Date : Sep 26th, 2017
* Description : Contains the implementation of the WaterVechile
class.
********************************************************************/
#include "water_vehicle.h"
#include "position.h"
WaterVehicle::WaterVehicle(Position::Coordinates coordinates, Position::Orientation orientation, unsigned int length) :
_coordinates(coordinates), _orientation(orientation), _length(length)
{
if (length == 0)
throw "Ship length must be greater than 0";
}
Position::Coordinates WaterVehicle::GetCoordinates() const
{
return _coordinates;
}
void WaterVehicle::SetCoordinates(Position::Coordinates coordinates)
{
_coordinates = coordinates;
}
Position::Orientation WaterVehicle::GetOrientation() const
{
return _orientation;
}
void WaterVehicle::SetOrientation(Position::Orientation orientation)
{
_orientation = orientation;
}
unsigned int WaterVehicle::GetLength() const
{
return _length;
}
bool WaterVehicle::IsSunk() const
{
return _hits == _length; // assumes _length != 0
}
bool WaterVehicle::IsHit(const Position::Coordinates& coordinates)
{
Position::Coordinates shipCoordinates = _coordinates;
for (int i = 0; i < _length; i++)
{
if (shipCoordinates == coordinates)
{
_hits++;
return true;
}
else if (_orientation == Position::HORIZONTAL)
shipCoordinates.X++;
else
shipCoordinates.Y++;
}
return false;
}