Hi am new to java and i have a program my teacher wants us to practice and write. Here is the program instructions: Using the PairOfDice class from programming project 5.10, design and implement a class to play a game called Pig. In this game,...
Hi am new to java and i have a program my teacher wants us to practice and write.
Here is the program instructions:
Using the PairOfDice class from programming project 5.10, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a 1, all points accumulated for that round are forfeited and control of the dice moves to the other player. If the player rolls two 1’s in one turn, the player loses all points accumulated thus far in the game and loses control of the dice. The player may voluntarily turn over the dice after each roll. There for the player must decide to either roll again (be a Pig) and risk losing points or relinquish control of the dice, possibly allowing the other player to win. Implement the computer player such that it always relinquishes the dice after accumulating 20 or more points in any given round.
Here are the 5 classes required
Die:
public class Die {
private final int MAX = 6;
private int faceValue;
public Die() {
faceValue = 1;
}
public int roll() {
faceValue = (int) (Math.random() * MAX) + 1;
return faceValue;
}
public void setFaceValue(int value) {
if (value > 0 && value =goal)
rollAgain=false;
else
if (limit==ASK){
System.out.println("Take another turn (Y/N)?");
Scanner sc =new Scanner(System.in);
String again=sc.nextLine();
rollAgain=again.equalsIgnoreCase("Y");
}
else
if(round>=limit)
rollAgain=false;
if(rollAgain){
total+=round;
round=0;
}
return rollAgain;
}
public int getPoints(){
return total;
}
}
PlayPig
import java.util.*;
class PlayPig
{
public static void main(String[]args)
{
Pig game = new Pig(100);
game.play();
}
}
Pig
(I have no idea what to do for this class. I know that PlayPig class want to run game from this Pig class but I have no idea what im suppose to be doing. I have email my teacher and he said to ask the tutors but they are closed today and he wants us to turn it in by 11:59 pm tonight which is in 3.5 hours for me. i have go this far and have no idea what to do now. The pig class is suppose to manage the players but i have now idea how to set it up and link the game.play method.(teacher gave us the playpig class)
Thanks for your time and help!