Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago