private void drawDungeon(Graphics g) { // System.out.println("At draw Dungeon"); Location current = hero.main.getLocation(); // System.out.println("current is "+current); int row = current.getRow(); int col = current.getCol(); // System.out.println(current); int counterr = 0; int counterc = 0; for (int r = row - 4; r < row + 5; r++) { // gets 4 above and 4 below // hero for (int c = col - 4; c < col + 5; c++) { // System.out.println("counter r is " // +counterr+" counter c is "+counterc); if (land[r][c].equals("C") || land[r][c].equals("R")) { // System.out.println("Looking at " + r + " " + c); g.drawImage(floor, counterc * 60, counterr * 60, 60, 60, null); // g.draw3DRect(r * 10, c * 10, 10, 10, true); } else if (land[r][c].equals("W")) { // System.out.println("Looking at " + r + " " + c); g.drawImage(wall, counterc * 60, counterr * 60, 60, 60, null); // g.draw3DRect(r * 10, c * 10, 10, 10, true); } else if (land[r][c].equals("S")) { // System.out.println("got here"); // System.out.println("Location of stairs is " + r + " " + // c); g.drawImage(stairs, counterc * 60, counterr * 60, 60, 60, null); } else { g.drawImage(error, counterc * 60, counterr * 60, 60, 60, null); } if (grid.get(new Location(r, c)) instanceof Pokemon) { // System.out.println("Pokemon here"); Pokemon p = (Pokemon) grid.get(new Location(r, c)); // g.drawImage(floor, counterc * 60, counterr * 60, 60, 60, // null); p.draw(g, counterc * 60, counterr * 60); // g.draw3DRect(r * 60, c * 60, 60, 60, true); } else if (grid.get(new Location(r, c)) instanceof Items) { // System.out.println("Found an item at " + r + " " + c); Items i = (Items) grid.get(new Location(r, c)); // g.drawImage(floor, counterc * 60, counterr * 60, 60, 60, // null); i.draw(g, counterc * 60, counterr * 60); // System.out.println("Drawimg at "+counterr+" "+counterc); } counterc++; } counterr++; counterc = 0; // System.out.println(); } }
/** * Generates the next generation based on the rules of the Game of Life and updates the grid * associated with the world * * @pre the game has been initialized * @post the world has been populated with a new grid containing the next generation */ public void createNextGeneration() { /** * You will need to read the documentation for the World, Grid, and Location classes in order to * implement the Game of Life algorithm and leverage the GridWorld framework. */ // create the grid, of the specified size, that contains Actors Grid<Actor> grid = world.getGrid(); // insert magic here... BoundedGrid<Actor> newgrid = new BoundedGrid<Actor>(ROWS, COLS); int col = getNumCols(); int row = getNumRows(); for (int column = 0; column < col; column++) { for (int rows = 0; rows < row; rows++) { Actor cell = getActor(rows, column); Location location = new Location(rows, column); if (cell != null) { ArrayList<Actor> Neighbors = grid.getNeighbors(location); int Neighborscount = Neighbors.size(); if (Neighborscount == 3) { // lives Rock newrock1 = new Rock(); Location newloc1 = new Location(rows, column); newgrid.put(newloc1, newrock1); } else if (Neighborscount == 2) { // lives Rock newrock1 = new Rock(); Location newloc1 = new Location(rows, column); newgrid.put(newloc1, newrock1); } else if (Neighborscount < 3) { // dies } else if (Neighborscount > 3) { // dies } } else if (cell == null) { ArrayList<Actor> Neighbors = grid.getNeighbors(location); int Neighborscount = Neighbors.size(); if (Neighborscount == 3) { // reborn Rock newrock1 = new Rock(); Location newloc1 = new Location(rows, column); newgrid.put(newloc1, newrock1); } } } } world.setGrid(newgrid); world.show(); }