Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We are making a Pigdice game without Loops and Arrays . I am stuck on how to get

ID: 3707331 • Letter: W

Question

We are making a Pigdice game without Loops and Arrays. I am stuck on how to get everything working. Im not worried about the GUIDriver but please help on the other classes.

the main things that need to happen are the rollButton(roll dice/beAPIG), the passButton(pass turn), and the continue Button(see each roll number) ex: player rolled a 3. continue? yes. player rolled a 4 conitnue? The computer AI has to always be a pig if its roundpoints are below 20. both players(if its their turn)lose their round points if rolled a 2 or a 3 and lose both round and game points if rolled snake eyes. The classes must work with the gametester.

The stage view should look like:

dont worry toomuch on the text such as "player rolled a 4" because I can always go back and do that.

The .PNG files dont really matter they are just the die facevalue images you can just get any facevalue 1-6 images from google and put them in. these are the .PNG I use.

These are the classes I have to use:

This is the algorithm of what each class has to do:

GUIDriver Class:

                processButtonPress method

                                input: ActionEvent

                                output: none

algorithm: if the game is not over, calls the beAPig method for the current player with the value of true if the human rollbutton is the ActionEvent, or fals otherwise. Next, calls the playGame method and updates the GUI components accordingly.

Game Class:

                Game constructor method

                                Input: none

                                Output: none

Algorithm:creates the two players and a pigDice, initializes the current player to start the game and sets “game over” conditions to false.

                playGame method

                                input: none

                                output: boolean: true if currentPlayer changes, false otherwise

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. Return true if the currentPlayer changes, false otherwise.

                gameOver method

                                input: none

                                output: boolean: true if the game is over, false otherwise

algorithm: if either players current round points + accumulated game points is greater or equal to the winning score, sets the value of a game over to true ( false otherwise) and returns the result.

Player Class:

                takeTurn method

                                input: PigDice

                                output: none

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.

Human Class:

                beAPig method

                                input: Boolean pigness

                                output: Boolean value of pigness

algorithm: sets the value of the pigness variable to the input parameter and returns the same value

Computer Class:

                beAPig method

                                input: Boolean pigness

                                output: Boolean value of pigness

sets the value of the pigness variable according to the AI rules for a computer player and ignores the input value

This is what I have done so far:

Die.java:

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

// Die.java Author: Lewis/Loftus/DuVall-Early Updated 3/21/16

//

// Represents one die (singular of dice) with faces showing values

// between 1 and 6.

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

import javafx.scene.image.Image;

public class Die

{

private final int MAX = 6; // maximum face value

private int faceValue; // current value showing on the die

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

// Constructor: Sets the initial face value.

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

public Die()

{

faceValue = 1;

}

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

// Rolls the die and returns the result.

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

public int roll()

{

faceValue = (int)(Math.random() * MAX) + 1;

return faceValue;

}

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

// Face value mutator.

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

public void setFaceValue (int value)

{

faceValue = value;

}

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

// Face value accessor.

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

public int getFaceValue()

{

return faceValue;

}

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

// Image accessor

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

public Image getDieImage()

{

Image dieImage = null; //image assigned from DiceImages files based on faceValue of Die

switch (faceValue)

{

case 1: dieImage = new Image("1.png");

break;

case 2: dieImage = new Image("2.png");

break;

case 3: dieImage = new Image("3.png");

break;

case 4: dieImage = new Image("4.png");

break;

case 5: dieImage = new Image("5.png");

break;

case 6: dieImage = new Image("6.png");

break;

}

return dieImage;

}

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

// Returns a string representation of this die.

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

public String toString()

{

String result = Integer.toString(faceValue);

return result;

}

}

Computer.java:

public class Computer extends Player
{
public Computer(String name)
{
super(name);
}
}

Game.java:

public class Game

{

private Player p1, p2, current;

private PigDice d;

private boolean GameOver= true;

private final int WINNING_SCORE=100;

public void Game()

{

current = p1;

}

public void playGame()

{

}

public void gameOver()

{

}

public void getCurrentPlayer()

{

return;

}

public void getHuman()

{

return;

}

public void getComputer()

{

return;

}

public void getPigDice()

{

}

public String toString()

{

return null;

}

}

GameTester.java:

import java.util.Scanner;

public class GameTester

{

public static void main(String[] args)

{

Game g = new Game();

Scanner s = new Scanner(System.in);

while (!g.gameOver())

{

System.out.println(g.getCurrentPlayer().getName() + "'s turn");

System.out.print(" Be a Pig (Y/N)? ");

g.getCurrentPlayer().beAPig(s.nextLine().toUpperCase().equals("Y"));

g.playGame();

System.out.println("Dice: " + g.getPigDice().toString());

System.out.println(g.getHuman().toString());

System.out.println(g.getComputer().toString());

}

System.out.println("The winner is "

+ (g.getHuman().getGamePoints() > g.getComputer().getGamePoints() ? g.getHuman().getName() : g.getComputer().getName()));

}

}

Human.java:

import java.util.Scanner;

public class Human extends Player

{

public Human(String n)

{

super(n);

System.out.println("Would you like to roll again [y/n]? ");

}

public boolean beAPig()

{

return true;

}

}

PairOfDice.java:

//******************************************************************************
// PairOfDice.java Author: DuVall-Early 3/21/16
//
// Aggregates 2 Die objects to represent a pair of dice
//******************************************************************************
import javafx.scene.image.Image;

public class PairOfDice
{
private Die die1;
private Die die2;

//******************************************************************************
//Create a new pair of dice
//******************************************************************************
public PairOfDice()
{
die1 = new Die();
die2 = new Die();
}

//******************************************************************************
//Get faceValue for die1
//******************************************************************************
public int getDie1()
{
return die1.getFaceValue();
}

//******************************************************************************
//Get faceValue for die2
//******************************************************************************
public int getDie2()
{
return die2.getFaceValue();
}

//******************************************************************************
//Set faceValue for die1
//******************************************************************************
public void setDie1(int value)
{
die1.setFaceValue(value);
}

//******************************************************************************
//Set faceValue for die2
//******************************************************************************
public void setDie2(int value)
{
die2.setFaceValue(value);
}

//******************************************************************************
// Returns the image for the first Die object
//******************************************************************************
public Image getDie1Image()
{
return die1.getDieImage();
}

//******************************************************************************
// Returns the image for the Second Die object
//******************************************************************************
public Image getDie2Image()
{
return die2.getDieImage();
}

//******************************************************************************
//Roll the pair of dice
//******************************************************************************
public int roll()
{
int val1 = die1.roll();
int val2 = die2.roll();

return val1 + val2;
}

//******************************************************************************
// Returns a string representation
//******************************************************************************
public String toString()
{
return "Die 1: " + die1.toString() + " Die 2: " + die2.toString() + " Total: "
+ (die1.getFaceValue() + die2.getFaceValue());
}
}

PigDice.java:

//********************************************************************
// PigDice.java Author: DuVall-Early 3/21/16
//
// Extends PairOfDice class to customize roll and toString methods for Pig Game
//********************************************************************
public class PigDice extends PairOfDice
{

//********************************************************************
//Overrides the PairOfDice roll method to provide a pig sum
//********************************************************************
public int roll()
{
int result = super.roll();
if ((result != 2) && (super.getDie1() == 1 || super.getDie2() == 1))
result = 3;
return result;
}

//********************************************************************
//Overrides the toString method to use the adjusted pig sum
//********************************************************************
public String toString()
{
int sum = super.getDie1() + super.getDie2();
sum = (sum!=2 && (super.getDie1() == 1 || super.getDie2() == 1)? 3 : sum);
String state = "Die 1: " + super.getDie1() + " Die 2: " + super.getDie2() + " Sum: " + sum;
return state;
}
}

Player.java:

import java.lang.String;

public abstract class Player

{

protected int roundPts;

protected int gamePts;

protected String name;

protected boolean pigness;

public Player(String n)

{

name = n;

  

}

public String getName()

{

return name;

}

public int getRoundPts()

{

return roundPts;

}

public int getGamePts()

{

return gamePts;

}

public boolean getPigness()

{

return pigness;

}

public void setPigness()

{

}

public void takeTurn(PigDice p)

{

if (pigness == true)

{

p.roll();

getGamePts

return roundPts;

else

{

gamePts = gamePts + roundPts;

}

}

}

@Override

public String toString()

{

return ("Points earned this round " + roundPts) +

("Total is" + (roundPts + gamePts));

}

public void setGamePts(int Val)

{

gamePts += Val;   

}

public void setRoundPts(int Val)

{

roundPts += Val;

}

  

public abstract boolean beAPig();

}

cx

Explanation / Answer

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class PigWithGraphicsPanel extends JPanel

{

private JButton roll;

private JButton hold;

private JButton computersTurn;

private JPanel panel;

public static JLabel pScore;

public static JLabel cScore;

public static JLabel pScorePerRound;

public static JLabel pPointsPerRoll;

public static JLabel cPointsPerRoll;

public static JLabel cPointsPerRound;

public static JLabel cPointsPerGame;

public static int computersPoints;

static int playersPointsPerRound;

static int playersPointsPerRoll;

static int playersPoints;

final static int WinningScore= 100;// the game is played to 100 points//

static int computersPointsPerRoll;

public static int computersPointsPerRound;

static int sentinalForPlayer;

static int sentinalForComputer;

static int roundNumber;

static int numberOfOnes;

public PigWithGraphicsPanel()

{

roll = new JButton("Roll");

roll.setEnabled(true);

hold = new JButton ("Hold");

hold.setEnabled(true);

computersTurn = new JButton ("Switch");

computersTurn.setEnabled(false);

pPointsPerRoll = new JLabel("You scored " + playersPointsPerRoll+ " this roll");

pScorePerRound = new JLabel ("Your points per round are " + playersPointsPerRound);

pScore = new JLabel("Your final score is " + playersPoints);

cPointsPerRoll = new JLabel ("The computer scored " + computersPointsPerRoll + " with this roll");

cPointsPerRound = new JLabel ("The computers total score this round is " + computersPointsPerRound);

cPointsPerGame = new JLabel ("THe computers total points are " + computersPoints);

ButtonListener listener = new ButtonListener();

ComputerListener compLis = new ComputerListener();

roll.add(listener);

hold.add(listener);

computersTurn.add(compLis);

panel = new JPanel();

panel.setPreferredSize(new Dimension(200,400));

panel.setBackground(Color.blue);

add(pPointsPerRoll);

add(pScorePerRound);

add(pScore);

add(roll);

add(hold);

add(computersTurn);

add(cPointsPerRoll);

add(cPointsPerRound);

add(cPointsPerGame);

}

private class ButtonListener implements ActionListener

{

public void actionPerformed (ActionEvent event)

{

PairOfDice playersDice = new PairOfDice();// creates a new pair of dice for the player//

playersDice.roll();

int playersRoll1= playersDice.getValue1();//gets the value of the first dice//

int playersRoll2= playersDice.getValue2();// gets the value of the second dice//

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote