예제 #1
0
        public void ExecuteInstructions_Works_Correctly(string str, string separator, int result)
        {
            var ship = new Ship1();

            ship.ExecuteInstructions(Parser.ParseInstructions(str, separator));
            Assert.That(ship.ManhattanDistance, Is.EqualTo(result));
        }
예제 #2
0
        private void CheckRays()
        {
            if (IsShotAvailable)
            {
                return;
            }

            Dictionary <Collider, bool> originalColliderValues = new Dictionary <Collider, bool>();

            foreach (var collider in Board.Objects)
            {
                if (collider == null)
                {
                    Debug.Log("Collider is null, ignore...");
                    continue;
                }

                originalColliderValues.Add(collider, collider.enabled);
                collider.enabled = (collider.tag == "ShipId:" + Ship2.ShipId) ? true : false;
            }

            bool rayIsFound = false;

            foreach (var limit in Arc.Limits)
            {
                Vector3 vectorFromDegrees = new Vector3((float)Math.Sin(limit.Value * Mathf.Deg2Rad), 0, (float)Math.Cos(limit.Value * Mathf.Deg2Rad));
                vectorFromDegrees = Ship1.TransformVector(vectorFromDegrees);

                RaycastHit hitInfo = new RaycastHit();
                if (Physics.Raycast(Ship1.ShipBase.GetGlobalPoint(limit.Key) + new Vector3(0, 0.003f, 0), vectorFromDegrees + new Vector3(0, 0.003f, 0), out hitInfo, Board.BoardIntoWorld(3 * Board.RANGE_1)))
                {
                    if (hitInfo.collider.tag == "ShipId:" + Ship2.ShipId)
                    {
                        if (!rayIsFound)
                        {
                            MinDistance = new RangeHolder(Ship1.ShipBase.GetGlobalPoint(limit.Key), hitInfo.point, Ship1, Ship2);
                            rayIsFound  = true;
                        }
                        else
                        {
                            RangeHolder secondRayResult = new RangeHolder(Ship1.ShipBase.GetGlobalPoint(limit.Key), hitInfo.point, Ship1, Ship2);
                            if (secondRayResult.DistanceReal < MinDistance.DistanceReal)
                            {
                                MinDistance = new RangeHolder(Ship1.ShipBase.GetGlobalPoint(limit.Key), hitInfo.point, Ship1, Ship2);
                            }
                        }
                    }
                }
            }

            if (rayIsFound)
            {
                Success();
            }

            foreach (var collider in Board.Objects)
            {
                collider.enabled = originalColliderValues[collider];
            }
        }
예제 #3
0
 private void StartGameButtonHandler(object sender, EventArgs e) //кнопка для начала игры
 {
     //скрытие всех начальных элементов формы
     StartGameButton.Hide();
     Ship1.Hide();
     Ship2.Hide();
     Ship3.Hide();
     Ship4.Hide();
     Ship5.Hide();
     Ship6.Hide();
     MartianBattleLabel.Hide();
     //определение управляющего объекта
     m_controlGame = new Controller(this, NumbersOfLives, Platform, new TextBox[] { Ship1, Ship2, Ship3, Ship4, Ship5, Ship6 });
     m_controlGame.StartGame(); //запуск игры
 }
예제 #4
0
        private void CheckRequirements()
        {
            if (Arc.CannotBeUsedForAttackThisRound)
            {
                return;
            }

            if (Range > Weapon.WeaponInfo.MaxRange)
            {
                return;
            }

            if (Arc.Limits != null && Arc.Limits.Count > 0)
            {
                float signedAngle = (float)Math.Round(Vector3.SignedAngle(MinDistance.Vector, Ship1.GetFrontFacing(), Vector3.down), 2);
                if (Arc.Facing != ArcFacing.Rear && Arc.Facing != ArcFacing.FullRear)
                {
                    if (signedAngle < Arc.Limits.First().Value || signedAngle > Arc.Limits.Last().Value)
                    {
                        return;
                    }
                }
                else
                {
                    if (signedAngle > Arc.Limits.First().Value&& signedAngle < Arc.Limits.Last().Value)
                    {
                        return;
                    }
                }
            }

            Success();
        }
예제 #5
0
        private void CheckRange()
        {
            InArcInfo    = new Dictionary <GenericArc, bool>();
            InSectorInfo = new Dictionary <GenericArc, bool>();

            List <ArcType> WeaponArcRestrictions = new List <ArcType>(Weapon.WeaponInfo.ArcRestrictions);

            if (WeaponArcRestrictions.Contains(ArcType.DoubleTurret))
            {
                WeaponArcRestrictions.RemoveAll(a => a == ArcType.DoubleTurret);
                WeaponArcRestrictions.Add(ArcType.SingleTurret);
            }

            foreach (var arc in Ship1.ArcsInfo.Arcs)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InArcInfo.Add(arc, shotInfoArc.InArc);
            }

            List <GenericArc> sectorsAndTurrets = new List <GenericArc>();

            sectorsAndTurrets.AddRange(Ship1.SectorsInfo.Arcs);
            sectorsAndTurrets.AddRange(Ship1.ArcsInfo.Arcs.Where(a => a.ArcType == ArcType.SingleTurret));
            foreach (var arc in sectorsAndTurrets)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InSectorInfo.Add(arc, shotInfoArc.InArc);

                if (WeaponArcRestrictions.Count > 0 && !WeaponArcRestrictions.Contains(arc.ArcType))
                {
                    continue;
                }

                bool result = shotInfoArc.IsShotAvailable;
                if (arc.ArcType == ArcType.Bullseye)
                {
                    Ship1.CallOnBullseyeArcCheck(Ship2, ref result);
                }

                if (result)
                {
                    if (IsShotAvailable == false)
                    {
                        MinDistance = shotInfoArc.MinDistance;
                    }
                    else
                    {
                        if (shotInfoArc.MinDistance.DistanceReal < MinDistance.DistanceReal)
                        {
                            MinDistance = shotInfoArc.MinDistance;
                        }
                    }

                    IsShotAvailable = true;

                    if (!(arc is ArcBullseye))
                    {
                        ShotAvailableFromArcs.Add(arc);
                    }
                }

                if (NearestFailedDistance == null)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
                else if (shotInfoArc.MinDistance.DistanceReal < NearestFailedDistance.DistanceReal)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
            }

            // For 360 arcs
            if (Weapon.WeaponInfo.CanShootOutsideArc)
            {
                DistanceInfo distInfo = new DistanceInfo(Ship1, Ship2);

                if (distInfo.Range < 4)
                {
                    MinDistance     = distInfo.MinDistance;
                    IsShotAvailable = true;
                }
                else
                {
                    NearestFailedDistance = distInfo.MinDistance;
                }
            }
        }
예제 #6
0
        private void CheckRequirements()
        {
            if (Range > 3)
            {
                return;
            }

            if (Arc.Limits != null && Arc.Limits.Count > 0)
            {
                float signedAngle = (float)Math.Round(Vector3.SignedAngle(MinDistance.Vector, Ship1.GetFrontFacing(), Vector3.up), 2);
                if (Arc.Facing != ArcFacing.Rear)
                {
                    if (signedAngle < Arc.Limits.First().Value || signedAngle > Arc.Limits.Last().Value)
                    {
                        return;
                    }
                }
                else
                {
                    if (signedAngle > Arc.Limits.First().Value&& signedAngle < Arc.Limits.Last().Value)
                    {
                        return;
                    }
                }
            }

            Success();
        }
예제 #7
0
        private void CheckRange()
        {
            InArcInfo    = new Dictionary <GenericArc, bool>();
            InSectorInfo = new Dictionary <GenericArc, bool>();

            foreach (var arc in Ship1.ArcsInfo.Arcs)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InArcInfo.Add(arc, shotInfoArc.InArc);
            }

            List <GenericArc> sectorsAndTurrets = new List <GenericArc>();

            sectorsAndTurrets.AddRange(Ship1.SectorsInfo.Arcs);
            sectorsAndTurrets.AddRange(Ship1.ArcsInfo.Arcs.Where(a => a.ArcType == ArcType.SingleTurret));
            foreach (var arc in sectorsAndTurrets)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc, Weapon);
                InSectorInfo.Add(arc, shotInfoArc.InArc);

                if (Weapon.WeaponInfo.ArcRestrictions.Count > 0 && !Weapon.WeaponInfo.ArcRestrictions.Contains(arc.ArcType))
                {
                    continue;
                }

                bool result = shotInfoArc.IsShotAvailable;
                if (arc.ArcType == ArcType.Bullseye)
                {
                    Ship1.CallOnBullseyeArcCheck(Ship2, ref result);
                }

                if (result)
                {
                    if (IsShotAvailable == false)
                    {
                        MinDistance             = shotInfoArc.MinDistance;
                        ObstructedByShips       = shotInfoArc.ObstructedByShips;
                        ObstructedByObstacles   = shotInfoArc.ObstructedByObstacles;
                        IsObstructedByBombToken = shotInfoArc.IsObstructedByBombToken;
                    }
                    else
                    {
                        if (shotInfoArc.MinDistance.DistanceReal < MinDistance.DistanceReal)
                        {
                            MinDistance             = shotInfoArc.MinDistance;
                            ObstructedByShips       = shotInfoArc.ObstructedByShips;
                            ObstructedByObstacles   = shotInfoArc.ObstructedByObstacles;
                            IsObstructedByBombToken = shotInfoArc.IsObstructedByBombToken;
                        }
                    }

                    IsShotAvailable = true;

                    if (!(arc is ArcBullseye) ||
                        (Weapon.WeaponInfo.ArcRestrictions.Count > 0 && Weapon.WeaponInfo.ArcRestrictions.Contains(ArcType.Bullseye)))
                    {
                        ShotAvailableFromArcs.Add(arc);
                    }
                }

                if (NearestFailedDistance == null)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
                else if (shotInfoArc.MinDistance.DistanceReal < NearestFailedDistance.DistanceReal)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
            }

            // For 360 arcs
            if (Weapon.WeaponInfo.CanShootOutsideArc)
            {
                DistanceInfo distInfo = new DistanceInfo(Ship1, Ship2);

                if (distInfo.Range < 4)
                {
                    MinDistance = distInfo.MinDistance;
                    //TODO: Obstructed shots for 360 arcs
                    IsShotAvailable = true;
                }
                else
                {
                    NearestFailedDistance = distInfo.MinDistance;
                }
            }

            /*Debug.Log("Check results:");
             * if (IsShotAvailable)
             * {
             *  foreach (var item in ObstructedByShips)
             *  {
             *      Debug.Log("Obstructed by " + item.PilotInfo.PilotName);
             *  }
             *  foreach (var item in ObstructedByObstacles)
             *  {
             *      Debug.Log("Obstructed by " + item.Name);
             *  }
             * }*/
        }
예제 #8
0
    void Awake()
    {
        Index = PlayerPrefs.GetInt("ShipSelection");
        Ship0 = GameObject.Find("Ship0");
        Ship1 = GameObject.Find("Ship1");
        Ship2 = GameObject.Find("Ship2");
        Ship3 = GameObject.Find("Ship3");
        Ship4 = GameObject.Find("Ship4");
        Ship5 = GameObject.Find("Ship5");

        if (Index == 0)
        {
            Ship0.SetActive(true);
            Ship1.SetActive(false);
            Ship2.SetActive(false);
            Ship3.SetActive(false);
            Ship4.SetActive(false);
            Ship5.SetActive(false);
            Player = GameObject.Find("Ship0");
        }
        if (Index == 1)
        {
            Ship0.SetActive(false);
            Ship1.SetActive(true);
            Ship2.SetActive(false);
            Ship3.SetActive(false);
            Ship4.SetActive(false);
            Ship5.SetActive(false);
            Player = GameObject.Find("Ship1");
        }
        if (Index == 2)
        {
            Ship0.SetActive(false);
            Ship1.SetActive(false);
            Ship2.SetActive(true);
            Ship3.SetActive(false);
            Ship4.SetActive(false);
            Ship5.SetActive(false);
            Player = GameObject.Find("Ship2");
        }
        if (Index == 3)
        {
            Ship0.SetActive(false);
            Ship1.SetActive(false);
            Ship2.SetActive(false);
            Ship3.SetActive(true);
            Ship4.SetActive(false);
            Ship5.SetActive(false);
            Player = GameObject.Find("Ship3");
        }
        if (Index == 4)
        {
            Ship0.SetActive(false);
            Ship1.SetActive(false);
            Ship2.SetActive(false);
            Ship3.SetActive(false);
            Ship4.SetActive(true);
            Ship5.SetActive(false);
            Player = GameObject.Find("Ship4");
        }
        if (Index == 5)
        {
            Ship0.SetActive(false);
            Ship1.SetActive(false);
            Ship2.SetActive(false);
            Ship3.SetActive(false);
            Ship4.SetActive(false);
            Ship5.SetActive(true);
            Player = GameObject.Find("Ship5");
        }
    }