Example #1
0
        /// <summary>
        /// Let the unit walk to the targetdirection in the specified direction. When the direction is null North is used. 
        /// the unit value should be set by properties later on 
        /// </summary>
        /// <param name="targetX"></param>
        /// <param name="targetY"></param>
        /// <param name="targetDirection"></param>
        public Walk(Unit unit, Tile targetPosition, ActionType? actionType = ActionType.Walk)
            : base(unit, actionType.Value)
        {
            this.TargetPosition = targetPosition;
            this.Speed = unit.UnitSpeed;

            this.TargetDirection = Direction.East;
        }
        public static void LoadMap(string mapName)
        {
            // Read the map file
            string pathToMap = GetMapPath(mapName);
            string mapFileContent = File.ReadAllText(pathToMap);

            // Initialize the tiles array
            string[] rows = mapFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            int columnLength = rows[0].Split(',').Length;
            Tile[,] tiles = new Tile[rows.Length, columnLength];

            // Loop through all the lines in the mapfile
            for (int rowIndex = 0; rowIndex < rows.Length; rowIndex++) {
                // Loop through all the command seperated values of each line
                string[] columns = rows[rowIndex].Split(',');
                for (int colIndex = 0; colIndex < columns.Length; colIndex++) {
                    // Add the new tile to our array
                    int tileType = int.Parse(columns[colIndex]);
                    tiles[rowIndex, colIndex] = new Tile((TileType)tileType, rowIndex, colIndex);
                }
            }

            Map.Instance.SetMap(tiles);
        }
Example #3
0
 public Charge(Unit unit, Tile targetPosition)
     : base(unit, targetPosition, ActionType.Charge)
 {
     Speed = Unit.UnitSpeed * 1.5;
 }
Example #4
0
 public void SetMap(Tile[,] tiles)
 {
     this.Tiles = tiles;
     // Loop through all the rows in the file
     for (int rowIndex = 0; rowIndex < this.Tiles.GetLength(0); rowIndex++)
     {
         // Loop through all the columns of each row
         for (int colIndex = 0; colIndex < this.Tiles.GetLength(1); colIndex++)
         {
             this.Tiles[rowIndex, colIndex].Map = this;
         }
     }
 }