/* Author: Usama Khan Date: 19 November 2007 Licence: no licence, it's free because everyone can write this simple program. Descript.: A very small program or game where the user has to move the mouse through a maze. If the user touches the black field of start, the time starts to count. If the user touches the black field of end, the time will be stopped and in the command window, you will be shown how long the user took to get from start to end. If the user get off the maze the program will force the user to end. */ import element.*; import java.awt.*; public class maze{ private static long startTime; private static long stopTime; private static Pt movePoint; //private static Pt move2; public static void main(String[] args){ DrawingWindow d = new DrawingWindow(500,500); Text s = new Text("start"); s.center(new Pt(250,400)); Text f = new Text("end"); f.center(new Pt(250,200)); Circle start= new Circle(250,400,30); Circle end = new Circle(250,200,30); Rect mid1 = new Rect(240, 225, 20, 150); d.fill(mid1); d.fill(start); d.fill(end); d.setForeground(Color.white); d.draw(s); d.draw(f); //move2 = d.getMouse(); boolean startin = false; boolean mazein = false; boolean mazeout = false; while(true){ movePoint = d.getMouse(); if(start.contains(movePoint)){ startin = true; //d.awaitMousePress(); startTime = System.currentTimeMillis(); //d.awaitMouseRelease(); } if(end.contains(movePoint)){ stopTime = System.currentTimeMillis(); System.out.println("It took you "+(stopTime-startTime)+" millisec"); break; } if(mid1.contains(movePoint)){ d.setForeground(Color.green); mazein = true; } //else{ // d.setForeground(Color.red); //} if(!mid1.contains(movePoint)){ mazeout = true; startin = false; d.setForeground(Color.red); System.out.println("Move your mouse to start-field to start game!"); //break; } if(startin==false&&mazein==true&&mazeout==true){ System.out.println("you lost, GAME OVER"); break; } d.fill(mid1); } } }