Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, need help with this gameOver method //--------------------------------------------------------------------------------------- if either player's current round points + accumulated game points is greater or equal to the winning

Java, need help with this gameOver method

//---------------------------------------------------------------------------------------

if either player's current round points + accumulated game points is greater or equal to the winning score,

sets the value of game over to true (false otherwise) and returns the result.

//---------------------------------------------------------------------------------------

public boolean gameOver()

{

if(roundPoints + gamePoints >= WINNING_SCORE)

{

gameOver return true;

}

return gameOver;

}

Full code:

import java.util.Scanner;

//******************************************************************************************

//

//

//******************************************************************************************

public class Game

{

private static final String WINNER_SCORE = null;

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

private Player p1, p2, current;

private PigDice d;

private boolean gameOver;

private final int WINNING_SCORE = 100;

//---------------------------------------------------------------------------------------

//creates the two players and a pigDice, initializes the current player to start the game

//and sets game over condition to false.

//---------------------------------------------------------------------------------------

public Game()

{

Scanner scan = new Scanner(System.in);

p1 = new Player("Player")

{

@Override

public boolean beAPig(boolean isPig)

{

return false;

}

};

p2 = new Player("Computer")

{

@Override

public boolean beAPig(boolean isPig)

{

return false;

}

};

current = p1;

}

//---------------------------------------------------------------------------------------

// if the game is not over, has the current player take its turn.

// If the current players pigness value is false after the turn, switches the

// current player.

//---------------------------------------------------------------------------------------

public boolean playGame()

{

if(!gameOver)

{

current.takeTurn(d);

if(!current.getPigness())

{

if(current == p1)

{

current = p2;

return true;

}

else

{

current = p1;

return true;

}

}

}

return false;

}

//---------------------------------------------------------------------------------------

// if either player's current round points + accumulated game points is

// greater or equal to the winning score,

// sets the value of game over to true (false otherwise) and returns the result.

//---------------------------------------------------------------------------------------

public boolean gameOver()

{

if(roundPoints + gamePoints >= WINNING_SCORE)

{

gameOver return true;

}

return gameOver;

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public Player getCurrentPlayer()

{

return p1;

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public Player getHuman()

{

return p2;

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public Player getComputer()

{

return getComputer();

}

//--------------------------------------------------------------------------------------

//

//--------------------------------------------------------------------------------------

public PigDice getPigDice()

{

return d;

}

//--------------------------------------------------------------------------------------

//

//--------------------------------------------------------------------------------------

public String toString()

{

return "Game{" +

"p1=" + p1 +

",p2=" + p2 +

",current=" + current +

", d=" + d +

",gameOver=" + gameOver +

",WINNER_SCORE=" + WINNER_SCORE + "}";

}

}

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

More Books

Students also viewed these Databases questions

Question

Compare Jung and Adlers theories to Freuds psychoanalysis.

Answered: 1 week ago