Question: Use this class the create a program that moves a single checker piece across a board and then have it return to its starting square.

Use this class the create a program that moves a single checker piece across a board and then have it return to its starting square. Your program should output the game-board after every move it makes to show its progress.

Need help finishing it.

#include using namespace std;

class checkerPiece { private: int xPosition = 0;//from 0 to 7 int yPosition = 0;//from 0 to 7

bool king = 0;//0 is not king, 1 is king

public: char color;//b for black and r for red

void upRight(); void upLeft(); void downRight(); void downLeft(); int xPositionReturn(); int yPositionReturn();

};

void checkerPiece::upRight() { if (color == 'b') { if ((xPosition + 1 <= 7) && (yPosition + 1 <= 7)) { xPosition++; yPosition++; } } else if (color == 'r') { if ((king == 1) && (xPosition + 1 <= 7) && (yPosition + 1 <= 7)) { xPosition++; yPosition++; } } if (king == 0 && color == 'b'&&yPosition == 7) { king = 1; }

}

void checkerPiece::upLeft() { if (color == 'b') { if ((xPosition - 1 >= 0) && (yPosition + 1 <= 7)) { xPosition--; yPosition++; } } else if (color == 'r') { if (king == 1 && (xPosition - 1 >= 0) && (yPosition + 1 <= 7)) { xPosition--; yPosition++; } } if (king == 0 && color == 'b'&&yPosition == 7) { king = 1; } }

void checkerPiece::downRight() { if (color == 'r') { if ((xPosition + 1 <= 7) && (yPosition - 1 >= 0)) { xPosition++; yPosition--; } } else if (color == 'b') { if ((king == 1) && (xPosition + 1 <= 7) && (yPosition - 1 >= 0)) { xPosition++; yPosition--; } } if (king == 0 && color == 'r'&&yPosition == 0) { king = 1; }

}

void checkerPiece::downLeft() { if (color == 'r') { if ((xPosition - 1 >= 0) && (yPosition - 1 >= 0)) { xPosition--; yPosition--; } } else if (color == 'b') { if ((king == 1) && (xPosition + 1 >= 0) && (yPosition - 1 >= 0)) { xPosition--; yPosition--; } } if (king == 0 && color == 'r'&&yPosition == 0) { king = 1; } }

int checkerPiece::xPositionReturn() { return xPosition; }

int checkerPiece::yPositionReturn() { return yPosition; }

void display(checkerPiece testPiece) { cout << endl; for (int y = 7; y >= 0; y--) {

for (int x = 0; x < 8; x++) { if (x == testPiece.xPositionReturn() && y == testPiece.yPositionReturn()) { cout << "O"; } else { cout << "X"; } } cout << endl; } cout << endl; }

int main() { checkerPiece testPiece; testPiece.color = 'b';

display(testPiece); testPiece.upRight();//starting point //how to make it across the board (to the top) and then have it return to its starting point

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!