Esempio n. 1
0
 public void AddSpell(ICastable spell,
     Vector2D position)
 {
     if (spell == null)
         throw new ArgumentNullException();
     _spells[spell] = position;
 }
Esempio n. 2
0
        public void CreateWall(Vector2D position)
        {
            if(!ExistsWallAt(position))
                _walls[position] = new WallBlock();

            _walls[position].Add(new Wall());
        }
Esempio n. 3
0
 public void DeserializeFirst()
 {
     var pos = new Vector2D(0, 0);
     var block = _walls[pos];
     _walls.Remove(pos);
     switch (_serializationType)
     {
         case "xml":
         {
             XmlSerializer serializer = new XmlSerializer(typeof(WallBlock), new Type[] { typeof(Wall) });
             using (var file = File.OpenRead("text.xml"))
             {
                 block = (WallBlock)serializer.Deserialize(file);
             }
         }
         break;
         case "json":
         {
             DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(WallBlock), new[] { typeof(Wall) });
             using (var file = File.OpenRead("text.json"))
             {
                     block = (WallBlock)serializer.ReadObject(file);
             }
         }
         break;
     }
     _walls[pos] = block;
 }
Esempio n. 4
0
 public Vector2D ToArrayIndex(Vector2D coordinate)
 {
     return new Vector2D
     (
         coordinate.X + _xMax / 2,
         coordinate.Y + _yMax / 2
     );
 }
Esempio n. 5
0
 public HealingMissle(Spell castedSpell,
     Vector2D position,
     Vector2D direction,
     TimeSpan timeCasted, int healing)
     : base(castedSpell, position, direction, timeCasted)
 {
     Healing = healing;
 }
Esempio n. 6
0
 public Vector2D ToCoordinate(Vector2D index)
 {
     return new Vector2D
     (
         index.X - _xMax / 2,
         index.Y - _yMax / 2
     );
 }
Esempio n. 7
0
 private SpinningMissle(Spell castedSpell,
     Vector2D position,
     Vector2D direction,
     TimeSpan timeCasted)
     : base(castedSpell, position,
     direction, timeCasted)
 {
     _spinningMissleState = SpinningMissleState.None;
 }
Esempio n. 8
0
 public CooldownExceptionArgs(Vector2D direction,
     Vector2D position,
     ICastable castable,
     TimeSpan remainingTime)
 {
     Direction = direction;
     Position = position;
     Castable = castable;
     RemainingTime = remainingTime;
 }
Esempio n. 9
0
File: Missle.cs Progetto: kostya9/OP
 public Missle(Spell castedSpell,
     Vector2D position,
     Vector2D direction,
     TimeSpan timeCasted)
 {
     if (castedSpell == null)
         throw new ArgumentNullException();
     CastedSpell = castedSpell;
     Position = position;
     Direction = direction;
     _timeCasted = timeCasted;
 }
Esempio n. 10
0
 public void CastSpell(ICastable spell,
     Vector2D direction)
 {
     if (spell == null)
         throw new ArgumentNullException();
     Vector2D position;
     try
     {
         position = _spells[spell];
     }
     catch (KeyNotFoundException e)
     {
         Debug.WriteLine("Could not find a spell in the dictionary");
         return;
     }
     var missle = spell.Cast(position, direction);
     OnSpellCasted(spell, missle);
 }
Esempio n. 11
0
 private Vector2D getNextDirectionCounterClockwise(Vector2D prevDirection)
 {
     return prevDirection.RotateBy45DegreesCounterClockwise();
 }
Esempio n. 12
0
 public IHealthyObject GetHealthyObjectAt(Vector2D position)
 {
     return GetWallAt(position).GetTop();
 }
Esempio n. 13
0
 public bool Equals(Vector2D other)
 {
     return (X == other.X) && (Y == other.Y);
 }
Esempio n. 14
0
        internal WallBlock GetWallAt(Vector2D position)
        {
            if (!ExistsWallAt(position))
                return null;

            var block = _walls[position];

            return block;
        }
Esempio n. 15
0
        internal bool ExistsWallAt(Vector2D position)
        {
            var contains = _walls.ContainsKey(position);
            if (!contains)
                return false;

            var block = _walls[position];

            if (block.GetTop().HitPoints == 0)
                block.Remove();

            if (block.Count == 0)
                _walls.Remove(position);

            return _walls.ContainsKey(position);
        }
Esempio n. 16
0
 public override Missle Cast(Vector2D position,
     Vector2D direction)
 {
     var missle = base.Cast(position, direction);
     return new SpinningMissle(missle);
 }
Esempio n. 17
0
 public PositionIsOccupiedException(Vector2D position)
     : base($"The position {position} is occupied")
 {
 }
Esempio n. 18
0
File: Spell.cs Progetto: kostya9/OP
        public virtual Missle Cast(Vector2D position, Vector2D direction)
        {
            var canCast = CanCast();
            var timeNow = TimeHelper.GetCurrentTime();
            if (!canCast)
                throw new CooldownException(new CooldownExceptionArgs(direction, position, this, Cooldown - (timeNow - _lastCasted)));

            _lastCasted = timeNow;

            Debug.WriteLine($"Spell casted : {Name}\n Shouts {Sound}");
            return new Missle(this, position, direction, timeNow);
        }
Esempio n. 19
0
        // Prompt the user to direct the missle
        private Vector2D GetNewMissleDirection(Vector2D spellPosition)
        {
            var prevColor = Console.ForegroundColor;
            var enteredKey = ConsoleKey.X;
            var currentDirection = new Vector2D(1, 1);
            var directionViewPosition = spellPosition + currentDirection;
            Console.ForegroundColor = ConsoleColor.Red;

            while (enteredKey != ConsoleKey.Enter)
            {
                ConsoleDrawer.DrawSpell(spellPosition);

                enteredKey = Console.ReadKey().Key;
                if (enteredKey == ConsoleKey.LeftArrow)
                {
                    ConsoleDrawer.ClearConsoleAt(directionViewPosition);
                    currentDirection = getNextDirectionClockwise(currentDirection);
                }
                else if (enteredKey == ConsoleKey.RightArrow)
                {
                    ConsoleDrawer.ClearConsoleAt(directionViewPosition);
                    currentDirection = getNextDirectionCounterClockwise(currentDirection);
                }
                directionViewPosition = spellPosition + currentDirection;
                ConsoleDrawer.DrawDirectionView(directionViewPosition);
            }
            ConsoleDrawer.ClearConsoleAt(spellPosition);
            ConsoleDrawer.ClearConsoleAt(directionViewPosition);
            Console.ForegroundColor = prevColor;
            return currentDirection;
        }
Esempio n. 20
0
 private void DrawAtPositionAndChangeCode(Vector2D position)
 {
     var consolePosition = new Vector2D(_fieldUpperLeft.X + position.X, _fieldUpperLeft.Y + position.Y);
     switch ((FieldCode)_field[position.X, position.Y])
     {
         case FieldCode.TrailCode:
             {
                 ConsoleDrawer.DrawMissleTail(consolePosition);
                 SetCodeAt(position, FieldCode.Nothing);
             }
             break;
         case FieldCode.MissleCode:
             {
                 ConsoleDrawer.DrawMissle(consolePosition);
                 SetCodeAt(position, FieldCode.TrailCode);
             }
             break;
         case FieldCode.Nothing:
             {
                 ConsoleDrawer.ClearConsoleAt(consolePosition);
             }
             break;
         case FieldCode.WallCode:
         {
             var coordinate = _calculator.ToCoordinate(position);
             var healthyObject = _game.WallStore.GetHealthyObjectAt(coordinate);
             //Delete object if it's gone
             if(healthyObject == null || healthyObject.HitPoints == 0)
                 SetCodeAt(position, FieldCode.Nothing);
             ConsoleDrawer.DrawHealthyObject(consolePosition, healthyObject);
         }
         break;
     }
 }
Esempio n. 21
0
 private void AddWall(Vector2D position)
 {
     SetCodeAt(_calculator.ToArrayIndex(position), FieldCode.WallCode);
     _game.WallStore.CreateWall(position);
 }
Esempio n. 22
0
 public SpellCooldownZeroEventArgs(Vector2D position)
 {
     Position = position;
 }
Esempio n. 23
0
File: Missle.cs Progetto: kostya9/OP
 public void Collide()
 {
     Direction = new Vector2D(0, 0);
 }
Esempio n. 24
0
 // To have an ability to delete something if it's gone from the field
 private bool IsInTheField(Vector2D position)
 {
     var xMax = XMax;
     var yMax = YMax;
     var indexPos = _calculator.ToArrayIndex(position);
     return (indexPos.X < xMax) &&
            (indexPos.Y < yMax) &&
            (indexPos.X >= 0) &&
            (indexPos.Y >= 0);
 }
Esempio n. 25
0
 private void SetCodeAt(Vector2D position,
     FieldCode code)
 {
     _field[position.X, position.Y] = (int)code;
 }
Esempio n. 26
0
 public MissleMovedHandlerArgs(Vector2D previousPosition)
 {
     PreviousPosition = previousPosition;
 }