Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how can I fix this code so it print the movement. package simplified.single.player.chess.game; import java.util.Scanner; /** * * @author cubanitos */ public class SimplifiedSinglePlayerChessGame {

how can I fix this code so it print the movement. package simplified.single.player.chess.game; import java.util.Scanner; /** * * @author cubanitos */ public class SimplifiedSinglePlayerChessGame { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input = new Scanner(System.in); String [][] chess = new String [8][8]; String [] backPieces = {"rook", "knight","bishop", "king","queen","bishop","knight","rook"}; int [] frontPieces = {0,1,2,3,4,5,6,7}; for(int a = 0; a < 8; a++) { for (int b = 0; b < 8; b++) { if (a > 1 & a < 6) { chess [a][b] = "empty";} if (a == 0) { chess [a][b] = "white " + backPieces [b]; } if (a == 7) { chess [a][b]= "black " + backPieces [b]; } if (a == 1){ chess [a][b] = "white pawn"; } if (a == 6){ chess [a][b] = "black pawn"; } } } //Prompt the user to choose a color. ' int userResponse; System.out.print("Choose the color black(1) or white(2) with which you want to play"); userResponse = input.nextInt(); //Display the status of the chess board and the color that the user is currently playing. System.out.println("The game is ready to be play."); if(userResponse == 1){ System.out.println("You are playing with color black pieces."); } else { System.out.println("You are playing with white pieces."); } // This step prompt the user to make a move. //In this section the user specifies the current location of the piece and the desire destination of the piece. System.out.print("Choose the current location of the piece index(b),row index(a): "); int column = input.nextInt(); int row = input.nextInt(); System.out.print("Choose the desire destination of piece column index(b), row index(a): "); int desiredColumn = input.nextInt(); int desireRow = input.nextInt(); //Check for valid indexes. if(column >= 0 & column < 8){ if(row >= 0 & row < 8) if(desiredColumn >= 0 & desiredColumn < 8) if(desireRow >= 0 & desireRow <8) System.out.println("The location and the desired destination are valid"); } else{ System.out.println("The location and the desired destination are not valid"); } //Check wheter there is a piece at the specified current location. // if(column < 2 || column > 5){ if(row < 2 || column > 5) System.out.println("The current location is empty, you can move your piece there."); } else{ System.out.println("The current location is being occupied by a piece, choose a different square"); } if(desiredColumn > 1 & desiredColumn <6){ if(desireRow > 1 & desireRow <6) System.out.println("The desired destination is empty"); } else{ System.out.println("The desired destination is occupied, pick a different destination square "); } //Switch the color of the user.For example if the user had chosen Black first then now the user will make amove for White. System.out.print("Choose the color black(1) or white(2): "); userResponse = input.nextInt(); if(userResponse == 1){ System.out.println(userResponse + "black"); } else{ System.out.println(userResponse + "white"); } // Ask teh user if he or she want to continue playing the game. System.out.println("Do you want to continue playing chess, select yes(Y) or no(N): "); char Y; char N; char checkResponse = input.next().charAt(0); if(checkResponse == 'Y'){ System.out.print("Choose the current location of the piece index(b),row index(a): "); } else{ System.exit(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_2

Step: 3

blur-text-image_3

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

What is the process to carry out an accounting analysis?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago