Exemplo n.º 1
0
 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 void addItem() {
    int pick = (int) (Math.random() * openSpaces.size());
    // System.out.println("openspaces is size " + openSpaces.size());
    Location l = openSpaces.get(pick);
    int choose = (int) (Math.random() * 3);
    // System.out.println(choose);
    switch (choose) {
      case 0:
        Apple a = new Apple();
        world.add(l, a);
        openSpaces.remove(l);

        break;
      case 1:
        GrimyFood f = new GrimyFood();
        world.add(l, f);
        openSpaces.remove(l);

        break;
      case 2:
        OranBerry o = new OranBerry();

        world.add(l, o);
        openSpaces.remove(l);

        break;
    }
  }
 public static void main(String[] args) {
   RockHound rockHound = new RockHound();
   ActorWorld actorWorld = new ActorWorld();
   actorWorld.add(rockHound);
   actorWorld.add(new Rock());
   actorWorld.show();
 }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 7
0
 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();
 }
Exemplo n.º 8
0
 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();
 }
 /**
  * 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();
 }
Exemplo n.º 10
0
 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.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 ChameleonCritter());
   world.add(new Location(5, 8), new ChameleonCritter());
   world.show();
 }
Exemplo n.º 12
0
 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();
 }
  /**
   * 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();
  }
Exemplo n.º 14
0
 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();
 }
Exemplo n.º 15
0
 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();
 }
Exemplo n.º 16
0
 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();
 }
Exemplo n.º 17
0
  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();
  }
Exemplo n.º 18
0
  @Test
  public void testBasicFeature() {
    ActorWorld world = new ActorWorld();
    Jumper a = new Jumper(Color.RED);
    Jumper b = new Jumper(Color.GREEN);
    Jumper c = new Jumper(Color.BLUE);

    world.add(new Location(2, 0), a);
    a.act();
    assertEquals(0, a.getLocation().getRow());
    assertEquals(0, a.getLocation().getCol());
    assertEquals(Location.NORTH, a.getDirection());

    world.add(new Location(1, 3), b);
    b.act();
    assertEquals(0, b.getLocation().getRow());
    assertEquals(3, b.getLocation().getCol());
    assertEquals(Location.NORTH, b.getDirection());
    b.act();
    assertEquals(0, b.getLocation().getRow());
    assertEquals(3, b.getLocation().getCol());
    assertEquals(Location.NORTHEAST, b.getDirection());
    b.act();
    assertEquals(0, b.getLocation().getRow());
    assertEquals(3, b.getLocation().getCol());
    assertEquals(Location.EAST, b.getDirection());
    b.act();
    assertEquals(0, b.getLocation().getRow());
    assertEquals(5, b.getLocation().getCol());
    assertEquals(Location.EAST, b.getDirection());

    world.add(new Location(0, 6), c);
    c.act();
    assertEquals(0, c.getLocation().getRow());
    assertEquals(6, c.getLocation().getCol());
    assertEquals(Location.NORTHEAST, c.getDirection());
    c.act();
    assertEquals(0, c.getLocation().getRow());
    assertEquals(6, c.getLocation().getCol());
    assertEquals(Location.EAST, c.getDirection());
    c.act();
    assertEquals(0, c.getLocation().getRow());
    assertEquals(8, c.getLocation().getCol());
    assertEquals(Location.EAST, c.getDirection());
  }
Exemplo n.º 19
0
 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();
 }
Exemplo n.º 20
0
  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();
  }
Exemplo n.º 21
0
  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();
  }
Exemplo n.º 22
0
  /**
   * 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();
  }
Exemplo n.º 24
0
  public static void makeBugs(ActorWorld world, int n) {

    for (int i = 0; i < n; i++) {

      Bug coloredBug = new Bug();

      world.add(coloredBug);

      int x = coloredBug.getLocation().getCol();
      int y = coloredBug.getLocation().getRow();

      coloredBug.setColor(new Color(25 * y, 0, 25 * x));
    }
  }
  public void nextLevel() {
    //		if (!firstStage)
    this.getInfo().writeText("You moved to the next stage!");
    //		else
    //			firstStage = false;
    //		boolean check = false;
    Dungeon d;
    floorLevel++;
    if (floorLevel == 6)
      JOptionPane.showMessageDialog(
          null, "Great Job! You beat the game (as it is right now). If you want you can continue.");
    d = new Dungeon(60, 60); // creates a dungeon
    ArrayList<Room> roo = d.getRooms();
    boolean reDo = d.checkRooms();
    while (reDo == true) {
      d = new Dungeon(50, 50);
      reDo = d.checkRooms();
    }

    land = d.getDungeon(); // / change to land
    openSpaces = openLocations(); // gets locations of the rooms/corridors
    hero.setLand(this.land);
    grid = new BoundedGrid<>(land.length, land[1].length);
    world = new ActorWorld(grid);

    int counter = 0;
    for (int i = 0; i < numEnemies * floorLevel; i++) {
      addEnemy();
      counter++;
    }
    for (int i = 0; i < numItems + floorLevel; i++) {
      addItem();
    }

    Location l = (openSpaces.get((int) (Math.random() * openSpaces.size())));
    world.add(openSpaces.get((int) (Math.random() * openSpaces.size())), hero.main);
    hero.setGrid(grid);
    hero.setPanel(this);

    addStairs();

    ArrayList<ArrayList<Location>> a = d.getCorridors();
    for (ArrayList<Location> lo : a) {
      for (int i = 0; i < lo.size(); i++) {
        openSpaces.add(lo.get(i));
      }
    }
    repaint();
  }
  public void startGame() {
    JOptionPane.showMessageDialog(
        null, "Welcome to Pokemon Mystery Dungeon! Reach the 6th stage to beat the game!");
    //			if (!firstStage)
    //				this.getInfo().writeText("You moved to the next stage!");
    //			else
    //				firstStage = false;
    //			boolean check = false;
    Dungeon d;

    d = new Dungeon(60, 60); // creates a dungeon
    ArrayList<Room> roo = d.getRooms();
    boolean reDo = d.checkRooms();
    while (reDo == true) {
      d = new Dungeon(50, 50);
      reDo = d.checkRooms();
    }

    land = d.getDungeon(); // / change to land
    openSpaces = openLocations(); // gets locations of the rooms/corridors
    grid = new BoundedGrid<>(land.length, land[1].length);
    world = new ActorWorld(grid);

    int counter = 0;
    for (int i = 0; i < numEnemies * floorLevel; i++) {
      addEnemy();
      counter++;
    }
    for (int i = 0; i < numItems + floorLevel; i++) {
      addItem();
    }
    PersonalityTest t = new PersonalityTest(land);
    Pokemon z = t.chooseCharacter(this);
    hero = new Hero(z, land, this);
    Location l = (openSpaces.get((int) (Math.random() * openSpaces.size())));
    world.add(openSpaces.get((int) (Math.random() * openSpaces.size())), hero.main);
    hero.setGrid(grid);
    hero.setPanel(this);

    addStairs();

    ArrayList<ArrayList<Location>> a = d.getCorridors();
    for (ArrayList<Location> lo : a) {
      for (int i = 0; i < lo.size(); i++) {
        openSpaces.add(lo.get(i));
      }
    }
    repaint();
  }
 private void addEnemy() {
   int pick = (int) (Math.random() * openSpaces.size());
   // System.out.println("openspaces is size " + openSpaces.size());
   Location l = openSpaces.get(pick);
   // System.out.println(l);
   int choose = (int) (Math.random() * 4);
   // System.out.println(choose);
   switch (choose) {
     case 0:
       Cyndaquil a = new Cyndaquil(true, land, this);
       world.add(l, a);
       openSpaces.remove(l);
       enemies.add(a);
       break;
     case 1:
       Mudkip m = new Mudkip(true, land, this);
       world.add(l, m);
       // System.out.println("Pokemon here");
       openSpaces.remove(l);
       enemies.add(m);
       break;
     case 2:
       Munchlax mu = new Munchlax(true, land, this);
       world.add(l, mu);
       // System.out.println("Pokemon here");
       openSpaces.remove(l);
       enemies.add(mu);
       break;
     case 3:
       Pichu p = new Pichu(true, land, this);
       world.add(l, p);
       openSpaces.remove(l);
       enemies.add(p);
       break;
   }
 }
Exemplo n.º 28
0
  /**
   * Creates the actors and inserts them into their initial starting positions in the grid
   *
   * @pre the grid has been created
   * @post all actors that comprise the initial state of the game have been added to the grid
   */
  private void populateGame(boolean test) {
    // constants for the location of the three cells initially alive

    // the grid of Actors that maintains the state of the game
    //  (alive cells contains actors; dead cells do not)
    Grid<Actor> grid = world.getGrid();

    Random rand = new Random();

    int n; // Nunmber variable for random number

    // Runs for regular program
    if (test == false) {
      // Randomly places an actor at coordinates (a, i)
      for (int i = 0; i <= 1000; i++) {
        for (int a = 0; a <= 1000; a++) {
          n = rand.nextInt(10);
          // Randomly chooses where an actor is initially placed on a grid
          if (n == 2 || n == 5 || n == 7 || n == 9 || n == 1) {
            Actor rock1 = new Actor();
            Location loc1 = new Location(i, a);
            grid.put(loc1, rock1);
          }
        }
      }
    }

    // Tested version (Works if this is placed as code for populateGame)
    if (test == true) {
      for (int i = 0; i <= 4; i++) {
        for (int a = 0; a <= 4; a++) {
          if (i == 0 && a == 0
              || i == 0 && a == 4
              || i == 1 && a == 1
              || i == 1 && a == 3
              || i == 2 && a == 2
              || i == 3 && a == 1
              || i == 3 && a == 3
              || i == 4 && a == 0
              || i == 4 && a == 4) {
            Actor rock1 = new Actor();
            Location loc1 = new Location(i, a);
            grid.put(loc1, rock1);
          }
        }
      }
    }
  }
Exemplo n.º 29
0
  public boolean getResult() {
    if (!runned) {
      runned = true;
      world.step();
      result = false;

      for (int i = 0; i < jumperToTest.length; ++i)
        if (jumperToTest[i].check() == false) return false;
      if (flowerToTest != null) {
        for (int i = 0; i < flowerToTest.length; ++i)
          if (flowerToTest[i].check() == false) return false;
      }
      result = true;
    }
    return result;
  }
Exemplo n.º 30
0
  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();
  }