Added ai player and fixed so player kan create units
This commit is contained in:
parent
e7403858f8
commit
c83605d5c4
22 changed files with 373 additions and 123 deletions
|
|
@ -14,7 +14,7 @@ public class AStar{
|
|||
|
||||
private int width;
|
||||
private int hight;
|
||||
private AStarNode[][] map;
|
||||
private static AStarNode[][] map;
|
||||
|
||||
protected boolean randomizeMap = true;
|
||||
protected Random RAND = new Random(0);
|
||||
|
|
@ -23,7 +23,12 @@ public class AStar{
|
|||
width = InGameState.getMap().getSize().getX();
|
||||
hight = InGameState.getMap().getSize().getY();
|
||||
initializePathfinder();
|
||||
initializeMap();
|
||||
if(map != null){
|
||||
reset();
|
||||
}
|
||||
else{
|
||||
initializeMap();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AStarNode> startSearch(Vector2i start, Vector2i goal){
|
||||
|
|
@ -38,13 +43,29 @@ public class AStar{
|
|||
pathfinder = new AStarPathfinder();
|
||||
}
|
||||
|
||||
protected void reset(){
|
||||
for(int y = 0, nodeId = 0; hight > y; y++) {
|
||||
MultiPrintStream.out.println("");
|
||||
for(int x = 0; width > x; x++, nodeId++) {
|
||||
if(!InGameState.getMap().isPosEmpty(x, y)) {
|
||||
map[x][y].setBlocked(true);
|
||||
MultiPrintStream.out.print(1);
|
||||
}
|
||||
else{
|
||||
MultiPrintStream.out.print(""+0);
|
||||
map[x][y].setBlocked(false);
|
||||
}
|
||||
map[x][y].setVisited(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeMap() {
|
||||
System.out.println("Initializing map");
|
||||
// Create the map.
|
||||
map = new AStarNode2D[width][hight];
|
||||
for(int y = 0, nodeId = 0; hight > y; y++) {
|
||||
MultiPrintStream.out.println();
|
||||
MultiPrintStream.out.println("");
|
||||
for(int x = 0; width > x; x++, nodeId++) {
|
||||
map[x][y] = new AStarNode2D(x, y, nodeId);
|
||||
|
||||
|
|
@ -52,10 +73,10 @@ public class AStar{
|
|||
map[x][y].setBlocked(true);
|
||||
MultiPrintStream.out.print(1);
|
||||
}
|
||||
else MultiPrintStream.out.print(0);
|
||||
else MultiPrintStream.out.print(""+0);
|
||||
}
|
||||
}
|
||||
MultiPrintStream.out.println();
|
||||
MultiPrintStream.out.println("");
|
||||
/*
|
||||
for(int x = 0, nodeId = 0; width > x; x++) {
|
||||
for(int y = 0; hight > y; y++, nodeId++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue