forked from ngandugilbert/BattleShips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
172 lines (151 loc) · 2.81 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
#include<time.h>
using namespace std;
//Create ships
int Gen()
{
srand(time(NULL));
return rand()%2;
}
class Player
{
string Name;
int Lives;
public:
Player()
{
Lives=4;
Name="Captain";
}
//get lives
int getLives()
{
return Lives;
}
void ReduceLives()
{
Lives--;
}
void setName(string Name)
{
Player::Name=Name;
}
string getName()
{
return Name;
}
void Start();
void Intro();
};
class Ships
{
string level;
int NumberOfShips;
int AvailableShips;
int Latitude;
int Longitude;
int addShips();
int counted;
int Position[7][5]; /*{
{
0,1,0,0,0
},
{
0,0,1,0,0
},
{
0,0,1,0,0
},
{
1,0,0,1,0
},
{
0,0,1,0,0
},
{
1,0,0,0,1
},
{
0,1,0,1,0
}
};*/
public:
Ships()
{
NumberOfShips=4;
//AvailableShips=10;
Latitude=0;
Longitude=0;
counted = addShips();
if(counted == 0)
counted = addShips();
if(counted > 0 && counted <=4)
level = "Easy";
else if(counted>=5 && counted<8)
level = "Medium";
else if(counted == 10 || counted ==9 )
level = "Hard";
}
int getNumberOfShips()
{
return NumberOfShips;
}
int getAvailableShips()
{
return AvailableShips;
}
void setLatitude(int Latitude)
{
Ships::Latitude=Latitude;
}
int getLatitude()
{
return Latitude;
}
void setLongitude(int Longitude)
{
Ships::Longitude=Longitude;
}
int getLongitude()
{
return Longitude;
}
string getLevel()
{
return level;
}
bool Validate(int, int);
bool Target();
};
int Ships::addShips()
{
for(int col = 0; col<7; col++)
{
for(int row = 0; row<4; row++)
{
int cod = Gen();
if(AvailableShips<10)
{
//keep track of created ships
AvailableShips +=cod;
Position[col][row] = cod;
}
else
{
//if more ships are there set the rest to zeros
Position[col][row] = 0;
}
}
}
return AvailableShips;
}
//Player Storage as team multiplayer
struct node
{
string name;
node* next;
};
node* End = NULL;
node* p;
#endif // MAIN_H_INCLUDED