Exemplo n.º 1
0
        /// <summary>
        /// Gets dummy AI to attack a controller
        /// </summary>
        public ShipAttack RandomAttack(Controller controller)
        {
            // Checks if all cells has been searched, then return invalid
            if (!CheckAnyLeftCells(controller))
            {
                return(ShipAttack.Invalid);
            }

            while (true)
            {
                // Picks random coordinate
                RandomizePosition(controller);

                // Checking if coordinate is known
                if (!CheckCoordinateExist(controller))
                {
                    break;
                }
            }
            // Stores the coordinate
            SaveCoordinate(controller);

            // Attack cell and return the attack state
            aIAttackMessage = controller.DestoryShip(aIX, aIY);
            return(aIAttackMessage);
        }
Exemplo n.º 2
0
    void Awake()
    {
        //Only for debug purposes so i can start the main game scene without going on the menu before
        //Have to remove this try-catch model later, cannot not have a ShipSelector Instance
        try{
            shipSelectorController = GameObject.FindGameObjectWithTag("ShipSelectorController").GetComponent <ShipSelectorController>();
        }catch (Exception e) {
            Debug.Log("Missing ship selector object \n" + e.Message);
        }
        //SetDefaultBulletTypeSprite();
        SetBulletTypeImagesByIndex(this.shipSelectorController.currentShipTypeIndex);

        playerShip          = GameObject.FindGameObjectWithTag("Ship");
        shipAttackHandler   = playerShip.GetComponent <ShipAttack>();
        shipMovementHandler = playerShip.GetComponent <ShipMovement>();
        shipScoreController = GameObject.FindGameObjectWithTag("GameController").GetComponent <ScoreController>();
        weaponTypeTimeBar.SetActive(false);

        if (shipMovementHandler.shipHaveBoost)
        {
            boostBarPanel.SetActive(true);
        }
        else
        {
            boostBarPanel.SetActive(false);
        }
    }
Exemplo n.º 3
0
 void Awake()
 {
     shipAttackController = GetComponent <ShipAttack>();
     shipHealthManager    = GetComponent <ShipHealthManager>();
     gameController       = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>();
     scoreController      = GameObject.FindGameObjectWithTag("GameController").GetComponent <ScoreController>();
     hudController        = GameObject.FindGameObjectWithTag("HUD").GetComponent <HUDController>();
     soundController      = GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundController>();
 }
Exemplo n.º 4
0
        private ShipAttack Attack(ShipAttack shipAttack)
        {
            if (shipAttack != ShipAttack.Invalid)
            {
                round++;
            }

            return(shipAttack);
        }
Exemplo n.º 5
0
    public void OnTriggerEnter(Collider other)
    {
        base.OnTriggerEnter(other); // Trigger base function

        // Set target
        ShipAttack att = gameObject.GetComponentInParent <ShipAttack>();

        att.SetTarget(other.gameObject);
    }
Exemplo n.º 6
0
    public void SetShipTargetTest()
    {
        GameObject go     = new GameObject("Ship");
        ShipAttack attack = go.AddComponent <ShipAttack>();

        GameObject target = new GameObject("Target");

        attack.SetTarget(target);

        Assert.AreNotEqual(null, attack.target);
    }
Exemplo n.º 7
0
    public override void Awake()
    {
        base.Awake();
        shipMove = gameObject.GetSafeComponent<ShipMove>();
        shipAttack = gameObject.GetSafeComponent<ShipAttack>();
        shipBlueprint = gameObject.GetSafeComponent<ShipBlueprint>();

        componentCamera.enabled = false;
        //manual init to ensure correct intitialization order
        shipBlueprint.Init();
        shipMove.Init();
        shipAttack.Init();

        selectedComponents = new List<ShipComponent>();
    }
Exemplo n.º 8
0
 // Use this for initialization
 void Awake()
 {
     hydraInput = GameObject.FindGameObjectWithTag("HydraInput").GetComponent<SixenseInput>();
     shipMove = gameObject.GetComponent<ShipMove>();
     shipAttack = gameObject.GetComponent<ShipAttack>();
     playerInventory = gameObject.GetComponent<PlayerInventory>();
     switch (GOD.whatControllerAmIUsing)
     {
         case WhatControllerAmIUsing.KEYBOARD:
             hydraInput.enabled = false;
             break;
         case WhatControllerAmIUsing.MOUSE_KEYBOARD:
             hydraInput.enabled = false;
             break;
         case WhatControllerAmIUsing.HYDRA:
             hydraInput.enabled = true;
             break;
         default:
             break;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Gets smart AI to attack a controller
        /// </summary>
        public ShipAttack SmartAttack(Controller controller)
        {
            //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-//
            // AI algorithm for battleship game									//
            //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-//

            // Checks if all cells has been searched, then return invalid
            if (!CheckAnyLeftCells(controller))
            {
                return(ShipAttack.Invalid);
            }

            if (aIAttackMessage == ShipAttack.Sank)
            {
                aIRandomSearch       = true;
                aIShipDirectionFound = false;
            }

            while (true)
            {
                // Picks random coordinate
                if (aIRandomSearch == true)
                {
                    RandomizePosition(controller);
                }
                else
                {
                    // Trys to find the direction the ship is placed
                    if (aIShipDirectionFound == false)
                    {
                        // Picks between horizontal or vertical
                        int pick = random.Next(0, 2);
                        if (pick == 0)
                        {
                            int y = random.Next(0, 2);
                            if (y == 0)
                            {
                                y = -1;
                            }
                            if (y == 1)
                            {
                                y = 1;
                            }
                            aIShipLastDirection = y;

                            aIX = aIHitStartX;
                            aIY = aIHitStartY + y;

                            // Checks if coordinate is inside the map
                            if ((aIY < 0) || (aIY >= controller.Map.Height))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            int x = random.Next(0, 2);
                            if (x == 0)
                            {
                                x = -1;
                            }
                            if (x == 1)
                            {
                                x = 1;
                            }
                            aIShipLastDirection = x;

                            aIX = aIHitStartX + x;
                            aIY = aIHitStartY;

                            // Checks if coordinate is inside the map
                            if ((aIX < 0) || (aIX >= controller.Map.Width))
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (aIShipDirection == ShipDirection.Horizontal)
                        {
                            aIX = aIHitPreX + aIShipLastDirection;
                            aIY = aIHitPreY;

                            if ((aIX <= 0) || (aIX >= controller.Map.Width - 1) || (controller.Map.GetFieldValue(aIX, aIY) == (int)Field.Miss))
                            {
                                aIShipLastDirection = Toggle(aIShipLastDirection);
                                aIX = aIHitStartX + aIShipLastDirection;
                            }
                        }
                        else
                        {
                            aIX = aIHitPreX;
                            aIY = aIHitPreY + aIShipLastDirection;

                            if ((aIY <= 0) || (aIY >= controller.Map.Height - 1) || (controller.Map.GetFieldValue(aIX, aIY) == (int)Field.Miss))
                            {
                                aIShipLastDirection = Toggle(aIShipLastDirection);
                                aIY = aIHitStartY + aIShipLastDirection;
                            }
                        }
                    }
                }

                // Checking if coordinate is known
                if (!CheckCoordinateExist(controller))
                {
                    break;
                }
            }

            // Store the coordinate
            aIHitPreX = aIX;
            aIHitPreY = aIY;

            // When random search is disabled and there was discovered a ship cell
            if ((aIRandomSearch == false) && ((controller.Map.GetFieldValue(aIX, aIY) != (int)Field.Water)))
            {
                // Here is the ship direction determined when there is still not found a direction
                if (aIShipDirectionFound == false)
                {
                    // Checks if the previews x cell is not at the starting ship coordinate then it's pointing horizontal else it must be pointing vertical
                    if (aIHitPreX != aIHitStartX)
                    {
                        aIShipDirection = ShipDirection.Horizontal;
                    }
                    else
                    {
                        aIShipDirection = ShipDirection.Vertical;
                    }

                    aIShipDirectionFound = true;
                }
            }

            // When seaching randomly and there was discovered a ship cell, then disable random search and store the coordinate as start
            if ((aIRandomSearch == true) && (controller.Map.GetFieldValue(aIX, aIY) != (int)Field.Water))
            {
                aIHitStartX    = aIX;
                aIHitStartY    = aIY;
                aIRandomSearch = false;
            }

            // Stores the coordinate
            SaveCoordinate(controller);

            // Attack cell and return the attack state
            aIAttackMessage = controller.DestoryShip(aIX, aIY);
            return(aIAttackMessage);
        }