public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("New Game")) { newGame(); } if (e.getActionCommand().equals("Exit Game")) { exit(); } if (e.getActionCommand().equals("About")) { JDialog f = new JDialog(); f.add(new JLabel(new ImageIcon("splash_applet.jpg"))); f.setSize(660, 520); f.setLocationRelativeTo(this); f.setVisible(true); } }
/** * * Method that deals with the menu options * @param event the event that triggered this method */ public void actionPerformed(ActionEvent event) { if (event.getSource() == newMenuItem) { try { tableArea.newGame(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (event.getSource() == topScoresOption) { } else if (event.getSource() == quitMenuItem) { System.exit(0); } else if (event.getSource() == aboutMenuItem) { JOptionPane.showMessageDialog( tableArea, "By Jeffrey Wang and Hayes Lee\n\u00a9 2015", "About Neon Hex", JOptionPane.INFORMATION_MESSAGE); } }
Board() { addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { exit(); } }); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(screenSize); setLocation(0, 0); r3 = Math.sqrt(3); Button ng, eg, ab; ng = new Button("New Game"); eg = new Button("Exit Game"); ab = new Button("About"); gold = new ImageIcon("./coin2.jpg").getImage(); silver = new ImageIcon("./coin1.jpg").getImage(); Panel pan = new Panel(); pan.setLayout(new FlowLayout()); pan.add(ng); pan.add(eg); pan.add(ab); setLayout(new BorderLayout()); add(pan, BorderLayout.NORTH); newGame(); ng.addActionListener(this); eg.addActionListener(this); ab.addActionListener(this); addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { int mx = e.getX(), my = e.getY(); place(mx, my); } }); }
void place(int mx, int my) { if (drme) { drme = false; return; } int n = data.a.length; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (((mx - data.a[i][j].x) * (mx - data.a[i][j].x) + (my - data.a[i][j].y) * (my - data.a[i][j].y) < bst.scale * bst.scale * .75) && data.a[i][j].getState() == 0) { if (count == 1 && gst.swap) { int ch = JOptionPane.showConfirmDialog( this, "Swap moves?", "Swap", JOptionPane.YES_NO_OPTION); if (ch == JOptionPane.YES_OPTION) { lmv.setState(cst); switch (cst) { case 1: data.a[i][j].setState(2); break; case 2: data.a[i][j].setState(1); break; } repaint( (int) (lmv.x - 0.8 * bst.scale), (int) (lmv.y - 0.8 * bst.scale), (int) (1.6 * bst.scale), (int) (1.6 * bst.scale)); if (AIMethods.gameOver(this, lmv.i, lmv.j, count)) { newGame(); } if (gst.ai != null) gst.ai.updateAI(lmv.i, lmv.j, lmv.getState(), count); } else data.a[i][j].setState(cst); } else data.a[i][j].setState(cst); lmv = data.a[i][j]; repaint( (int) (data.a[i][j].x - 0.8 * bst.scale), (int) (data.a[i][j].y - 0.8 * bst.scale), (int) (1.6 * bst.scale), (int) (1.6 * bst.scale)); switch (cst) { case 1: cst = 2; break; case 2: cst = 1; break; } if (AIMethods.gameOver(this, lmv.i, lmv.j, count)) { System.out.println("Game Over"); firstrun = true; String win = ""; if (lmv.getState() == Block.RED_BEAD) { switch (gst.theme) { case 0: win = "Red"; break; case 1: win = "Black"; break; case 2: win = "Gold"; break; } } else { switch (gst.theme) { case 0: win = "Blue"; break; case 1: win = "Green"; break; case 2: win = "Silver"; break; } } if (gst.audio) AePlayWave.play(AePlayWave.END); JOptionPane.showMessageDialog( this, win + " wins", "Game Over", JOptionPane.INFORMATION_MESSAGE); newGame(); return; } if (gst.audio) { if (gst.ai == null) AePlayWave.play(AePlayWave.PLACE); else if (userMove) AePlayWave.play(AePlayWave.AIMOVE); } count++; if (gst.ai != null && userMove) { userMove = false; gst.ai.nextMove(lmv.i, lmv.j, lmv.getState(), count); } else userMove = true; return; } } } if (gst.audio) AePlayWave.play(AePlayWave.BLOCK); }
public void newGame() { board.newGame(); board.setCurrentPlayer(player1); }