Question: Could use this help as fast as possible. In JavaFX, I have 3 buttons piggy, pass for the player. And I have computer for the
Could use this help as fast as possible. In JavaFX, I have 3 buttons piggy", "pass" for the player. And I have "computer" for the computer turn. I am trying to write a statement that turns on the proper buttons with the turn of the player and computer. Something like:
if (player turn)
pass button, piggy button is on, computer button is off/disabled
else(computer turn)
computer button is on, piggy and pass button are off/disabled
So, I am going to only list my GUI code because it seems that if I were to list the other classes that my question will never get looked at.
All I want is really a push in the right direction here, what would you do??? and what location in the class should a statement to handle this issue be placed. If you just look at this code and give me your algorithm along with placement, then I will be very happy. Even if it doesn't work, I hope it shows me something to move me along in solving this issue. Thank-you very much
Note: I can give the rest of the classes upon request, however, I don't need this tested, just your thoughts on what you would do. In fact, I already having the same question with all the code listed and sitting for over 24 hours, you could probably pull that question easy if you want all the code. I just figure the less to comb through the more likely you get help.
//*************************************************************************
public class GUIDriver extends Application
{
private Text sumText, humanScore, computerScore, currentPlayerIs;
private ImageView die1View, die2View;
private Game g;
private Button piggy, pass, proceed;
//-----------------------------------------------------------------------
// Constructor: creates ImageView, Flowpane etc.
// Initializing sumText, images pig1, pig2
//-----------------------------------------------------------------------
public void start(Stage primaryStage)
{
//--------------------------------------------------------------------
// declaring variables
//--------------------------------------------------------------------
g = new Game();
sumText = new Text ("Sum is: 0");
humanScore = new Text(g.getHuman().toString());
computerScore = new Text(g.getComputer().toString());
Image pig1 = g.getPigDice().getDie1Image();
Image pig2 = g.getPigDice().getDie2Image();
die1View = new ImageView(pig1);
die2View = new ImageView(pig2);
//--------------------------------------------------------------------
// creates the piggy button, if piggy is pressed it does an action
//--------------------------------------------------------------------
piggy = new Button ("Roll like a pig!");
piggy.setOnAction(this::processButtonPress);
//---------------------------------------------------------------------
// creates the pass button, if pass is pressed it does an action
//---------------------------------------------------------------------
pass = new Button ("Pass like a pansy!");
pass.setOnAction(this::processButtonPress);
//----------------------------------------------------------------------
// creates the proceed button, if proceed is pressed it does an action
//----------------------------------------------------------------------
proceed = new Button ("Computer");
proceed.setOnAction(this::processButtonPress);
//----------------------------------------------------------------------
// creates Flowpane, position, and color
//---------------------------------------------------------------------------
FlowPane pane = new FlowPane(die1View, die2View, piggy, pass, proceed, sumText, humanScore, computerScore);
pane.setPrefWrapLength(100);
pane.setStyle("-fx-background-color: lightgreen");
pane.setAlignment(javafx.geometry.Pos.CENTER);
pane.setHgap(10);
pane.setVgap(20);
//---------------------------------------------------------------
// Setting scene and title
//---------------------------------------------------------------
Scene scene = new Scene(pane, 800, 600);;
primaryStage.setTitle("Pigger Game");
primaryStage.setScene(scene);
primaryStage.show();
}
//-------------------------------------------------------------------
// If game is not over, calls the beAPig method for current Player
// Calls playGame method and updates the GUI components accordingly
//-------------------------------------------------------------------
public void processButtonPress(ActionEvent event)
{
if(!g.gameOver())
{
if(piggy == event.getSource())
{
g.getCurrentPlayer().beAPig(true);
}
else
{
g.getCurrentPlayer().beAPig(false);
}
if(g.playGame() == true)
{
}
die1View.setImage(g.getPigDice().getDie1Image());
die2View.setImage(g.getPigDice().getDie2Image());
sumText.setText("Sum is: " + g.getPigDice().toString());
humanScore.setText(g.getHuman().toString());
computerScore.setText(g.getComputer().toString());
currentPlayerIs.setText(g.getCurrentPlayer().getName());
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
