Пример #1
0
    /**
     *  Loops through room, checking each tile to see if it is a ground tile and whether the one above it
     *  is empty. If both of these conditions are met, placeElement() is called.
     **/

    public void genElements()
    {
        for (int x = 0; x < room.getCellsRows(); x++)
        {
            for (int y = 0; y < room.getCellsCols(); y++)
            {
                checkTile(x, y); //check what elements can be generated at a tile
                genTiles(x, y);  //choose from valid elements to be generated
                //reset bool values
                canGenSingle = false;
                canGenDouble = false;
                canGenBush   = false;
            }
        }
    }
 /**
  *  Loops through room, checking each tile to see if it has enough ground and empty
  *  If so, placeEnemy() is called.
  **/
 public void genEnemies()
 {
     for (int x = 1; x < room.getCellsRows() - 1; x++)                                                                                                                     //we start at 1 higher and end at 1 lower to not go out of bounds when doing below adjacency checks
     {
         for (int y = 0; y < room.getCellsCols() - 1; y++)                                                                                                                 //similar here (0 higher and 1 lower)
         {
             if (room.hasGround(x, y) && room.hasGround(x + 1, y) && room.hasGround(x - 1, y))                                                                             //check for 3 tiles of ground
             {
                 if (room.hasCellOfType(x, y + 1, CellType.Empty) && room.hasCellOfType(x + 1, y + 1, CellType.Empty) && room.hasCellOfType(x - 1, y + 1, CellType.Empty)) //check 3 tiles of empty
                 {
                     placeEnemy(x, y);
                 }
             }
         }
     }
 }