Question: I need help writing this code for computer science in eclispe I got the code for game of pig I want to check and compare

I need help writing this code for computer science in eclispe I got the code for game of pig I want to check and compare my solution here is what I have now private void switchPlayer(){
currentPlayerIndex =(currentPlayerIndex +1)%2;
if (scores[currentPlayerIndex]>= WINNING_SCORE){
// Game over, record result
String result = "Player "+(currentPlayerIndex +1)+" wins!";
LocalDateTime dateTime = LocalDateTime.now();
int totalPoints = scores[currentPlayerIndex];
GameRecord gameRecord = new GameRecord(result, dateTime, totalPoints, "Player "+(currentPlayerIndex +1));
gameHistory.add(gameRecord);
// Reset scores for a new game
scores = new int[]{0,0};
}
}
@SuppressWarnings("hiding")
private void updateUI(){
gameofpig.currentPlayerLabel.setText("Current Player: Player "+(currentPlayerIndex +1));
roundScoreLabel .setText("Round Score: "+ scores[currentPlayerIndex]);
}
private int rollDice(){
return new Random().nextInt(6)+1;
}
private static class GameRecord {
private String result;
private LocalDateTime dateTime;
private int totalPoints;
private String player;
public GameRecord(String result, LocalDateTime dateTime, int totalPoints, String player){
this.result = result;
this.dateTime = dateTime;
this.totalPoints = totalPoints;
this.player = player;
}
}
}

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!