java - trying to change a label on an event or board state -



java - trying to change a label on an event or board state -

hello fellow nerds have question! working on project due quarta-feira , stuck half way through. game 2 player game each player takes turn selecting list of 16 nodes which, when clicked add together hidden value players score. project given label reads "player 1's turn" default , part of assignment asks create alter text represent who's turn currently. turn changes after current player guesses square. there "hold" button current player can skip turn (there "bust" square hidden sets current player's score zero). think can figure part out after part done. guys please help point me in right direction? please don't solve me. want larn stuff, need direction/advise.

here looks when runs: image

thanks help, site amazing! here relevant code:

public class guicodebehind { private viewmodel theviewmodel; private list<button> buttons; private list<node> boardnodes; @fxml private gridpane boardgridpane; @fxml private button holdbutton; @fxml private label gamestatuslabel; @fxml private textfield player1scoretextfield; @fxml private textfield player2scoretextfield; public guicodebehind() { this.theviewmodel = new viewmodel(); this.createbuttons(); } /** * initializes gui components, binding them view model properties * , setting event handlers. */ @fxml public void initialize() { this.bindguicomponentstoviewmodel(); this.addbuttonstoboard(); this.boardnodes = this.boardgridpane.getchildren(); this.seteventactions(); } private void createbuttons() { this.buttons = new arraylist<button>(); (int = 0; < 16; i++) { this.buttons.add(this.createbuttonwithid(i)); } } private button createbuttonwithid(int id) { string buttonid = "" + (id + 1); button abutton = new button(" ? "); abutton.setmaxwidth(double.max_value); abutton.setid(buttonid); homecoming abutton; } private void addbuttonstoboard() { (int row = 0; row < 4; row++) { this.addarow(row); } } private void addarow(int row) { (int column = 0; column < 4; column++) { this.boardgridpane.add(this.buttons.remove(0), column, row); } } private void bindguicomponentstoviewmodel() { this.player1scoretextfield.textproperty(). bindbidirectional(this.theviewmodel.player1scoreproperty()); this.player2scoretextfield.textproperty(). bindbidirectional(this.theviewmodel.player2scoreproperty()); } private void seteventactions() { (node abutton: this.boardnodes) { abutton.setonmouseclicked(event -> this.handleboardbuttonclick(abutton)); } } private void handleboardbuttonclick(node abutton) { abutton.setdisable(true); this.holdbutton.requestfocus(); this.theviewmodel.play(abutton.getid()); ((button) abutton).settext(this.theviewmodel.selectedsquaredescription()); } }

the viewmodel:

/** * viewmodel defines view model play-or-hold application. */ public final class viewmodel { private string descriptionofselectedsquare; private final player player1; private final player player2; private final gameboard theboard; private final gamecontroller thegamecontroller; private stringproperty player1score; private stringproperty player2score; private stringproperty gamestatus; /** * creates new viewmodel instance. * * @precondition none * @postcondition object , properties exist */ public viewmodel() { this.descriptionofselectedsquare = ""; this.player1 = new regularplayer(); this.player2 = new privilegedplayer(); gameboardfactory mill = new onedoublepointsboardfactory(true); this.theboard = factory.getgameboard(); this.thegamecontroller = new gamecontroller(this.theboard, this.player1, this.player2); this.player1score = new simplestringproperty("0"); this.player2score = new simplestringproperty("0"); } /** * returns property represents score player 1. * * @precondition none * @return property */ public stringproperty player1scoreproperty() { homecoming this.player1score; } /** * returns property represents score player 2. * * @precondition none * @return property */ public stringproperty player2scoreproperty() { homecoming this.player2score; } /** * tells game controller carry out current * player's move. * * @precondition 1 <= gamesquareid <= 16 * @postcondition current player's score reflects move, && * currentmovevalue() returns value of * @param gamesquareid id of selected command in gui */ public void play(string gamesquareid) { int squareindex = integer.parseint(gamesquareid) - 1; this.thegamecontroller.play(squareindex); this.descriptionofselectedsquare = this.theboard.getsquare(squareindex).getdescription(); this.player1score.setvalue("" + this.player1.getscore()); this.player2score.setvalue("" + this.player2.getscore()); } /** * returns value of current "move". * * @precondition none * @return value of selected game board item */ public string selectedsquaredescription() { homecoming this.descriptionofselectedsquare; } public stringproperty gamestatusstringproperty() { homecoming this.gamestatus; } }

java

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -