private void newGame() { NewGameDialog ngd = new NewGameDialog(); goc = new GameOfCluedo(); goc.startGame(ngd.getPlayers("New Game")); can_board.setBoard(goc.getBoard()); showButtons(); enableButtons(); btn_guess.setEnabled(false); ImageIcon img = new ImageIcon(myPicture[goc.getCurrentPlayer().getCharacter().ordinal()]); picLabel.setIcon(img); txt_name.setText(goc.getCurrentPlayer().getName()); // JOptionPane.showMessageDialog(this, goc.getCurrentPlayer().getName() + "'s Turn"); repaint(); }
private void accusePressed() { GuessDialog ac = new GuessDialog(); if (goc.accuse(ac.getGuess("Accuse"))) { System.out.println("You win"); goc.setWinner(goc.getCurrentPlayer()); // Correct set winner and end game endTurn(); } else { System.out.println("You lost"); String playerName = goc.getCurrentPlayer().getName(); goc.playerLost(goc.getCurrentPlayer()); // Wrong remove player from play endTurn(); if (goc != null && !goc.checkGameOver()) { can_board.setBoard(goc.getBoard()); JOptionPane.showMessageDialog(this, playerName + " has been eliminated"); } } }
private void movePressed() { if (!moveSelected && goc.canMove()) { goc.die.roll(); lbl_dice.setIcon(goc.die.getDiceIcon()); if (goc.highlightValidMoves()) { btn_guess.setEnabled(false); btn_accuse.setEnabled(false); moveSelected = true; can_board.setBoard(goc.getBoard()); } else { btn_move.setEnabled(false); JOptionPane.showMessageDialog(this, " There are no valid moves"); if (!goc.getPlayerPos().isRoom()) { endTurn(); } } } }
private void endTurn() { if (goc.checkGameOver()) { showGameOver(); return; } goc.endTurn(); can_board.setBoard(goc.getBoard()); ImageIcon img = new ImageIcon(myPicture[goc.getCurrentPlayer().getCharacter().ordinal()]); picLabel.setIcon(img); txt_name.setText(goc.getCurrentPlayer().getName()); // if new player not in room disable guess if (!goc.getPlayerPos().isRoom()) { btn_guess.setEnabled(false); } else { btn_guess.setEnabled(true); } btn_move.setEnabled(true); // JOptionPane.showMessageDialog(this, goc.getCurrentPlayer().getName() + "'s Turn"); }
public boolean showGameOver() { int popup = 0; if (goc.getWinner() == null) { popup = JOptionPane.showConfirmDialog( null, "Game Over!\nAll players eliminated.\n\nDo you want to play again?", "Game Over", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); } else { popup = JOptionPane.showConfirmDialog( null, "Game Over!\n" + goc.getWinner().getName() + " has guessed the envelope.\n\nDo you want to play again?", goc.getWinner().getName() + " Won", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); } if (popup == JOptionPane.YES_OPTION) { newGame(); return true; } else { goc = null; can_board.setBoard(null); picLabel.setIcon(new ImageIcon(myPicture[myPicture.length - 1])); txt_name.setText("Dr. Black"); disableButtons(); hideButtons(); repaint(); } return false; }