import java.awt.*; import java.applet.Applet; class GoogleKnightsPanel extends Panel { int state[][] = new int[5][5]; static int levels[][][] = { { { 0, 2, 2, 2, 0 }, { 2, 0, 0, 0, 0 }, { 1, 0, 1, 1, 0 }, { 3, 0, 0, 3, 0 }, { 0, 3, 3, 0, 0 }, }, { { 0, 2, 2, 0, 0 }, { 1, 0, 0, 1, 0 }, { 1, 0, 0, 1, 0 }, { 0, 3, 3, 0, 0 }, { 0, 0, 0, 0, 0 }, }, { { 2, 2, 2, 0, 0 }, { 1, 0, 1, 0, 0 }, { 3, 3, 3, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, }, { { 0, 2, 2, 0, 0 }, { 1, 0, 2, 0, 0 }, { 1, 1, 1, 0, 0 }, { 0, 0, 3, 0, 0 }, { 3, 3, 0, 0, 0 }, }, { { 1, 2, 2, 0, 0 }, { 0, 2, 2, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 1, 1, 0, 0 }, { 1, 3, 3, 3, 3 }, }, { { 0, 2, 2, 0, 0 }, { 1, 0, 0, 2, 0 }, { 3, 1, 1, 2, 0 }, { 3, 0, 0, 0, 0 }, { 0, 3, 3, 0, 0 }, }, }; static String answers[] = { "B5A3D4B5B1C3A3B1B5A3C3B5B5D4A2C3C3B5A4C3C5A4C3A2C1D3D3C5A2C1A4C3C3A2D1C3C3A4B1C3A3B1C3D1", "C1D3B1A3B4A2C4D2D3B4A3C4A2C1D2B1", "A1C2B3A1C3A2B1C3A3B1C2A3C1B3A2C1", "C2A3B5C3A3B5C4A3A3C2B1A3A3C4A5B3C3B1C1A2B3C1A2C3B5A3C4A5C3B5A3C4", "C2A1D5B4B4C2C5B3B3A5A5C4A1B3B3A5C1B3B3C5C2A1A1B3B3C1B1C3C3D5A5B3B3A1A1C2C2B4C4A5A5B3B3A1A1C2B5C3C3B1B2C4C4A5E5C4C4B2A5C4C4E5D5C3C3B5B4D5", "C1A2D3C1C5D3A4C5B1C3C3A4A3B1B5A3A2C3C3B5C1A2D3C1C5D3D2B3B3C5B1D2A3B1A2C3B5A3C3B5", }; GoogleKnightsPanel() { //setBackground(Color.black); setuppieces(); } int level=0, step=0; public void paint(Graphics g) { g.setFont(new Font("Arial",Font.BOLD,18)); //set the font Color white = new Color(0x99, 0x99, 0xFF); Color black = new Color(0x66, 0x66, 0xFF); Color gray = new Color(0xFF, 0xFF, 0xFF); int r, col; // draw board for(r=0;r<5;r++) { for(col=0;col<5;col++) { if(state[r][col] == 0) g.setColor(gray); else if((r+col)%2 == 1) g.setColor(white); else g.setColor(black); g.fillRect(col*30, r*30, 30, 30); } } // draw targets for(r=0;r<5;r++) { for(col=0;col<5;col++) { if(levels[level][r][col] > 1) { if(levels[level][r][col] == 2) { g.setColor(Color.black); } else { g.setColor(Color.white); } g.drawRect(col*30+5, r*30+5, 20, 20); } } } // draw pieces for(r=0;r<5;r++) { for(col=0;col<5;col++) { if(state[r][col] > 1) { if(state[r][col] == 3) g.setColor(Color.black); else g.setColor(Color.white); g.fillOval(col*30+7, r*30+7, 17, 17); } } } } //end of paint method void movepieces() { int i, fromr, fromc, tor, toc; setuppieces(); for(i=0;i>"), c); c.gridx = 0; c.gridy = 2; add(prev = new Button("<"), c); c.gridx = 1; c.gridy = 2; add(next = new Button(">"), c); } public boolean action (Event evt, Object what) { if(evt.target == nextlev) panel.nextlev(); else if(evt.target == prevlev) panel.prevlev(); else if(evt.target == next) panel.next(); else if(evt.target == prev) panel.prev(); return false; } }