public override void Update() { if (Energy <= 0) { ShipDied?.Invoke(this, new EventArgs()); } if (Pos.X + Dir.X > 0 && Pos.X + Dir.X < Game.Width) { Pos.X += Dir.X; } if (Pos.Y + Dir.Y > 0 && Pos.Y + Dir.Y < Game.Height) { Pos.Y += Dir.Y; } }
/// <summary> /// Выстрелить по этому игроку. /// </summary> /// <param name="cell"></param> protected virtual void Hit(Cell cell) { bool missedShot = true; foreach (var ship in ships) { int damagedBlock = ship.GetBlockIndex(cell); if (damagedBlock > -1) { ship.Hit(damagedBlock); missedShot = false; if (ship.IsAlive()) { ShipBlockDamaged?.Invoke(this, cell); } else { ships.Remove(ship); ShipDied?.Invoke(this, ship); if (GetCountAliveShips() == 0) { AllShipsDied?.Invoke(this); } } break; } } if (missedShot) { ShotMissed?.Invoke(this, cell); BindStep(); } else { EnemyPlayer.BindStep(); } }