import javax.swing.*; import java.awt.*; import java.lang.Math; public class Memory extends java.applet.Applet { private int xMouse; private int yMouse; private boolean mouseClicked = false; private boolean firstRun = true; private static final int WIDTH = 100; //add the rest of your instance variables here /*Sets the background of your memory board to black*/ public void init() { setBackground(Color.BLACK); } /*This is main in java applets You may need to add (not change) a couple things in this method */ public void paint(Graphics canvas) { if(firstRun) //for the first run we need to build our random board { buildBoard(4); firstRun = false; } else // once our board is built we will display the game { displayGame(canvas); if (mouseClicked) // if the mouse has been clicked { displayHit(canvas);//find which box the user clicked mouseClicked = false; } } } /* DO NOT change this method determins if the mouse has been pressed sets x and y Mouse to the location of the mouse arrow redraws the image */ public boolean mouseDown(Event e, int x, int y ) { mouseClicked = true; xMouse = x; yMouse = y; repaint(); return true; } /*DO NOT change this method redraws the scene */ public void update ( Graphics g ) { paint(g); } /* pre: none post: build an array that holds the memory vales for a board of size x size the board will hold two of each int from 0 to size randomly placed in the array */ public void buildBoard(int s) { } public void displayGame(Graphics canvas) { canvas.setColor(Color.WHITE); for(int i =0; i < 400; i+= WIDTH) for(int j = 0; j < 400; j+= WIDTH) canvas.drawRect(i, j, WIDTH, WIDTH); } /* Pre: xMouse and yMouse have been initialized Post: A circle is displayed in the correct box on the screen Currenlty the circle is displayed at the mouse location */ public void displayHit(Graphics g) { g.setColor(Color.WHITE); g.fillOval(xMouse, yMouse, 40, 40); } }