Exemplo n.º 1
0
  /**
   * Solves the maze for four robot starting positions
   *
   * @param draw
   */
  private boolean solve(boolean draw) {
    maze.draw();

    Point robotPositions[] = new Point[4];
    robotPositions[0] = new Point(1, 1); // bottom left
    robotPositions[1] = new Point(1, MAZE_SIZE); // top left
    robotPositions[2] = new Point(MAZE_SIZE, 1); // bottom right
    robotPositions[3] = new Point(MAZE_SIZE, MAZE_SIZE); // top right

    // one position for each robot
    boolean[] solved = {false, false, false, false};

    for (int i = 0; i < 4; i++) {
      if (robotPositions[i] != null) {
        solved[i] = maze.solve(robotPositions[i], maze.GetCentrePoint(), draw);
        // System.out.println("Robot " + (i + 1) + " path solved: " + solved[i]);
        if (draw) {
          StdDraw.clear();
          maze.draw();
        }
      }
    }

    return (solved[0] && solved[1] && solved[2] && solved[3]);
  }
Exemplo n.º 2
0
  public Environment() {
    StdDraw.setCanvasSize(WINDOW_HEIGHT, WINDOW_LENGTH); // pixel size of window

    // Determines how the maze scales within the window
    StdDraw.setXscale(0, MAZE_SIZE + 2);
    StdDraw.setYscale(0, MAZE_SIZE + 2);

    validMaze = false;

    maze = new Maze(MAZE_SIZE); // create a new maze object

    StdDraw.show(0); // Show the maze window we have just created
    maze.draw(); // Draw the maze
    StdDraw.show(200); // Show this for 200 ms

    // pass the argument "true" to see the maze solve
    validMaze = solve(false); // solve the maze, but don't draw it
  }
Exemplo n.º 3
0
 /** This method cannot be called directly. */
 @Override
 public void actionPerformed(ActionEvent e) {
   FileDialog chooser =
       new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
   chooser.setVisible(true);
   String filename = chooser.getFile();
   if (filename != null) {
     StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
   }
 }
Exemplo n.º 4
0
  /** Test client. */
  public static void main(String[] args) {
    // final int WINDOW_LENGTH = 600;
    // final int WINDOW_HEIGHT = 1200;
    // StdDraw.setCanvasSize(WINDOW_HEIGHT, WINDOW_LENGTH); //pixel size of window
    StdDraw.setXscale(0, 1.2);
    StdDraw.setYscale(0, 1.2);

    StdDraw.square(.2, .8, .1);
    StdDraw.filledSquare(.8, .8, .2);
    StdDraw.circle(.8, .2, .2);

    // draw a blue diamond, radius 0.1 (old method)
    StdDraw.setPenRadius(); // default radius
    StdDraw.setPenColor(Colors.BOOK_BLUE);
    double[] x = {.1, .2, .3, .2};
    double[] y = {.2, .3, .2, .1};
    StdDraw.filledPolygon(x, y);

    // draw a cyandiamond, radius 0.1 (new method)
    StdDraw.setPenColor(Colors.CYAN);
    StdDraw.filledDiamond(.45, .2, 0.1);

    // draw a magenta triangle, radius 0.1
    StdDraw.setPenColor(Colors.MAGENTA);
    StdDraw.filledTriangle(.45, 0.4, 0.1);

    // Green filled rectangle, rotated x degrees
    StdDraw.setPenColor(Colors.GREEN);
    StdDraw.filledAngledRectangle(.45, .8, .05, .2, 10);
    // StdDraw.filledAngledRectangle(0.2, 0.2, 0.2, 0.05, 90);
    // StdDraw.filledAngledRectangle(0, 0, 0.2, 0.05, 0);

    StdDraw.setPenColor(Colors.BOOK_RED);
    StdDraw.setPenRadius(.02);
    StdDraw.arc(.8, .2, .1, 120, 60);
    StdDraw.line(0.8, 0.2, 0.8, 0.3);

    // text
    StdDraw.setPenRadius();
    StdDraw.setPenColor(Colors.BLACK);
    StdDraw.text(0.2, 0.5, "black text");
    StdDraw.setPenColor(Colors.WHITE);
    StdDraw.text(0.8, 0.8, "white text");

    // Edge testing
    StdDraw.setPenColor(Colors.GRAY);
    // StdDraw.circle(0, 0, .2);
    StdDraw.line(0, 0, 0, 1);
  }
Exemplo n.º 5
-1
 /** This method cannot be called directly. */
 @Override
 public void mouseMoved(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
   }
 }