Пример #1
0
  public void paint(Graphics g) {

    board.drawMaze();
    pacman.drawMazeMan(true);
    pacman.start();
  }
Пример #2
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == start2Button) {
      maze.sol = 2;
      timer1.start();
    }
    if (e.getSource() == resetButton) {
      timer1.stop();
      timer2.stop();
      timer3.stop();
      timer4.stop();
      maze.sol = 0;
      this.maze.readFromFile("maze.txt");
      maze.repaint();
    }
    if (e.getSource() == start1Button) {
      maze.sol = 1;
      timer2.start();
      // maze.leastVisitedNeighbour();
    }
    if (e.getSource() == start3Button) {
      maze.sol = 3;
      timer3.start();
    }
    if (e.getSource() == start4Button) {
      maze.sol = 4;
      maze.dijkstra();
      timer4.start();
    }
    if (maze.sol == 2) {
      if (!maze.cells[maze.currentX][maze.currentY].isEnd()) {
        maze.stepLeastVistedNeighbour();
        maze.repaint();
      } else {
        timer1.stop();
      }
    }

    if (maze.sol == 1) {
      if (!maze.cells[maze.currentX][maze.currentY].isEnd()) {
        maze.randomStep();
        maze.repaint();
      } else {
        timer2.stop();
      }
    }
    if (maze.sol == 3) {
      if (!maze.cells[maze.currentX][maze.currentY].isEnd()) {
        maze.stepRightHand();
        maze.repaint();
      } else {
        timer3.stop();
      }
    }
    if (maze.sol == 4) {
      if (!maze.cells[maze.currentX][maze.currentY].isEnd()) {
        maze.stepDjikstra();
        maze.repaint();
      } else {
        timer4.stop();
      }
    }
  }