-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
79 lines (70 loc) · 1.7 KB
/
Player.cpp
File metadata and controls
79 lines (70 loc) · 1.7 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
//
// Created by Marcin on 2018-11-11.
//
#include "Player.h"
Player::Player(int x, int y): board(Board(x, y)), enemyBoard(Board(x, y)) {}
void Player::printBoard() {
board.printCheat();
}
unsigned char Player::checkForHit(int x, int y) {
return board.checkForHit(x, y);
}
bool Player::shoot(int x, int y, Player &enemy) {
unsigned char result = enemy.checkForHit(x, y);
bool out = false;
if(result != 'o') {
score++;
out = true;
}
if(result == 'X' || result == 'o') {
enemyBoard.setAt(x, y, result);
} else if(result == '#') {
enemyBoard.setAt(x, y, 'o');
} else if(result) {
enemyBoard.setAt(x, y, 'X');
enemyBoard.sink(x, y, result - '0' - 4);
}
return out;
}
void Player::printEnemyBoard() {
enemyBoard.printCheat();
}
int Player::getScore() const {
return score;
}
bool Player::setUp(int p, int q, int t, int d) {
bool failed;
board.print();
do {
failed = false;
board.clear();
for (int i = 0; i < p; i++) {
if(!placeShip(5)){
failed = true;
continue;
};
}
for (int i = 0; i < q; i++) {
if(!placeShip(4)){
failed = true;
continue;
};
}
for (int i = 0; i < t; i++) {
if(!placeShip(3)){
failed = true;
continue;
};
}
for (int i = 0; i < d; i++) {
if(!placeShip(2)){
failed = true;
continue;
};
}
} while(failed);
return true;
}
void Player::printCheatEnemyBoard(Player &enemy) {
enemy.printBoard();
}