public int Move(Point destination) { var distance = MapDisplay.PointDifference(_Position, destination); if (distance <= MovesLeft) { Unit unit = Game.GetUnitAt(destination); if (unit == null) { MovesLeft -= distance; _Position = destination; if (Game.GetMineAt(destination) != null) { return(Game.EnterMinefield(this)); } return(0); } else { if (!unit.IsDetected && unit.IsSubmerged) { Game.FireSubmarineDetectedEvent(); } unit.IsDetected = true; } } return(-1); }
public virtual void OnGameChanged() { if (Health <= 0) { Game.RemoveUnit(this); Wreck wreck = new Wreck(Player, Position); wreck.Name = Name; Game.AddUnit(wreck); Game.FireSinkingEvent(); } bool isDetected = IsDetected; if (!IsSubmerged) { isDetected = true; } else if (!IsDetected && new Random(Game.TurnIndex * GetHashCode()).NextDouble() < 0.5) { isDetected = Game.Units.Any(u => MapDisplay.PointDifference(u.Position, Position) <= u.Type.SonarRange && u.Player.Faction != Player.Faction); } if (IsDetected != isDetected && isDetected && IsSubmerged) { Game.FireSubmarineDetectedEvent(); } IsDetected = isDetected; }
public void OnGameChanged() { bool isVisible = IsVisible; if (!IsVisible && new Random(Game.TurnIndex * GetHashCode()).NextDouble() < 0.25) { isVisible = Game.Units.Any(u => MapDisplay.PointDifference(u.Position, Position) <= 2 && u.Player.Faction != Faction); } IsVisible = isVisible; }
public bool IsTileVisible(Point position) { if (_VisibleTiles == null) { _VisibleTiles = new List <bool>(); for (int y = 0; y < Game.Terrain.Height; y++) { for (int x = 0; x < Game.Terrain.Width; x++) { bool a = false; for (int i = 0; i < Units.Count; i++) { if (MapDisplay.PointDifference(new Point(x, y), Units[i].Position) <= Units[i].Type.ViewDistance) { a = true; break; } } _VisibleTiles.Add(a); } } } return(_VisibleTiles[position.X + position.Y * Game.Terrain.Width]); }