Question: Need help on Pig Dice Game program. I am confused on what to do with this step on the takeTurn Method. Below is what I
Need help on Pig Dice Game program. I am confused on what to do with this step on the takeTurn Method. Below is what I am trying to get done, along with my code. My PairOfDice and PigDice cannot change, I only need the method in the takeTurn from the Player class. Thank-you
Player Class
takeTurn method
input: PigDice
output: none
what I want to achieve "algorithm" If the players pigness is true rolls the PigDice and sets the Players roundPoints, gamePoints and pigness according to the roll
results, otherwise adds the roundPoints to the gamePoints and zeros out the roundPoints.
//*************************************************************************************
// 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)
{
}
//---------------------------------------------------------------------------------
//
//---------------------------------------------------------------------------------
public abstract boolean beAPig(boolean isPig);
@Override
public String toString()
{
return "Player{" +
"name = " + name +
", roundPoints =" + roundPoints +
", gamePoints =" + gamePoints +
", pigness =" + pigness + "}";
}
}
******************************************************************************************************************************************
PigDice Program
******************************************************************************************************************************************
//*******************************************************************************
// PigDice.java Author: 3-14-18
//
//*******************************************************************************
public class PigDice extends PairOfDice
{
//---------------------------------------------------------------------------
// Constructor PigDice
//---------------------------------------------------------------------------
public PigDice()
{
super();
}
//--------------------------------------------------------------------------
// Inheritance from PairOfDice
// Adjust the roll to output 3 everytime a 1 is rolled with any
// other number except one. Snake eyes produces sum: 2
//--------------------------------------------------------------------------
public int roll()
{
int sum = super.roll();
if (((getDie1()==1) && (getDie2()!=1)) || ((getDie2()==1) && (getDie1()!=1)))
sum = 3;
return sum;
}
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
public String toString()
{
int sum = getDie1() + getDie2();
if (((getDie1()==1) && (getDie2()!=1)) || ((getDie2()==1) && (getDie1()!=1)))
sum = 3;
return "\tDie 1: " + getDie1()
+ " \tDie 2: " + getDie2()
+ " \tSum: " + sum;
}
}
*********************************************************************************************************************************
PairOfDice program
**********************************************************************************************************************************
import javafx.scene.image.Image;
//********************************************************************
// PairOfDice.java Author: 3/14/2018
//
// Represents a Pair of Dice that aggregates two Die objects
// You may use this as a starting point for Project 1B if you wish
//********************************************************************
public class PairOfDice
{
//Class level variables
private Die die1, die2;
//-----------------------------------------------------------------
// Constructor: Instantiates the two Die objects and stores them
// as class level variables
//-----------------------------------------------------------------
public PairOfDice()
{
die1 = new Die();
die2 = new Die();
}
//-----------------------------------------------------------------
// die 1 value accessor (getter)
//-----------------------------------------------------------------
public int getDie1()
{
return die1.getFaceValue();
}
//-----------------------------------------------------------------
// die 2 value accessor (getter)
//-----------------------------------------------------------------
public int getDie2()
{
return die2.getFaceValue();
}
//-----------------------------------------------------------------
// die 1 value mutator (setter)
//-----------------------------------------------------------------
public void setDie1(int val)
{
die1.setFaceValue(val);
}
//-----------------------------------------------------------------
// die 2 value mutator (setter)
//-----------------------------------------------------------------
public void setDie2(int val)
{
die2.setFaceValue(val);
}
//-----------------------------------------------------------------
// Rolls both of the die objects and returns the sum of the roll
//-----------------------------------------------------------------
public int roll()
{
return die1.roll() + die2.roll();
}
//-----------------------------------------------------------------
// Returns a string representation of this PairOfDice object with
// the values labeled appropriately
// Overrides the toString method inherited from Object
//-----------------------------------------------------------------
public String toString()
{
return "Die 1: " + die1.toString()
+ " Die 2: " + die2.toString()
+ " \tSum: " + (die1.getFaceValue() + die2.getFaceValue());
}
//-----------------------------------------------------------------
// Image die1 (getter), from Die program aggregation
// PigDice program will use inheritance from PairOfDice program
//-----------------------------------------------------------------
public Image getDie1Image()
{
return die1.getDieImage();
}
//-----------------------------------------------------------------
// Image die2 (getter), from Die program aggregation
// PigDice program will use inheritance from PairOfDice program
//-----------------------------------------------------------------
public Image getDie2Image()
{
return die2.getDieImage();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
