From fc418150a9ad5a5981aeb32467aec51f514c33ac Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 27 Oct 2015 21:50:08 -0500 Subject: [PATCH] Create Piece.cpp --- Piece.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Piece.cpp diff --git a/Piece.cpp b/Piece.cpp new file mode 100644 index 0000000..6848914 --- /dev/null +++ b/Piece.cpp @@ -0,0 +1,69 @@ +#include +#include "Piece.h" + +using namespace std; + +Piece::Piece(){ + x = -1; + y = -1; + type = '?'; +} + +Piece::Piece(int r, int c){ + x = r; + y = c; + type = '_'; +} + +Piece::Piece(int r, int c, char t){ + x = r; + y = c; + type = t; +} + +void Piece::moveFwd(){ + if (type == 'X'){ + x++; + } + + else if (type == 'O'){ + x--; + } + + else + cout << "Error: trying to move an empty piece forward."; +} + +void Piece::moveLeft(){ + if (type == 'X'){ + x++; + y--; + } + + else if (type == 'O'){ + x--; + y--; + } + + else + cout << "Error: trying to move an empty piece left."; +} + +void Piece::moveRight(){ + if (type == 'X'){ + x++; + y++; + } + + else if (type == 'O'){ + x--; + y++; + } + + else + cout << "Error: trying to move an empty piece left."; +} + +void Piece::isTaken(){ + cout << getX() << " " << getY() << "\n\n"; +}