[INDENT][INDENT][INDENT][INDENT]This matching game should be reset to a new game with different colours, but it does not? Can someone help
(sorry not button, it should be function)
OOCW2Last.java
import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; import java.util.Random; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.UIManager; public class OOCW2Last { public static final int WIDTH = 4; public static final int HEIGHT = 4; public static final int COLOURS = 4; public static final int MAX_PER_COLOUR = 4; public static final int BUT_SIZE = 100; int player1Score = 0; int player2Score = 0; int butNumber1 = 0; int butNumber2 = 0; public int turn = 1; boolean player1 = true; boolean matchedColours; int i = 0; JLabel top = new JLabel("Player 1"); JLabel bottom = new JLabel("Player 2"); Color[] colors = new Color[8]; ColorButton[] arrayButtons = new ColorButton[WIDTH*HEIGHT]; Random rand = new Random(); JFrame mainGUI = new JFrame(); JPanel panelMain = new JPanel(); boolean firstRun = true; public static void main(String[] args) { OOCW2Last main = new OOCW2Last(); main.createGUI(); } public void createGUI() { top.setBackground(Color.GREEN); top.setOpaque(true); bottom.setBackground(Color.RED); bottom.setOpaque(true); panelMain.setLayout(new GridLayout(WIDTH,HEIGHT)); initButtons(); mainGUI.getContentPane().add(top, BorderLayout.NORTH); mainGUI.getContentPane().add(bottom, BorderLayout.SOUTH); mainGUI.getContentPane().add(panelMain,BorderLayout.CENTER); mainGUI.pack(); mainGUI.setResizable(false); mainGUI.setVisible(true); message(bottom,top); } public void initButtons() { System.out.println("reset"); int x = MAX_PER_COLOUR; int y = WIDTH*HEIGHT; int z; for (int i = 0; i < WIDTH*HEIGHT; i++) { arrayButtons[i] = new ColorButton(i, BUT_SIZE, BUT_SIZE, this); if(firstRun) panelMain.add(arrayButtons[i]); arrayButtons[i].setButtonFin(false); arrayButtons[i].setButtonState(0); arrayButtons[i].setBackground(Color.gray); arrayButtons[i].colorPicked = false; } colors[0] = Color.blue; colors[1] = Color.yellow; colors[2] = Color.cyan; colors[3] = Color.red; colors[4] = Color.orange; colors[5] = Color.green; colors[6] = Color.white; colors[7] = Color.pink; for (int i = 0; i < COLOURS; i++) { while(x > 0) { z = rand.nextInt(y); while (arrayButtons[z].colorPicked == true){ z = rand.nextInt(y); } arrayButtons[z].realButtonColor = colors[i]; //get the real colours for the button from the array arrayButtons[z].colorPicked = true; arrayButtons[z].flip(false); //set all colours to grey front x --; } x = MAX_PER_COLOUR; } } public void reset(){ initButtons(); player1Score = 0; player2Score = 0; turn = 0; player1=true; message(bottom, top); } public int getTurn(){ // this gets the turn and returns it to ColorButton return turn; } }