-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
84 lines (73 loc) · 1.64 KB
/
Player.cpp
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
#include "Player.h"
#include "Board.h"
void Player::init()
{
if (computer)
{
playerId = "Computer";
playerBoard.setShipsRandom();
}
else
{
std::cout << "Gib deinen Namen ein: ";
std::cin >> playerId;
playerBoard.drawField();
std::cout << "Falls alle Schiffe Random gesetzt werden sollen, geben Sie bitte R ein"
<< std::endl
<< "Falls Sie die Schiffe selber platzieren wollen, geben Sie einen beliebigen anderen Buchstaben ein: ";
char input;
std::cin >> input;
switch (input) {
case 'r':
case 'R':
playerBoard.setShipsRandom();
playerBoard.drawField();
break;
default: playerBoard.setShips();
}
}
}
void Player::fire(Player& enemy, std::shared_ptr<struct_Point> point)
{
char marker = (enemy.playerBoard.attack(point) ? 'X' : 'O');
hitBoard.setPos(point, marker);
}
bool Player::wouldHit(std::shared_ptr<struct_Point> point)
{
return (playerBoard.getPos(point) == 'S');
}
bool Player::checkTarget(std::shared_ptr<struct_Point> point)
{
return (hitBoard.getPos(point) == '*');
}
void Player::showHitBoard()
{
std::cout << "Hit Board: " << std::endl << std::endl;
hitBoard.drawField();
std::cout << std::endl;
}
void Player::showShipBoard(){
std::cout << "Schiffsfeld: " << std::endl << std::endl;
playerBoard.drawField();
std::cout << std::endl;
}
bool Player::gameStatus()
{
return playerBoard.fleetStatus();
}
void Player::setPlayerId(std::string& id)
{
playerId = id;
}
std::string Player::getPlayerId()
{
return playerId;
}
void Player::setComputer(bool b)
{
computer = b;
}
bool Player::getComputer()
{
return computer;
}