public static void main(String[] args) { RockHound rockHound = new RockHound(); ActorWorld actorWorld = new ActorWorld(); actorWorld.add(rockHound); actorWorld.add(new Rock()); actorWorld.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); Jumper alice = new Jumper(); alice.setColor(Color.ORANGE); world.add(new Location(5, 5), alice); world.show(); }
public static void main(String[] args) { int[] turns = {5, 3, 7, 5, 9, 7, 11}; ActorWorld world = new ActorWorld(); DancingBug bob = new DancingBug(turns); world.add(new Location(5, 5), bob); world.show(); }
public static void main(String[] args) { ActorWorld player = new ActorWorld(); CircleBug round = new CircleBug(3); round.setColor(Color.GREEN); player.add(new Location(5, 5), round); player.show(); }
public static void main(String[] args) { int[] directions = {2, 7, 9, 1, 5, 6, 3, 9, 4, 2, 1, 4, 3, 2}; ActorWorld world = new ActorWorld(); DancingBug alice = new DancingBug(directions); alice.setColor(Color.ORANGE); world.add(new Location(7, 8), alice); world.show(); }
/** * Adds two different Jumpers to a world, one with its color changed to Orange * * @param args */ public static void main(String[] args) { ActorWorld world = new ActorWorld(); Jumper alpha = new Jumper(); alpha.setColor(Color.ORANGE); Jumper beta = new Jumper(); world.add(new Location(7, 8), alpha); world.add(new Location(5, 5), beta); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); CircleBug alice = new CircleBug(6); alice.setColor(Color.ORANGE); CircleBug bob = new CircleBug(3); world.add(new Location(7, 8), alice); world.add(new Location(5, 5), bob); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); int num = 50; for (int i = 0; i < num; i++) { world.add(new Critter()); } world.add(new BlusterCritter(15)); world.show(); }
public static void main(String[] args) { // create a patten array int[] a = {1, 2, 3, 4, 5, 6, 7, 8}; ActorWorld world = new ActorWorld(); // creat a DancingBug with the patten array above DancingBug zyh = new DancingBug(a); zyh.setColor(Color.ORANGE); // add the bug into grid, and set the location initially world.add(new Location(5, 5), zyh); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); world.addGridClass("SparseBoundedGrid"); world.addGridClass("SparseBoundedGrid1"); world.addGridClass("SparseBoundedGrid2"); world.addGridClass("SparseBoundedGrid3"); world.addGridClass("UnboundedGrid2"); world.setGrid(new SparseBoundedGrid3<Actor>(10, 10)); world.add(new Location(5, 6), new Bug()); world.add(new Location(4, 3), new Critter()); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); world.add(new Location(7, 8), new Rock()); world.add(new Location(3, 3), new Rock()); world.add(new Location(2, 8), new Rock(Color.BLUE)); world.add(new Location(5, 5), new Rock(Color.PINK)); world.add(new Location(1, 5), new Rock(Color.RED)); world.add(new Location(7, 2), new Rock(Color.YELLOW)); world.add(new Location(4, 4), new BlusterCritter(10)); world.add(new Location(5, 8), new BlusterCritter(3)); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); ZBug alice = new ZBug(6); alice.setColor(Color.ORANGE); ZBug bob = new ZBug(3); // world.add(new Location(7, 8), alice); // world.add(new Location(5, 5), bob); bob.putSelfInGrid(world.getGrid(), new Location(0, 0)); bob.removeSelfFromGrid(); // bob.removeSelfFromGrid(); bob.putSelfInGrid(world.getGrid(), new Location(0, 2)); world.show(); }
/** * Default constructor for objects of class GameOfLife * * @post the game will be initialized and populated with the initial state of cells */ public GameOfLife(boolean test) { // create the grid, of the specified size, that contains Actors UnboundedGrid<Actor> grid = new UnboundedGrid<Actor>(); // create a world based on the grid world = new ActorWorld(grid); // populate the game populateGame(test); // display the newly constructed and populated world world.show(); }
/** * Default constructor for objects of class GameOfLife * * @post the game will be initialized and populated with the initial state of cells */ public GameOfLife() { // create the grid, of the specified size, that contains Actors BoundedGrid<Actor> grid = new BoundedGrid<Actor>(ROWS, COLS); // create a world based on the grid world = new ActorWorld(grid); // populate the game populateGame(); // display the newly constructed and populated world world.show(); }
/** * 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(); }
public static void main(String[] args) { Grid<Actor> grid = new BoundedGrid<Actor>(20, 20); ActorWorld world = new ActorWorld(grid); world.add(new Location(9, 9), new BeMeCritter()); world.add(new Location(2, 5), new BeMeCritter(Color.green)); world.add(new Critter()); world.add(new Location(2, 10), new Rock()); world.add(new Location(10, 10), new BeMeCritter()); world.add(new Location(10, 9), new Critter()); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); // DancingBug alice = new DancingBug(6); // alice.setColor(Color.ORANGE); Random r = new Random(); int[] array = new int[100]; for (int i = 0; i < array.length; i++) { array[i] = r.nextInt(5); } DancingBug bob = new DancingBug(array); // world.add(new Location(7, 8), alice); world.add(new Location(5, 5), bob); world.show(); }
public static void main(String[] args) { int[] i = { 2, 5, 6, 8, 14, 56, 5, 1, 5, 4, 52, 52, 5, 87, 85, 542, 1, 2, 6, 8, 4, 5, 5, 2, 1, 5, 4, 5, 2, 1, 5, 4, 87, 5, 1, 2, 4, 85, 52, 7, 4, 76, 36, 35, 6 }; ActorWorld world = new ActorWorld(); BoxBug alice = new BoxBug(6); DancingBug b = new DancingBug(i); alice.setColor(Color.ORANGE); BoxBug bob = new BoxBug(3); // world.add(new Location(7, 8), alice); // world.add(new Location(5, 5), bob); world.add(new Location(4, 3), b); world.show(); }
public static void main(String[] args) { // ActorWorld world = new ActorWorld(new UnboundedGrid2<Actor>()); ActorWorld world = new ActorWorld(new SparseBoundedGrid<Actor>(30, 30)); // ActorWorld world = new ActorWorld(new SparseBoundedGrid2<Actor>(30, 30)); // ActorWorld world = new ActorWorld(); world.addGridClass("SparseBoundedGrid"); world.addGridClass("SparseBoundedGrid2"); world.addGridClass("UnboundedGrid2"); world.add(new Location(4, 4), new Bug()); world.add(new Location(2, 2), new Bug()); // world.remove(new Location(2, 2)); world.add(new Location(3, 2), new Bug()); world.show(); // world.show(); }
public static void main(String[] args) { Color purple = new Color(148, 0, 211); ActorWorld world = new ActorWorld(); Bug redBug = new Bug(); world.add(redBug); System.out.println(redBug.getLocation()); makeBugs(world, 10); // colorBug(redBug); // moveBug(redBug, 5); // randomBug(redBug, 10000); world.add(new Rock()); world.show(); }
public static void main(String[] args) { // UnboundedGrid ugr=new UnboundedGrid(); ActorWorld world = new ActorWorld(); /*world.add(new Location(-1,-1),new MazeBug()); for(int i=0;i<=40;i++){ for(int j=0;j<=40;j+=40){ world.add(new Location(i,j),new Rock()); } } for(int i=0;i<=40;i+=40){ for(int j=0;j<=40;j++){ world.add(new Location(i,j),new Rock()); } }*/ world.add(new Location(0, 0), new MazeBug()); world.add(new Location(0, 1), new MazeBug2()); world.add(new Location(1, 1), new Rock()); world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); // 在world中添加actors world.add(new Flower()); world.add(new Location(4, 4), new MazeBug1()); world.add(new Location(5, 3), new Rock()); world.add(new Location(4, 3), new Rock()); world.add(new Location(3, 3), new Rock()); world.add(new Location(2, 4), new Rock()); world.add(new Location(6, 5), new Rock()); world.add(new Location(5, 5), new Rock()); world.add(new Location(5, 6), new Rock()); world.add(new Location(3, 5), new Rock()); world.add(new Location(3, 6), new Rock()); world.add(new Location(4, 7), new Rock()); world.add(new Location(7, 4), new Rock()); world.add(new Location(6, 3), new Rock()); // 显示world world.show(); }
public static void main(String[] args) { ActorWorld world = new ActorWorld(); // Specify a // Jumper jumper = new Jumper(); // world.add(new Location(5, 5), jumper); // world.add(new Location(3, 5), new Rock()); Test testSpecifyA = new Test( new JumperInfo[] { new JumperInfo( new Location(5, 5), Location.NORTH, new Location(5, 5), Location.NORTHEAST) }, null, new Location[] {new Location(3, 5)}); if (testSpecifyA.getResult()) { System.out.println("test passed"); } // Specify b // Jumper jumper = new Jumper(); // world.add(new Location(1, 5), jumper); // Specify c // Jumper jumper = new Jumper(); // world.add(new Location(0, 5), jumper); // Specify d // Jumper jumperA = new Jumper(), jumperB = new Jumper(Color.RED); // world.add(new Location(3, 2), jumperA); // world.add(new Location(4, 2), new Rock()); // world.add(new Location(5, 2), jumperB); // // Jumper jumperC = new Jumper(), jumperD = new Jumper(Color.RED); // jumperC.setDirection(Location.SOUTH); // jumperD.setDirection(Location.SOUTH); // world.add(new Location(5, 5), jumperC); // world.add(new Location(4, 5), new Rock()); // world.add(new Location(3, 5), jumperD); // // Jumper jumperE = new Jumper(), jumperF = new Jumper(Color.RED); // world.add(new Location(3, 8), jumperE); // world.add(new Location(5, 8), jumperF); // Specify e // Jumper jumperA = new Jumper(), jumperB = new Jumper(Color.RED); // world.add(new Location(3, 2), jumperA); // world.add(new Location(4, 2), jumperB); // // Jumper jumperC = new Jumper(), jumperD = new Jumper(Color.RED); // jumperC.setDirection(Location.SOUTH); // jumperD.setDirection(Location.SOUTH); // world.add(new Location(4, 5), jumperC); // world.add(new Location(3, 5), jumperD); // two Actors in the front // Jumper jumperA = new Jumper(); // world.add(new Location(5, 2), jumperA); // world.add(new Location(4, 2), new Flower()); // world.add(new Location(3, 2), new Flower()); // // Jumper jumperB = new Jumper(); // world.add(new Location(5, 5), jumperB); // world.add(new Location(4, 5), new Rock()); // world.add(new Location(3, 5), new Rock()); // // Jumper jumperC = new Jumper(); // world.add(new Location(5, 8), jumperC); // world.add(new Location(4, 8), new Rock()); // world.add(new Location(3, 8), new Flower()); // near edge // Jumper jumperA = new Jumper(); // world.add(new Location(1, 3), jumperA); // // Jumper jumperB = new Jumper(); // world.add(new Location(0, 6), jumperB); world.show(); }