/***************************/ /* Path Finder V1.0 1997 */ /* for Java API 1.1.3 */ /* Qing Li */ /***************************/ import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.util.*; public class Path extends Applet { int num_obstacle = 3; int obstacle_size = 40; int obstacle_edges = 4; int num_gem = 3; int gem_radius = 10; int rover_width = 30; int rover_height = 20; int rover_angle = 0; double tmp; // create "more than enough" empty objects -- use "vector" later. D_Obstacle[] dressed_obstacles = { new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), new D_Obstacle(), }; D_Gem[] dressed_gems = { new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem(), new D_Gem() }; Rover rover = new Rover(); public void init() { String arg; int i, j, k, x, y; boolean success; // get parameters from applet tag fields arg = getParameter("num_obstacle"); if (arg != null) num_obstacle = Integer.parseInt(arg); arg = getParameter("obstacle_size"); if (arg != null) obstacle_size = Integer.parseInt(arg); arg = getParameter("obstacle_edges"); if (arg != null) obstacle_edges = Integer.parseInt(arg); arg = getParameter("num_gem"); if (arg != null) num_gem = Integer.parseInt(arg); arg = getParameter("gem_radius"); if (arg != null) gem_radius = Integer.parseInt(arg); // create random obstacles int xpoints[] = new int [obstacle_edges]; int ypoints[] = new int [obstacle_edges]; double angle[] = new double [obstacle_edges]; double alpha = 0.5; for (i=0; i=0; k--) { if (angle[k+1] < angle[k]) { // swap the two angles tmp = angle[k]; angle[k] = angle[k+1]; angle[k+1] = tmp; } } } for (j=0; j=0; j--) success = success && ( (gem_tmp.x-dressed_gems[j].x)* (gem_tmp.x-dressed_gems[j].x)+ (gem_tmp.y-dressed_gems[j].y)* (gem_tmp.y-dressed_gems[j].y) > (gem_tmp.radius+dressed_gems[j].radius)* (gem_tmp.radius+dressed_gems[j].radius) ); if(success) dressed_gems[i].dress (x, y, gem_radius, rover_width, rover_height); } } // create rover success = false; while (!success) { success = true; x = Boundary.minx + (int) Math.round((Boundary.maxx - Boundary.minx) * Math.random()); y = Boundary.miny + (int) Math.round((Boundary.maxy - Boundary.miny) * Math.random()); int tmp_angle = (int) Math.round(360 * Math.random()); rover.put (x, y, rover_width, rover_height, tmp_angle); // see that the rover is contained in the boundary success = success && Boundary.contains(rover.body); // see that the rover does not initially hit obstacles success = success && (rover.hit_obstacle(dressed_obstacles, num_obstacle) == -1); // see that the rover does not initially hit gems success = success && (rover.hit_gem(dressed_gems, num_gem) == -1); } repaint(); } public void paint(Graphics g) { int i; Boundary.show(g); rover.show(g); for (i=0; i