/// <summary> /// The method that all Tile must implement to describe their own behavior /// It return a Tile : /// - Either itself, if no change has been made /// - Either a new Tile, depending on the transformation it got (condition of transformation in the ExecuteStep of the inherited Tile classes) /// </summary> /// <param name="neighbors">The list of neighbors of the tile</param> public override Tile ExecuteStep(List <Tile> neighbors) { // Become "Rock" if the "Ice" touches "Lava" if (neighbors.Any(n => n.Type == EnumTileType.Lava)) { return(TileFactory.CreateTileAt(this.Position, EnumTileType.Rock)); } return(this); }
/// <summary> /// The method that all Tile must implement to describe their own behavior /// It return a Tile : /// - Either itself, if no change has been made /// - Either a new Tile, depending on the transformation it got (condition of transformation in the ExecuteStep of the inherited Tile classes) /// </summary> /// <param name="neighbors">The list of neighbors of the tile</param> public override Tile ExecuteStep(List <Tile> neighbors) { // Become "Lava" if the "Wall" touches one if (neighbors.Any(n => n.Type == EnumTileType.Lava)) { // 3 chances out of 10 to become "Lava" if the "Wall" touches one Random rand = new Random(); if (rand.Next(10) < 3) { return(TileFactory.CreateTileAt(this.Position, EnumTileType.Lava)); } } return(this); }
/// <summary> /// Get the tile at a specific position /// </summary> /// <param name="x">The x coordonate</param> /// <param name="y">The y coordonate</param> /// <returns></returns> public Tile GetTileOrDefault(int x, int y) { // Get the Tile list or instantiate it if (Tiles == null) { Tiles = new List <Tile>(); } Tile tile = Tiles.FirstOrDefault(t => t.Position != null && t.Position.IsAt(x, y)); if (tile == null) { tile = TileFactory.CreateTileAt(new Position(x, y)); } return(tile); }
/// <summary> /// Initialize the board with specified height and width /// </summary> /// <param name="height">The height of the board</param> /// <param name="width">The width of the board</param> public static void Init(int height, int width) { if (instance == null) { instance = new Board(Math.Min(Constants.MaxHeight, height), Math.Min(Constants.MaxWidth, width)); } // Instantiate the Tile list Instance.Tiles = new List <Tile>(); // Create walls on bottom line for (int x = 0; x < Instance.Width; x++) { Instance.Tiles.Add(TileFactory.CreateTileAt(new Position(x, 0), EnumTileType.Wall)); } // Create walls on top line for (int x = 0; x < Instance.Width; x++) { Instance.Tiles.Add(TileFactory.CreateTileAt(new Position(x, Instance.Height - 1), EnumTileType.Wall)); } // Create walls on first column for (int y = 0; y < Instance.Height; y++) { Instance.Tiles.Add(TileFactory.CreateTileAt(new Position(0, y), EnumTileType.Wall)); } // Create walls on last column for (int y = 0; y < Instance.Height; y++) { Instance.Tiles.Add(TileFactory.CreateTileAt(new Position(Instance.Width - 1, y), EnumTileType.Wall)); } // Create others Tiles (without the frame of 1 tile) randomly for (int x = 1; x < Instance.Width - 1; x++) { for (int y = 1; y < Instance.Height - 1; y++) { Instance.Tiles.Add(TileFactory.CreateTileAt(new Position(x, y))); } } }