-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
41 lines (35 loc) · 1.19 KB
/
Copy pathMap.cpp
File metadata and controls
41 lines (35 loc) · 1.19 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
#include<Map>
template <int size> bool Map<size>::isPosFree(coords coords){
if(field[ship.coords.x][ship.coords.y] == 0){
return true
}else{
return false;
}
}
template <int size> bool Map<size>::isAlive(int shipID){
for(int i = 0; i++;i<size){
for(int j = 0;j<size;j++){
if(field[i][j]= shipID){return true;}//schiff lebt noch
}
}
return false; // schiff lebt nicht mehr
}
template <int size> void Map<size>::setShip(coords coords, int shipID){
field[coords.x][coords.y] = shipID;
}
template <int size> int Map<size>::processShot(coords coords){ // 0 = platscher 1 = hit 2 = treffer versenkt 3 = feld wurde schon beschossen
if(field[coords.x][coords.y] == 1)
return 3; // wurde schon beschosen
else if(field[coords.x][coords.y] == 0){
return 0; //kein treffer
}else if(field[coords.x][coords.y] > 1){
int tempID = 0;
tempID = field[coords.x][coords.y];
field[coords.x][coords.y] = 1;
if(isAlive(shipID)){
return 2; // hit
}else{
return 3; // treffer versenkt;
}
}
}