/// <summary>
 /// Creates a random map with the ground made of the <c>Tile</c> tile.
 /// </summary>
 /// <param name="height">Height of the map, in tiles.</param>
 /// <param name="width">Width of the map, in tiles.</param>
 /// <param name="tile"><c>Tile</c> the map is going to be filled with.</param>
 public Map(int height, int width, Tile.Ground tile)
 {
     this.height = height;
     this.width  = width;
     map         = new Tile[this.height, this.width];
     for (int i = 0; i < this.height; i++)
     {
         for (int j = 0; j < this.width; j++)
         {
             map[i, j] = new Tile(tile);
             if (Random.value * 10 > 9)
             {
                 map[i, j].ObjectAbove = Tile.Object.Stone;
             }
             else if (Random.value * 10 > 7)
             {
                 map[i, j].ObjectAbove = Tile.Object.Tree;
             }
         }
     }
 }
Пример #2
0
    /// <summary>
    /// Returns a tile prefab with a sprite attached to it. It will raise an exception if the prefab does not exist.
    /// </summary>
    /// <param name="type">The <c>Tile.Ground</c> type to get the tile of.</param>
    /// <returns></returns>
    public static GameObject GetTile(Tile.Ground type)
    {
        string finalPath = tilesPath;

        switch (type)
        {
        case Tile.Ground.Grass:
            finalPath += "grass";
            break;

        case Tile.Ground.Sand:
            finalPath += "sand";
            break;

        case Tile.Ground.Water:
            finalPath += "water";
            break;

        default:
            throw new System.Exception("Ground type does not hasve a matching prefab in the database");
        }
        return(LoadGameObject(finalPath));
    }