-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cannon.cpp
47 lines (36 loc) · 867 Bytes
/
Cannon.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
/**
* @file Cannon.cpp - Implementation of Cannon class
* @author Kevin Lundeen
* @see "Seattle University, CPSC 2430, Spring 2018"
*/
#include "Cannon.h"
using namespace std;
Cannon::Cannon(int row, int col) : heading(EAST), r(row), c(col) {
}
void Cannon::move() {
c += sign();
}
void Cannon::reverse() {
if (heading == EAST)
heading = WEST;
else
heading = EAST;
}
void Cannon::rotate() {
}
int Cannon::sign() const {
return heading == EAST ? +1 : -1;
}
void Cannon::render(PixelMatrix &pxm) const {
pxm.paint(r, c - 1, r, c + 1, RGB::RED);
pxm.paint(r - 1, c, RGB::RED);
}
Critter::Direction Cannon::getHeading() const {
return heading;
}
int Cannon::getColumn() const {
return c;
}
ostream &Cannon::print(ostream &out) const {
return out << "Cannon(" << r << "," << c << "," << heading << ")";
}