Exemplo n.º 1
0
    public bool checkGameOver()
    {
        GameObject      gameI    = GameObject.Find("Display Game Information");
        GameInformation gameInfo = gameI.GetComponent <GameInformation>();

        if (ShipContainer.checkIfEarthLost())
        {
            if (GlobalVariables.local)
            {
                SceneManager.LoadScene("MarsWins", LoadSceneMode.Single);
                return(true);
            }
            else
            {
                FindObjectOfType <NetworkEndSceneHandler>().loadSceneOnClient("MarsWins");
                return(true);
            }
        }

        if (ShipContainer.checkIfMarsLost())
        {
            if (GlobalVariables.local)
            {
                SceneManager.LoadScene("EarthWins", LoadSceneMode.Single);
                return(true);
            }
            else
            {
                FindObjectOfType <NetworkEndSceneHandler>().loadSceneOnClient("EarthWins");
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 2
0
    public void ChangeShips()
    {
        int m = ShipContainer.GetSpaceshipCount();

        for (int i = 0; i < shipControls.Length; i++)
        {
            if (shipControls [i])
            {
                GameObject  ship  = ShipContainer.GetSpaceShip(i);
                ShipControl sc    = null;
                int         image = 0;
                if (ship)
                {
                    ship.transform.position = resetPositions [i];
                    ship.transform.rotation = Quaternion.identity;

                    sc    = ship.GetComponent <ShipControl> ();
                    image = (int)sc.shipType;
                    sc.Reset();
                }
                shipControls [i].SetShip(sc, shipImages [image], i <= m);
            }
        }
        if (scrapText)
        {
            scrapText.text = Mathf.FloorToInt(Highscore.GetScore()).ToString();
        }
    }
Exemplo n.º 3
0
        public static List <ShipContainer> GenerateRandomContainers(int amount, int seed)
        {
            Random rnd = new Random(seed);
            List <ShipContainer> containers = new List <ShipContainer>();

            for (int i = 0; i < amount; i++)
            {
                ShipContainer container;
                int           weight = rnd.Next(4, 20);
                weight = weight * 1000;
                int type = rnd.Next(5);

                if (type == 1)
                {
                    container = new ShipContainer(weight, Types.ContainerTypes.Cooled);
                }
                else if (type == 2)
                {
                    container = new ShipContainer(weight, Types.ContainerTypes.Valueable);
                }
                else
                {
                    container = new ShipContainer(weight, Types.ContainerTypes.Regular);
                }

                containers.Add(container);
            }

            return(containers);
        }
Exemplo n.º 4
0
        public bool CheckSides(ShipContainer c)
        {
            if (c.Type == Types.ContainerTypes.Regular)
            {
                if (Ship.AddRegularContainer(c, Ship.CheckBalance(false)))
                {
                    return(true);
                }
            }

            if (c.Type == Types.ContainerTypes.Cooled)
            {
                if (Ship.AddCooledContainer(c, Ship.CheckBalance(false)))
                {
                    return(true);
                }
            }

            if (c.Type == Types.ContainerTypes.Valueable)
            {
                if (Ship.AddValueableContainer(c, Ship.CheckBalance(false)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
    virtual protected void Update()
    {
        if (!checkGameOver())
        {
            if (timer > 0)
            {
                timer -= Time.deltaTime;
            }
            else if (!eventIsRunning)
            {
                Debug.Log(eventPropability);
                if (eventAllowed)
                {
                    int i = Random.Range(0, 100);
                    if (i < eventPropability)
                    {
                        ShipContainer.deactivateAllShips();
                        eventIsRunning = true;
                        eventAllowed   = false;
                        EventSupportShip sShip = new EventSupportShip();
                        sShip.initiateEvent();
                    }
                }

                if (!eventIsRunning)
                {
                    FindObjectOfType <AudioManager>().Stop("engine1");
                    ShipContainer.activateNextShip();
                    eventAllowed = true;
                    timer       += roundTime;
                }
            }
        }
    }
Exemplo n.º 6
0
 public void SetShipChunk(ShipChunk chunk)
 {
     this.shipChunk = chunk;
     base.transform.SetParent(chunk.transform);
     this.rigidbody2d       = chunk.rigidbody2d;
     chunk.rigidbody2d.mass = (((double)chunk.rigidbody2d.mass >= 0.01 ? chunk.rigidbody2d.mass + this.mass : this.mass));
     this.shipContainer     = chunk.shipContainer;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Raises the destroy event.
 /// </summary>
 void OnDestroy()
 {
     ShipContainer.RemoveSpaceShip(this.gameObject);
     if (criticalShip)
     {
         Global.currentGlobalControl.GameOver(0.5f);
     }
 }
Exemplo n.º 8
0
    /// <summary>
    /// Raises the collision stay2d event.
    /// </summary>
    /// <param name="coll">Coll.</param>

    /*void OnCollisionStay2D (Collision2D coll)
     * {
     *      if (path) {
     *              path.StopPathing ();
     *      }
     *      if (movement) {
     *              movement.ClearTargets ();
     *      }
     * }*/

    /// <summary>
    /// Start this instance.
    /// </summary>
    void Awake()
    {
        ShipContainer.AddSpaceShip(transform.gameObject);
        if (ShipContainer.lastContainer)
        {
            transform.parent = ShipContainer.lastContainer.transform;
        }
    }
Exemplo n.º 9
0
 public void Instruct()
 {
     if (instructable)
     {
         Movement m = GetComponent <Movement> ();
         if (m)
         {
             m.SetTarget(ShipContainer.GetMainShip().transform.position);
             m.speed = instructedSpeed;
         }
     }
 }
Exemplo n.º 10
0
        public static List <ShipContainer> GenereateSpecificContainer(int weight, Types.ContainerTypes type, int amount)
        {
            List <ShipContainer> containers = new List <ShipContainer>();

            for (int i = 0; i < amount; i++)
            {
                ShipContainer container = new ShipContainer(weight, type);
                containers.Add(container);
            }

            return(containers);
        }
Exemplo n.º 11
0
    public void SetButtonText()
    {
        if (selectedShip != 0)
        {
            GameObject ship = ships [selectedShip - 1];
            GetComponent <AudioManager> ().selectedShip = ship;
            if (ship != null)
            {
                buyUpgradePanel.SetActive(true);
                buyShipsPanel.SetActive(false);
                buyUpgradePanel.gameObject.transform.GetChild(0).GetComponent <Button> ().enabled = true;

                ShipUpgrades u = ship.GetComponent <ShipUpgrades> ();
                SetButtonActive(buyUpgradePanel.transform.GetChild(0).gameObject, u.UpgradeText());
                if (u.AmountOfUpgrades() != u.GetMaxUpgrades())
                {
                    priceText1.text = "" + 5;                     // u.GetUpgradeCost
                    priceText2.text = "";
                }
                else
                {
                    priceText1.text = "";
                    priceText2.text = "";
                }

                /*if (ship.GetComponent<ShipUpgrades> ().GetMaxUpgrades () - ship.GetComponent<ShipUpgrades> ().AmountOfUpgrades () > 0) {
                 *      SetButtonActive (buyUpgradePanel.transform.GetChild (0).gameObject, "Buy Upgrade");
                 *      priceText1.text = "" + 5;
                 *      priceText2.text = "";
                 * } else if (ship.GetComponent<ShipUpgrades> ().GetMaxUpgrades () == ship.GetComponent<ShipUpgrades> ().AmountOfUpgrades ()) {
                 *      buyUpgradePanel.gameObject.transform.GetChild (0).GetComponent<Button> ().enabled = false;
                 *      SetButtonActive (buyUpgradePanel.transform.GetChild (0).gameObject, "Ship Fully Upgraded");
                 *      priceText1.text = "";
                 *      priceText2.text = "";
                 * }*/
            }
            else
            {
                selectedShip = ShipContainer.GetSpaceshipCount() + 1;
                buyShipsPanel.SetActive(true);
                buyUpgradePanel.SetActive(false);
                SetButtonActive(buyShipsPanel.transform.GetChild(0).gameObject, "Buy Pidgeon");
                priceText1.text = "" + 5;
                priceText2.text = "" + 5;
                SetButtonActive(buyShipsPanel.transform.GetChild(1).gameObject, "Buy UFO");
            }
        }
        else
        {
            buyUpgradePanel.SetActive(false);
            buyShipsPanel.SetActive(false);
        }
    }
Exemplo n.º 12
0
    public void displayInformation()
    {
        GameObject ship = ShipContainer.getActiveShip();

        if (ship)
        {
            if (GlobalVariables.singlePlayer && ship.name.StartsWith("Ship_Mars"))
            {
                machineGun = " 1. Machine Gun: Infinite" + "\n";
                missile    = " 2. Missiles:" + ship.GetComponent <AIBehaviour>().missileAmount + "\n";
                laserBeam  = " 3. LaserBeam: " + ship.GetComponent <AIBehaviour>().laserAmount + "\n";

                currentWeapon = " Loaded: ";

                if (ship.GetComponent <AIBehaviour>().weapontype == AIBehaviour.Weapontype.MACHINE_GUN)
                {
                    currentWeapon += "MACHINE GUN";
                }
                else if (ship.GetComponent <AIBehaviour>().weapontype == AIBehaviour.Weapontype.MISSILE)
                {
                    currentWeapon += "MISSILE LAUNCHER";
                }
                else if (ship.GetComponent <AIBehaviour>().weapontype == AIBehaviour.Weapontype.LASER)
                {
                    currentWeapon += "LASERBEAM";
                }
            }
            else
            {
                machineGun = " 1. Machine Gun: Infinite" + "\n";
                missile    = " 2. Missiles:" + ship.GetComponent <Shoot>().missileAmount + "\n";
                laserBeam  = " 3. LaserBeam: " + ship.GetComponent <Shoot>().laserAmount + "\n";

                currentWeapon = " Loaded: ";

                if (ship.GetComponent <Shoot>().weapontype == Shoot.Weapontype.MACHINE_GUN)
                {
                    currentWeapon += "MACHINE GUN";
                }
                else if (ship.GetComponent <Shoot>().weapontype == Shoot.Weapontype.MISSILE)
                {
                    currentWeapon += "MISSILE LAUNCHER";
                }
                else if (ship.GetComponent <Shoot>().weapontype == Shoot.Weapontype.LASER)
                {
                    currentWeapon += "LASERBEAM";
                }
            }
            updateText();
        }
    }
Exemplo n.º 13
0
        public void AddValueableContainer_Test()
        {
            //Arrange
            ShipContainer container = new ShipContainer(20000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Valueable);
            Point         expected  = new Point(0, 2);

            //Act
            ship.AddValueableContainer(container, ContainerMovement_V2.Objects.Enums.Types.Sides.Right);
            Point actual = ship.piles.Where(x => x.containers.Count > 0).Select(x => x.Location).FirstOrDefault();

            //Assert
            Assert.AreEqual(expected.X, actual.X);
            Assert.AreEqual(expected.Y, actual.Y);
        }
Exemplo n.º 14
0
 void GetShips()
 {
     for (int i = 0; i < ships.Length; i++)
     {
         if (ShipContainer.GetSpaceShip(i) != null)
         {
             ships [i] = ShipContainer.GetSpaceShip(i);
         }
         else
         {
             ships [i] = null;
         }
     }
 }
        public void AddCustomContainer_test()
        {
            //Arrange
            ShipContainer expected = new ShipContainer(7000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Cooled);
            ShipContainer actual;

            //Act
            List <ShipContainer> containers = ContainerFactory.GenereateSpecificContainer(7000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Cooled, 1);

            actual = containers[0];

            //Assert
            Assert.AreEqual(expected.Type, actual.Type);
            Assert.AreEqual(expected.Weight, actual.Weight);
        }
Exemplo n.º 16
0
        public void CheckOccupation_Test()
        {
            //Arrange
            ShipContainer container1 = new ShipContainer(20000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Regular);

            ship.AddRegularContainer(container1, ContainerMovement_V2.Objects.Enums.Types.Sides.Left);

            bool expected = false;

            //Act
            bool actual = ship.CheckOccupation(new Point(0, 0));

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 17
0
        public void CheckBalance_Test_01()
        {
            //Arrange
            ShipContainer container1 = new ShipContainer(30000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Regular);
            ShipContainer container2 = new ShipContainer(30000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Regular);
            ShipContainer container3 = new ShipContainer(1000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Regular);

            ship.AddRegularContainer(container1, ContainerMovement_V2.Objects.Enums.Types.Sides.Left);
            ship.AddRegularContainer(container2, ContainerMovement_V2.Objects.Enums.Types.Sides.Right);
            ship.AddRegularContainer(container3, ContainerMovement_V2.Objects.Enums.Types.Sides.Right);

            ContainerMovement_V2.Objects.Enums.Types.Sides expected = ContainerMovement_V2.Objects.Enums.Types.Sides.Middle;

            //Act
            ContainerMovement_V2.Objects.Enums.Types.Sides actual = ship.CheckBalance(false);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 18
0
    public void StartExplosion()
    {
        if (gameObject.name.StartsWith("Ship"))
        {
            ShipContainer.removeShipFromList(gameObject);
        }

        Destroy(gameObject);

        GameObject explosion = Resources.Load(ResourcePathConstants.explosion) as GameObject;
        GameObject expl      = GameObject.Instantiate(explosion, gameObject.transform.position, Quaternion.identity);

        if (!GlobalVariables.local)
        {
            if (NetworkServer.active)
            {
                NetworkServer.Spawn(expl);
            }
        }
    }
Exemplo n.º 19
0
        public void AddContainer_Test_02()
        {
            //Arrange
            bool expected = false;

            ShipContainer        added      = new ShipContainer(20000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Cooled);
            List <ShipContainer> containers = ContainerFactory.GenereateSpecificContainer(10000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Regular, 12);
            Stack stack = new Stack(new System.Drawing.Point(0, 0));

            foreach (var c in containers)
            {
                stack.AddContainer(c);
            }

            //Act
            bool actual = stack.AddContainer(added);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
    public void createGameScene()
    {
        ShipContainer.resetShipLists();
        GameObject controller = GameObject.Find("Game Controller");

        if (controller == null)
        {
            controller = GameObject.Find("NetworkGameController");
        }
        GameController gameController = controller.GetComponent <GameController>();

        this.shipAmount      = gameController.shipNumber;
        this.asteroidDensity = gameController.asteroidDensity;
        game = new List <GameObject>();
        this.createBackground();
        this.createBackgroundPlanet();
        this.spawnAsteroids();
        this.spawnShips();
        ShipContainer.printShips();
    }
Exemplo n.º 21
0
    public void ChangeShips()
    {
        int m = ShipContainer.GetSpaceshipCount();

        for (int i = 0; i < shipControls.Length; i++)
        {
            if (shipControls [i])
            {
                GameObject  ship  = ShipContainer.GetSpaceShip(i);
                ShipControl sc    = null;
                int         image = 0;
                if (ship)
                {
                    sc    = ship.GetComponent <ShipControl> ();
                    image = (int)sc.shipType;
                }
                shipControls [i].SetShip(sc, shipImages [image], i < m, activeSprite, inActiveSprite);
                shipControls [i].SetSelectionImage();
            }
        }
    }
Exemplo n.º 22
0
        public void CheckSides_Test()
        {
            //Arrange
            ShipContainer con = ContainerFactory.GenereateSpecificContainer(70000, ContainerMovement_V2.Objects.Enums.Types.ContainerTypes.Regular, 1)[0];

            Ship expected = ShipFactory.GenerateDefaultShip();

            expected.AddRegularContainer(con, ContainerMovement_V2.Objects.Enums.Types.Sides.Left);
            expected.AddRegularContainer(con, ContainerMovement_V2.Objects.Enums.Types.Sides.Right);
            expected.CheckBalance(false);

            Test_Dock.Ship.AddRegularContainer(con, ContainerMovement_V2.Objects.Enums.Types.Sides.Left);

            //Act
            Test_Dock.CheckSides(con);
            var actual = Test_Dock.Ship;

            actual.CheckBalance(false);

            //Assert
            Assert.AreEqual(expected.LeftWeight, actual.LeftWeight);
            Assert.AreEqual(expected.RightWeight, actual.RightWeight);
        }
Exemplo n.º 23
0
    /// <summary>
    /// Spawn the specified offset and baseAngle.
    /// </summary>
    /// <param name="offset">Offset. The index of the multispawn at which this spawn is.</param>
    /// <param name="baseAngle">Base angle. The angle all multispawn objects will be based on.</param>
    void Spawn(int offset, float baseAngle)
    {
        Vector3 oldPosition = transform.position;

        float   corrector;
        Vector3 corrected = transform.position;

        if (spawnAlignment.x != 0f)
        {
            corrector   = Mathf.Ceil(transform.position.x / spawnAlignment.x);
            corrected.x = corrector * spawnAlignment.x;
        }
        if (spawnAlignment.y != 0f)
        {
            corrector   = Mathf.Ceil(transform.position.y / spawnAlignment.y);
            corrected.y = corrector * spawnAlignment.y;
        }
        if (spawnAlignment.z != 0f)
        {
            corrector   = Mathf.Ceil(transform.position.z / spawnAlignment.z);
            corrected.z = corrector * spawnAlignment.z;
        }
        transform.position = corrected;

        // Get the angle at which to spawn
        int   adapter = Mathf.FloorToInt((offset + 1) / 2f) * Global.signs [offset % 2];
        float angle   = (angularSeparation) * adapter + baseAngle;

        // Pre rotate so transform.up becomes usable
        transform.eulerAngles = new Vector3(0f, 0f, (baseAngle + (Mathf.PI * 0.5f)) * Mathf.Rad2Deg);

        // Decide starting position
        // SpaceObjectSpawnType.Predefined not needed in switch
        switch (spawnType)
        {
        case SpaceObjectSpawnType.Parallel:
            transform.position = Screen.GetRadiusEdge(angle);
            break;
        }

        corrected           = adapter * gridSeparation;
        transform.position += corrected;

        // Add random offset to start position
        transform.position = new Vector3(transform.position.x - SeededRandom.Range(spawnOffsets.minOffset.x, spawnOffsets.maxOffset.x),
                                         transform.position.y - SeededRandom.Range(spawnOffsets.minOffset.y, spawnOffsets.maxOffset.y),
                                         transform.position.z - SeededRandom.Range(spawnOffsets.minOffset.z, spawnOffsets.maxOffset.z));

        Vector3 targetPoint = predefinedTrajectory;

        // SpaceObjectTrajectoryType.Predefined no needed in switch
        switch (trajectoryType)
        {
        case SpaceObjectTrajectoryType.Targeted:
            // Pick a random target, if none exists, use predefined targetPoint
            GameObject target = ShipContainer.GetSpaceShip(SeededRandom.Range(0, 25));
            if (target != null)
            {
                targetPoint = target.transform.position;
            }
            break;

        case SpaceObjectTrajectoryType.TargetOpposite:
            // Set target to the opposite of the screen, multispawns will move parallel
            targetPoint = Screen.GetScreenEdge(transform.position, transform.up);
            break;

        case SpaceObjectTrajectoryType.TargetOppositeX:
            targetPoint    = transform.position;
            targetPoint.x *= -1f;
            break;

        case SpaceObjectTrajectoryType.TargetOppositeY:
            targetPoint    = transform.position;
            targetPoint.y *= -1f;
            break;

        case SpaceObjectTrajectoryType.TargetZero:
            targetPoint = Vector3.zero;
            break;
        }

        GameObject newObject = Instantiate(prefab) as GameObject;
        Movement   movement  = newObject.GetComponent <Movement> ();

        if (movement)
        {
            movement.SetTarget(targetPoint);
        }

        targetPoint          -= transform.position;
        transform.eulerAngles = new Vector3(0f, 0f, Mathf.Atan2(targetPoint.y, targetPoint.x) * Mathf.Rad2Deg + 270f);

        newObject.transform.parent   = transform.parent;
        newObject.transform.position = transform.position;
        newObject.transform.rotation = transform.rotation;

        transform.position = oldPosition;
    }
Exemplo n.º 24
0
 public void SetShipContainer(ShipContainer container)
 {
     this.shipContainer = container;
     base.transform.SetParent(container.transform);
     this.rigidbody2d = base.GetComponent <Rigidbody2D>();
 }
Exemplo n.º 25
0
 public void DestroyShip()
 {
     ShipContainer.RemoveSpaceShip(affectedShip.gameObject);
     Destroy(affectedShip.gameObject);
 }
Exemplo n.º 26
0
 public void AddContainer(string type, ShipContainer value)
 {
     m_Containers.Add(type, value);
 }