-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.cpp
More file actions
66 lines (56 loc) · 1.68 KB
/
Copy pathPlayer.cpp
File metadata and controls
66 lines (56 loc) · 1.68 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
#include "Player.hpp"
using std::ostream;
using std::vector;
#include <string>
using std::string;
string Player::getName(){return _name;}
/*void Player::addLastShot(int xCoord, int yCoord, bool isHit){
auto coords = std::make_pair(xCoord, yCoord);
auto coordsWithHit = std::make_pair(coords, isHit);
_previousShots.push_back(coordsWithHit);
}*/
bool Player::processOpponentShot(int xCoord, int yCoord){
if(_gameBoard.checkForHit(xCoord, yCoord)){
_gameBoard.processHit(xCoord, yCoord);
return true;
}
return false;
}
void Player::addPiece(int xCoord, int yCoord, bool isHorizontal, int shipSize){
if(isHorizontal)
_gameBoard.placePieceHorizontal(xCoord, yCoord, shipSize);
else
_gameBoard.placePieceVertical(xCoord, yCoord, shipSize);
}
ostream& Player::showBoard(ostream& os){
os << _gameBoard;
return os;
}
/*ostream& Player::showPreviousShots(ostream& os){
vector<vector<char>> display;
for(int y = 0; y < _gameBoard.getBoardSize(); y++){
display.push_back(vector<char>(_gameBoard.getBoardSize()));
for(auto item : display[y]){
item = '_';
}
}
for(auto coordPair : _previousShots){
auto coords = coordPair.first;
if(coords.second == true){
display[coords.second][coords.first] = 'X';
}
else{
display[coords.second][coords.first] = 'O';
}
}
}*/
bool Player::isLost(){
return _gameBoard.shipsRemaining();
}
ostream& Player::showGuessBoard(std::ostream& os){
os << _referenceBoard;
return os;
}
void Player::addGuess(int xCoord, int yCoord, string s){
_referenceBoard.processGuess(xCoord, yCoord, s);
}