コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: Mine.cs プロジェクト: mimikali/NavalGame
        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;
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: mimikali/NavalGame
 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]);
 }