public void AddSpell(ICastable spell, Vector2D position) { if (spell == null) throw new ArgumentNullException(); _spells[spell] = position; }
public void CreateWall(Vector2D position) { if(!ExistsWallAt(position)) _walls[position] = new WallBlock(); _walls[position].Add(new Wall()); }
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; }
public Vector2D ToArrayIndex(Vector2D coordinate) { return new Vector2D ( coordinate.X + _xMax / 2, coordinate.Y + _yMax / 2 ); }
public HealingMissle(Spell castedSpell, Vector2D position, Vector2D direction, TimeSpan timeCasted, int healing) : base(castedSpell, position, direction, timeCasted) { Healing = healing; }
public Vector2D ToCoordinate(Vector2D index) { return new Vector2D ( index.X - _xMax / 2, index.Y - _yMax / 2 ); }
private SpinningMissle(Spell castedSpell, Vector2D position, Vector2D direction, TimeSpan timeCasted) : base(castedSpell, position, direction, timeCasted) { _spinningMissleState = SpinningMissleState.None; }
public CooldownExceptionArgs(Vector2D direction, Vector2D position, ICastable castable, TimeSpan remainingTime) { Direction = direction; Position = position; Castable = castable; RemainingTime = remainingTime; }
public Missle(Spell castedSpell, Vector2D position, Vector2D direction, TimeSpan timeCasted) { if (castedSpell == null) throw new ArgumentNullException(); CastedSpell = castedSpell; Position = position; Direction = direction; _timeCasted = timeCasted; }
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); }
private Vector2D getNextDirectionCounterClockwise(Vector2D prevDirection) { return prevDirection.RotateBy45DegreesCounterClockwise(); }
public IHealthyObject GetHealthyObjectAt(Vector2D position) { return GetWallAt(position).GetTop(); }
public bool Equals(Vector2D other) { return (X == other.X) && (Y == other.Y); }
internal WallBlock GetWallAt(Vector2D position) { if (!ExistsWallAt(position)) return null; var block = _walls[position]; return block; }
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); }
public override Missle Cast(Vector2D position, Vector2D direction) { var missle = base.Cast(position, direction); return new SpinningMissle(missle); }
public PositionIsOccupiedException(Vector2D position) : base($"The position {position} is occupied") { }
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); }
// 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; }
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; } }
private void AddWall(Vector2D position) { SetCodeAt(_calculator.ToArrayIndex(position), FieldCode.WallCode); _game.WallStore.CreateWall(position); }
public SpellCooldownZeroEventArgs(Vector2D position) { Position = position; }
public void Collide() { Direction = new Vector2D(0, 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); }
private void SetCodeAt(Vector2D position, FieldCode code) { _field[position.X, position.Y] = (int)code; }
public MissleMovedHandlerArgs(Vector2D previousPosition) { PreviousPosition = previousPosition; }