-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttackMove.cpp
More file actions
54 lines (43 loc) · 1.84 KB
/
Copy pathAttackMove.cpp
File metadata and controls
54 lines (43 loc) · 1.84 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
//
// Created by Raunak Anand on 2019-06-01.
//
#include "BattleShip.hpp"
BattleShip::AttackMove::AttackMove(BattleShip::Player& attacker, int row, int column) : Move(attacker), row(row), column(column) {
}
const int BattleShip::AttackMove::getRow() const {
return row;
}
const int BattleShip::AttackMove::getCol() const {
return column;
}
bool BattleShip::AttackMove::isValid() const {
return (column >= moveMaker.getBoard().getNumCols() || row >= moveMaker.getBoard().getNumRows() || row < 0
|| column < 0);
}
void BattleShip::AttackMove::shipHealth(BattleShip::Creation& model, BattleShip::View& view) {
if (model.getDefendingPlayer().getBoard().at(row, column).shipIsThere()) {
model.getDefendingPlayer().getBoard().at(row, column).setContents(model.getDefendingPlayer().getBoard().at(row,
column).gethit());
hit = true;
} else {
model.getDefendingPlayer().getBoard().at(row, column).setContents(model.getDefendingPlayer().getBoard().at(row,
column).getmiss());
hit = false;
}
}
void BattleShip::AttackMove::shipHealth(BattleShip::Player& defender, BattleShip::View& view) {
if (defender.getBoard().at(row, column).shipIsThere()) {
defender.shipHealths[defender.getBoard().at(row, column).getContents()] -= 1;
defender.getBoard().at(row, column).setalreadyFiredAt(true);
}
defender.getBoard().at(row, column).setalreadyFiredAt(true);
}
int BattleShip::AttackMove::getColAttack() const {
return column;
}
int BattleShip::AttackMove::getRowAttack() const {
return row;
}
bool BattleShip::AttackMove::didItHit() {
return Move::moveMaker.getOpponent().getBoard().at(getRow(), getCol()).shipIsThere();
}