Java时间步:如何实时更新?

Java时间步:如何实时更新?,java,a-star,maze,timestep,Java,A Star,Maze,Timestep,我目前正在用Java编程一个2d迷宫,它有NPC,可以根据时间步移动!但是,我不完全确定如何根据每个时间步更新它们的位置。我已经将它添加到敌人在第一个时间步中正确的位置。然而,我不太确定如何在下一步更新它。以下是创建我所说内容所需的代码: 这是主要课程: import java.util.*; import java.io.*; public class astar { /** * @param args the command line arguments */

我目前正在用Java编程一个2d迷宫,它有NPC,可以根据时间步移动!但是,我不完全确定如何根据每个时间步更新它们的位置。我已经将它添加到敌人在第一个时间步中正确的位置。然而,我不太确定如何在下一步更新它。以下是创建我所说内容所需的代码:

这是主要课程:

import java.util.*;
import java.io.*;

public class astar {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String mapFile;
        String barberFile;
        createMap mazeInput = new createMap();
       
        
        System.out.print("Please enter the map file name: ");
        mapFile = input.nextLine().trim();
        System.out.println();
        System.out.print("Please enter the barber file name: ");
        barberFile = input.nextLine().trim();
        
        mazeInput.createMaze(mapFile);
        
        mazeInput.placeEnemies(barberFile);
        
        //mazeInput.displayMap();
        
        
    }
    }
这是createMap.java,这是从用户提供的文本文件中读取地图的方式:

import java.util.*;
import java.io.*;

public class Map {
    char [][] mapFinal;
    int time = 0;
    
    public void createArray(int x, int y){
        mapFinal = new char[x][y];
        
        for (int i = 0; i < x; i++){
            for(int j = 0; j < y; j++){
                mapFinal[i][j] = ' '; // filling the array with blank spaces.
                
            }
        }
    }
    
    public void addStart(int startX, int startY){
        mapFinal[startX][startY] = 'S';
    }
    public void addGoal (int goalX, int goalY){
        mapFinal[goalX][goalY] = 'G';
    }
    public void addWall(int wallX, int wallY){
        mapFinal[wallX][wallY] = 'W';
    }
    public void addBarber(int timeStep, int xCords, int yCords){
        if (timeStep == time){
            mapFinal[xCords][yCords] = 'B';
        }
    }
   
    public void displayMap(){
        System.out.println("Timestep: " + time);
        for (int i = 0; i < mapFinal.length; i++){
            for (int j = 0; j < mapFinal[i].length; j++){
                System.out.print(mapFinal[i][j] + " ");
            }
            System.out.println();
            
        }
        System.out.print("--------------------------");
        System.out.println();
    }
}
这是一个地图文件,M设置2d数组的尺寸,S是起点,G是目标。W是墙壁或其他无法到达的区域

barbercup.txt

0 5 3
0 5 4
0 6 3
0 6 2
1 5 3
1 5 4
1 6 3
1 6 2
2 5 3
2 5 4
2 6 3
2 6 2
3 5 3
3 5 4
3 6 3
3 6 2
4 5 3
4 5 4
4 6 3
4 6 2
5 5 3
5 5 4
5 6 3
5 6 2
6 5 3
6 5 4
6 6 3
6 6 2
7 5 3
7 5 4
7 6 3
7 6 2
8 5 3
8 5 4
8 6 3
8 6 2
9 5 3
9 5 4
9 6 3
9 6 2
10 5 3
10 5 4
10 6 3
10 6 2
11 5 3
11 5 4
11 6 3
11 6 2
12 5 3
12 5 4
12 6 3
12 6 2
13 5 3
13 5 4
13 6 3
13 6 2
14 5 3
14 5 4
14 6 3
14 6 2
15 5 3
15 5 4
15 6 3
15 6 2
16 5 3
16 5 4
16 6 3
16 6 2
17 5 3
17 5 4
17 6 3
17 6 2
-1
此文件左侧的每个数字都是一个时间步长。它将读取此文件并将所有敌人放置在第一个时间步位置(0),但我不知道如何实时增加和更改敌人的位置


谢谢你的意见

请遵循Java命名约定。使您的代码和硬代码测试数据,而不是使用扫描仪。NPC代表什么?
M 10 8
S 0 2
G 6 5
W 4 3
W 4 4
W 4 5
W 4 6
W 5 6
W 6 6
W 7 6
W 8 3
W 8 4
W 8 5
W 8 6
E
0 5 3
0 5 4
0 6 3
0 6 2
1 5 3
1 5 4
1 6 3
1 6 2
2 5 3
2 5 4
2 6 3
2 6 2
3 5 3
3 5 4
3 6 3
3 6 2
4 5 3
4 5 4
4 6 3
4 6 2
5 5 3
5 5 4
5 6 3
5 6 2
6 5 3
6 5 4
6 6 3
6 6 2
7 5 3
7 5 4
7 6 3
7 6 2
8 5 3
8 5 4
8 6 3
8 6 2
9 5 3
9 5 4
9 6 3
9 6 2
10 5 3
10 5 4
10 6 3
10 6 2
11 5 3
11 5 4
11 6 3
11 6 2
12 5 3
12 5 4
12 6 3
12 6 2
13 5 3
13 5 4
13 6 3
13 6 2
14 5 3
14 5 4
14 6 3
14 6 2
15 5 3
15 5 4
15 6 3
15 6 2
16 5 3
16 5 4
16 6 3
16 6 2
17 5 3
17 5 4
17 6 3
17 6 2
-1