Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, Need help writing this method, plus any tips on how you put it together would be great. Below is the section I need help

Java, Need help writing this method, plus any tips on how you put it together would be great. Below is the section I need help with. Also, the full Game and Player classes //--------------------------------------------------------------------------------------- // algorithm: 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. Returns true if the currentPlayer changes, false otherwise. //--------------------------------------------------------------------------------------- public boolean playGame() { if(gameOver == false) do { currentPlayer = takeTurn; if(currentPlayer == ) } return gameOver; }

*****************************************************************************************************

Game Class

****************************************************************************************************

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;

}

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

// algorithm: 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. Returns true if the currentPlayer changes, false otherwise.

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

public boolean playGame()

{

if(gameOver == false)

do

{

currentPlayer = takeTurn;

if(currentPlayer == )

}

return gameOver;

}

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

// 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()

{

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 + "}";

}

}

*********************************************************************************************************************

Player Class

**********************************************************************************************************************

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

// Player.java Author: 3-31-18

//

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

public abstract class Player

{

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

// declaring protected variables

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

protected String name;

protected int roundPoints, gamePoints;

protected boolean pigness;

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

// constructor for name

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

public Player(String name)

{

this.name = name;

}

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

// getter name

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

public String getName()

{

return name;

}

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

// getter RoundPoints

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

public int getRoundPoints()

{

return roundPoints;

}

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

// getter GamePoints

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

public int getGamePoints()

{

return gamePoints;

}

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

// getter boolean Pigness

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

public boolean getPigness()

{

return pigness;

}

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

//

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

public void takeTurn(PigDice p)

{

{

if(this.pigness)

{

this.roundPoints += p.roll();

this.pigness = false;

}

else

{

this.gamePoints += this.roundPoints;

this.roundPoints = 0;

}

}

}

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

//

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

public abstract boolean beAPig(boolean isPig);

@Override

public String toString()

{

return "Player{" +

"name = " + name +

", roundPoints =" + roundPoints +

", gamePoints =" + gamePoints +

", pigness =" + pigness + "}";

}

}

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

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

10. What is meant by a feed rate?

Answered: 1 week ago

Question

3. How can we confi rm both ourselves and others?

Answered: 1 week ago

Question

2. In what ways can confl ict enrich relationships?

Answered: 1 week ago