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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
class ChessPiece{
public:
ChessPiece(int, int, bool);
int getX(void);
int getY(void);
char print(void);
protected:
int xPosition;
int yPosition;
bool isWhite;
char graphic;
};
ChessPiece::ChessPiece(int x, int y, bool w){
xPosition = x;
yPosition = y;
isWhite = w;
}
int ChessPiece::getX(void){
return xPosition;
}
int ChessPiece::getY(void){
return yPosition;
}
char ChessPiece::print(void){
return graphic;
}
const int boardWidth = 8;
const int boardHeight = 8;
const int numOfPieces = 32;
int main(){
char board[boardWidth][boardHeight]; //created blank board w/ dashes
//Create empty board
for(int y = 0; y < boardHeight; y++){
for(int x = 0; x < boardWidth; x++){
board[x][y] = '-';
}
}
//Creating Pawns
ChessPiece *pieces[numOfPieces];
for(int x = 0; x < boardWidth; x++){
pieces[x] = new PawnPiece(x, 1, false); //dont understand this part
pieces[x+8] = new PawnPiece(x, 6, true);
}
//16 pawns - total = 16
//creating knights
pieces[16] = new KnightPiece(1,0,false);
pieces[17] = new KnightPiece(6,0,false);
pieces[18] = new KnightPiece(1,7,true);
pieces[19] = new KnightPiece(6,7,true);
//creating rooks
pieces[20] = new RookPiece(0,0,false);
pieces[21] = new RookPiece(7,0,false);
pieces[22] = new RookPiece(0,7,true);
pieces[23] = new RookPiece(7,7,true);
//creating Bishops
pieces[24] = new BishopPiece(2,0,false);
pieces[25] = new BishopPiece(5,0,false);
pieces[26] = new BishopPiece(2,7,true);
pieces[27] = new BishopPiece(5,7,true);
//creating Queens
pieces[28] = new QueenPiece(3,0,false);
pieces[29] = new QueenPiece(3,7,true);
//creating Kings
pieces[30] = new KingPiece(4,0,false);
pieces[31] = new KingPiece(4,7,true);
//4 knights - total = 20
PawnPiece *t = (PawnPiece*)pieces[0];
t -> moveForwardTwo();
KnightPiece *j = (KnightPiece*)pieces[17];
j -> moveForwardRight();
RookPiece *r = (RookPiece*)pieces[20];
r -> MoveSideRight(2);
//Print statementPawns
for(int x = 0; x < 32; x++){
int xPos = pieces[x]->getX();
int yPos = pieces[x]->getY();
// board[xPos][yPos] = 'Z'; //make and call print method for each piece
board[xPos][yPos] = pieces[x] -> print();
}}
| |