Create Piece.cpp
This commit is contained in:
parent
025de21e15
commit
fc418150a9
1 changed files with 69 additions and 0 deletions
69
Piece.cpp
Normal file
69
Piece.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#include <iostream>
|
||||||
|
#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";
|
||||||
|
}
|
Reference in a new issue