spawn start field of antGame in the same spot everytime
This commit is contained in:
		
							parent
							
								
									737d78c6da
								
							
						
					
					
						commit
						7de2a5d1af
					
				| 
						 | 
					@ -3,4 +3,6 @@ package evironment.antGame;
 | 
				
			||||||
public class Constants {
 | 
					public class Constants {
 | 
				
			||||||
    public static final int DEFAULT_GRID_WIDTH = 5;
 | 
					    public static final int DEFAULT_GRID_WIDTH = 5;
 | 
				
			||||||
    public static final int DEFAULT_GRID_HEIGHT = 5;
 | 
					    public static final int DEFAULT_GRID_HEIGHT = 5;
 | 
				
			||||||
 | 
					    public static final int START_X = 5;
 | 
				
			||||||
 | 
					    public static final int START_Y = 2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,7 @@ public class Grid {
 | 
				
			||||||
        this.height = height;
 | 
					        this.height = height;
 | 
				
			||||||
        grid = new Cell[width][height];
 | 
					        grid = new Cell[width][height];
 | 
				
			||||||
        initialGrid = new Cell[width][height];
 | 
					        initialGrid = new Cell[width][height];
 | 
				
			||||||
 | 
					        start = new Point(Constants.START_X, Constants.START_Y);
 | 
				
			||||||
        initRandomWorld();
 | 
					        initRandomWorld();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,10 +30,11 @@ public class Grid {
 | 
				
			||||||
                initialGrid[x][y] = new Cell(new Point(x, y), CellType.FREE);
 | 
					                initialGrid[x][y] = new Cell(new Point(x, y), CellType.FREE);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        start = new Point(RNG.getEnvRandom().nextInt(width), RNG.getEnvRandom().nextInt(height));
 | 
					 | 
				
			||||||
        initialGrid[start.x][start.y] = new Cell(new Point(start.x, start.y), CellType.START);
 | 
					 | 
				
			||||||
        spawnNewFood(initialGrid);
 | 
					        spawnNewFood(initialGrid);
 | 
				
			||||||
        spawnObstacles();
 | 
					        spawnObstacles();
 | 
				
			||||||
 | 
					        initialGrid[start.x][start.y] = new Cell(new Point(start.x, start.y), CellType.START);
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //TODO
 | 
					    //TODO
 | 
				
			||||||
| 
						 | 
					@ -53,7 +55,7 @@ public class Grid {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Spawns one additional food on a random field EXCEPT for the starting position
 | 
					     * Spawns one additional food on a random field EXCEPT for the starting position
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void spawnNewFood(Cell[][] grid) {
 | 
					    private void spawnNewFood(Cell[][] grid) {
 | 
				
			||||||
        boolean foodSpawned = false;
 | 
					        boolean foodSpawned = false;
 | 
				
			||||||
        Point potFood = new Point(0, 0);
 | 
					        Point potFood = new Point(0, 0);
 | 
				
			||||||
        CellType potFieldType;
 | 
					        CellType potFieldType;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue