// Simple Maze demo import java.applet.*; import java.awt.event.*; import java.awt.*; public class SimpleMaze extends Applet implements KeyListener { int x; int y; public void init() { setBackground(Color.black); x = 10; y = 10; addKeyListener(this); } public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (c == 'w') { y -= 10; } else if (c == 's') { y += 10; } else if (c == 'a') { x -= 10; } else if (c == 'd') { x += 10; } if (c != KeyEvent.CHAR_UNDEFINED) { repaint(); e.consume(); } } public void paint(Graphics g) { requestFocus(); // necessary so the applet has the initial focus if (!collisionDetection()) { g.setColor(Color.gray); g.drawLine(0, 100, 250, 100); // draw many more lines here g.setColor(Color.green); g.fillRect(x, y, 20, 20); // player's square } else { g.setColor(Color.yellow); g.drawString("LOSER", 130, 150); } } public boolean collisionDetection() { if (x < 250 && y < 100 && y + 20 > 100) // line segment 1 { return true; } // many more else if clauses here for a good maze return false; } }