import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.util.Vector; public class vann2_2 extends Applet implements KeyListener{ Graphics g; int vann_x1=10, vann_x2=20, vann_x3=vann_x1+150, vann_x4=vann_x2+130; int vann_y1=50, vann_y2=100; int vann_poolx1=vann_x2-vann_x1/2, vann_poolx2=vann_x3-5, vann_pooly=vann_y2-vann_y1/2; int pea_x=30, pea_y=30; // int x=30, y=100; int x=5, y=10; int rx=x-10, ry=y-10, xl=16, yl=16; public vann2_2(){ addKeyListener(this); } public void paint(Graphics g){ g.drawLine(vann_x1, vann_y1, vann_x3, vann_y1); //äär g.drawLine(vann_x2, vann_y2, vann_x4, vann_y2); //p6hi g.drawLine(vann_x1, vann_y1, vann_x2, vann_y2); //vasak kylg g.drawLine(vann_x1+150, vann_y1, vann_x2+130, vann_y2); //parem kylg //vesi (pooltais) g.setColor(Color.blue); g.drawLine(vann_poolx1, vann_pooly, vann_poolx2, vann_pooly); //inimene g.setColor(Color.red); /* g.drawOval(pea_x-10, pea_y-10, pea_x, pea_y); //pea g.drawLine(pea_x+5, vann_y1, pea_x+10, vann_y1+30); //selgroog g.drawLine(pea_x+5, vann_y1, pea_x+20, vann_y1+20); //1 kasi g.drawLine(pea_x+5, vann_y1, pea_x, vann_y1+20); //2 kasi g.drawLine(pea_x+10, vann_y1+30, pea_x+20, vann_y1+50); //1 jalg g.drawLine(pea_x+10, vann_y1+30, pea_x, vann_y1+50); //2 jalg*/ g.drawRect(x, y, 10, 10); } public void keyPressed(KeyEvent k){ int kood=k.getKeyCode(); if(kood==KeyEvent.VK_RIGHT){ x=x+5; } if(kood==KeyEvent.VK_LEFT){ x=x-5; } if(kood==KeyEvent.VK_UP){ y=y-5; } if(kood==KeyEvent.VK_DOWN){ y=y+5; /* if(y==20&&x>=0&&x<=60){ y=y-5; } if(y==40&&x>=60&&x<=80){ y=y-5; } if(y==60&&x>=40&&x<=60){ y=y-5; } if(y==80&&x>=20&&y<=80){ y=y-5; } */ } if(y==15&&x>=0&&x<=20){ System.out.println("Finis!"); for(int y=85; x<100; x=x+5){ g.setColor(Color.red); g.drawLine(x, y, x+5, y); x=x+5; try{Thread.sleep(100);}catch(Exception e){} } x=5; y=10; try{Thread.sleep(500);}catch(Exception e){} } repaint(); } public void keyReleased(KeyEvent k){} public void keyTyped(KeyEvent k){} public static void main(String argumendid[]){ Frame f=new Frame("Labürint"); f.add(new vann2_2()); f.setSize(300, 300); f.setVisible(true); } }