-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.cpp
More file actions
75 lines (61 loc) · 1.31 KB
/
player.cpp
File metadata and controls
75 lines (61 loc) · 1.31 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
#include "player.h"
#include "utils.h"
#include "board.h"
using namespace std;
Player::Player(string playerName, Board &board): name(playerName), board(board){}
Player::Player(string playerName, string boardFilename): name(playerName), board(Board(boardFilename)){}
void Player::show_board() const
{
clrscr();
board.display();
}
Bomb Player::get_bomb() const
{
//srand(time(NULL));
// Do input control
char row, column;
do
{
cout << "Target coordinates (row, column) ? ";
cin >> row >> column;
cin.clear();
cin.ignore(INT_MAX, '\n');
row = toupper(row);
column = tolower(column);
} while (row < 'A' || row > 'J' || column < 'a' || column > 'j');
// Create some defect bomb degree (60%)
int aim = rand() % 10;
// Make sure defect bomb aim to the 'sea'
if ((aim == 0 && row == 'A') || (aim == 1 && row == 'J') || (column == 'a' && aim == 2 ) || (column == 'j' && aim == 3))
aim = 5;
switch (aim) {
case NORTH:
row--;
break;
case SOUTH:
row++;
break;
case WEST:
column--;
break;
case EAST:
column++;
break;
default:
break;
}
PositionChar pc;
pc.row = row;
pc.column = column;
return Bomb(pc);
}
void Player::board_attacked(const Bomb &bomb)
{
//board.moveShips();
board.attack(bomb);
}
void Player::show() const
{
cout << "Name: " << name << endl;
board.show();
}