-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShip.cpp
More file actions
88 lines (74 loc) · 1.65 KB
/
Ship.cpp
File metadata and controls
88 lines (74 loc) · 1.65 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Ship.h"
Ship::Ship()
{
}
Ship::Ship(const int &deck_num)
{
this->deck_num = deck_num;
health = deck_num;
}
char Ship::get_value(const int &x, const int &y)
{
std::pair<int, int> p(x,y);
return coordinates_with_values.find(p)->second;
}
void Ship::set_value(const int &x, const int &y, const char &value)
{
std::pair<int, int> p(x,y);
coordinates_with_values.find(p)->second = value;
}
int Ship::get_health()
{
return health;
}
int Ship::get_deck_number()
{
return deck_num;
}
int Ship::get_hited_deck_number()
{
return hited_deck_num;
}
void Ship::hit(const int &x, const int &y)
{
for(auto &el : coordinates_with_values)
{
if(el.first.first == x && el.first.second == y)
{
el.second = destroyed_sign;
--health;
++hited_deck_num;
if(health == 0)
is_destroyed = true;
}
}
}
void Ship::add_ship_coordinate(const int &x, const int &y)
{
std::pair<int,int> p(x,y);
coordinates_with_values.insert({p, ship_sign});
}
bool Ship::has_coordinate(const int &x, const int &y)
{
for(auto &el : coordinates_with_values)
{
if(el.first.first == x && el.first.second == y)
{
return true;
}
}
return false;
}
bool Ship::get_is_destroyed()
{
return is_destroyed;
}
std::vector<std::pair<int, int> > Ship::get_coordinates()
{
std::vector<std::pair<int, int>> coordinates;
for(auto &a : coordinates_with_values)
{
coordinates.push_back(a.first);
}
return coordinates;
}