public void actionPerformed(ActionEvent arg0) { map.updateMap(); repaint(); if (map.getHomeFood() + map.getLostFood() >= FOOD - FOOD_ERROR && running) { System.out.println("All food has been collected!"); running = false; } }
/** * Creates a Pathfinder object * * @param map Map to pathfind in */ public PathFinder(Map map) { this.tiles = new boolean[map.getWidth()][map.getHeight()]; this.graph = new Node[map.getWidth()][map.getHeight()]; this.tileMap = map.getMap(); for (int x = 0; x < tiles.length; x++) { for (int y = 0; y < tiles[0].length; y++) { this.tiles[y][x] = ((this.tileMap[x][y] & (1 << 14)) != 0); this.graph[x][y] = new Node(y, x); } } }
public void paintComponent(Graphics g) { super.paintComponent(g); for (int y = 0; y < map.getHeight(); y++) { for (int x = 0; x < map.getWidth(); x++) { Point p = new Point(x, y); Food f = map.getFood(p); float foodval = (f == null ? 0.0f : f.getRemaining()); g.setColor(getPherColour(map.getPher(p), map.getNumAnts(p), foodval)); g.fillRect(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE); } } }
@Test public void testGetTile() { for (int row = 0; row < 5; row++) { for (int col = 0; col < 9; col++) { // Check null for town if (row == 2 && col == 4) { assertTrue(map.getTile(col * 67, row * 80) == right[row][col]); } else { assertTrue(map.getTile(col * 67, row * 80).getX() == right[row][col].getX()); assertTrue(map.getTile(col * 67, row * 80).getY() == right[row][col].getY()); } } } }
/** Moves leader to a new location */ public void moveTo(int x, int y) { // only move there if it's a valid location leader.move(x, y); if (leader.getX() == x && leader.getY() == y) { currentTerrain = map.getTerrain(x, y); if (currentTerrain != null) encounterNum += currentTerrain.getRate(); if (encounterNum > 100) if (currentTerrain.getFormations().size() > 0) { encounterNum = 0; Formation f = currentTerrain.getRandomFormation(); Engine.getInstance().changeToBattle(f, currentTerrain.getBackground()); } // interact with event if stepped on if (map.getEventMap().get(x + " " + y) != null) map.getEventMap().get(x + " " + y).interact(); } }
@Before public void setUp() { map = new Map(); final int rowLength = 9; final int columnLength = 5; this.right = new Tile[columnLength][rowLength]; System.out.println(map.getMap()[1][1].getY()); for (int row = 0; row < columnLength; row++) { for (int col = 0; col < rowLength; col++) { if ((col == 2 && row == 0) || (col == 8 && row == 2) || (col == 1 && row == 1)) { right[row][col] = new Tile(Terrain.MOUNTAIN1, col * WIDE, row * TALL); } else if ((row == 3 && (col == 1 || col == 6)) || (row == 4 && (col == 2 || col == 8))) { right[row][col] = new Tile(Terrain.MOUNTAIN2, col * WIDE, row * TALL); } else if ((row == 0 && col == 6) || (row == 1 && col == 8) || (row == 2 && col == 0)) { right[row][col] = new Tile(Terrain.MOUNTAIN3, col * WIDE, row * TALL); } else if (col == 4 && (row == 0 || row == 1 || row == 3 || row == 4)) { right[row][col] = new Tile(Terrain.RIVER, col * WIDE, row * TALL); } else if (!(row == 2 && col == 4)) { right[row][col] = new Tile(Terrain.PLAIN, col * WIDE, row * TALL); } } } }