import java.awt.*; import java.applet.*; public class coin_flip extends Applet { /* values assigned to white and black */ static final int WHITE = 1, BLACK = 2, N = 4, N2 = N*N; static final int NONE = -1; /* win determines when the game is won * color determines color of each position * circ = N^2 * 5 circulant matrix * xoff = x offset * yoff = y offset * width = width of applet * height = height of applet */ private char win='n'; private static int color[][] = new int[N][N]; private static int circ[][] = new int[N2][5]; private static int xoff, yoff, width, height; public void init() { build_circulant(); init_game(); Dimension d = size(); xoff = d.width / N; yoff = d.height / (N+1); width = d.width; height = d.height; } public void paint(Graphics g) { /* draw blue buttons */ g.setColor(Color.blue); g.fillRect(xoff, height-yoff/2, 2*xoff, yoff/2); g.setColor(Color.yellow); g.drawString("Restart", xoff+25, height-6); /* draw grid */ g.setColor(Color.black); g.drawLine(width-1,0,width-1,height-yoff); for(int i=0; i= 1 && col <= 2) { init_game(); win = 'n'; } /* Play victory song for winner */ if(win == 'y') { play(getCodeBase(), "audio/coool.au"); win = 'n'; g.setColor(Color.red); g.drawString("YOU WIN!!!", 2*xoff+15, height-28); } repaint(); return true; } /* initialize game */ void init_game() { /* generate initial state of coins */ for(int i=0; i