示例#1
0
    // Drives the current behavior based on what phase of the game is taking place.
    void ManageTurn()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        switch (gP)
        {
        case (GamePhase.Deploy):
            DeployMaster.SetTiles();     // let users set units
            break;

        case (GamePhase.Cannon):
            CannonMaster.HandleCannons();     // let users turn and fire cannons
            break;

        case (GamePhase.Move):
            MoveMaster.DecideMove();     // let users move available units
            break;

        case (GamePhase.Attack):     // Attack phase currently resolves itself with no need for user input
            break;

        default:
            break;
        }
    }
示例#2
0
 // disables cannon usability if another cannon kills the controling units
 static void DeactivateCannonByCannon(Player p)
 {
     foreach (Cannon c in p.Can)
     {
         if (c.Manned && !c.Moved)
         {
             CannonMaster.SetCannon(c);
         }
     }
 }
示例#3
0
 // enable cannon is a legal conditions met when a unit moves near it
 static void ActivateCannonByMove(Player p)
 {
     foreach (Cannon c in p.Can)
     {
         if (!c.manned)
         {
             CannonMaster.SetCannon(c);
         }
     }
 }
示例#4
0
 public void ResetMovable()
 {
     foreach (Unit u in Inf)
     {
         u.Moved = false;
     }
     foreach (Unit u in Cav)
     {
         u.Moved = false;
     }
     foreach (Cannon c in Can)
     {
         CannonMaster.SetCannon(c);
     }
 }
示例#5
0
    //initialize
    void Start()
    {
        instance = this;
        // canSkip = false;
        uiM = new UIMaster();
        sM  = new ScoreMaster();
        mM  = new MapMaster();
        pM  = new PlayerMaster();
        dM  = new DeployMaster();
        mvM = new MoveMaster();
        aM  = new AttackMaster();

        acceptInput = true;
        turnNum     = 0;

        CannonMaster.ResetCurrent();

        gP = GamePhase.Deploy;
        ScoreMaster.ResetScore();

        mL = new MapLoader();
        mL.LoadMapFromTextAsset(((TextAsset)Resources.Load("Maps/" + mapName)));
        PlayerMaster.SetBackLines(MapMaster.Map);
        TopDownCamera.ActivateMainCamera(MapMaster.Height, MapMaster.Width, MapMaster.MapRadius);

        UIMaster.SetGeneralUI();
        UIMaster.SetDeployUI();
        UIMaster.SetCannonUI();
        UIMaster.DisplayScore();

        UIMaster.SetPanelAlpha(false, (int)UIPannels.Cannon);
        UIMaster.SetPanelAlpha(false, (int)UIPannels.Phase);
        UIMaster.SetPanelAlpha(false, (int)UIPannels.View);
        UIMaster.SetPanelAlpha(false, (int)UIPannels.Fight);

        UIMaster.SetActionPanel(true);

        if (!tutorial)
        {
            UIMaster.DisplayState(gP, PlayerMaster.CurrentTurn);
        }

        // norton = VS_AI ? new AIBrain() : null; // must be called after UIMaster.SetGeneralUI to percive turns properly
    }
示例#6
0
    public static void SetCannonUI()
    {
        EventTrigger t = instance.cannonArrows[0].GetComponent <EventTrigger>();

        AddEventTriggerListener(t, EventTriggerType.PointerDown, delegate { CannonMaster.CurrentUp(); });
        AddEventTriggerListener(t, EventTriggerType.PointerUp, delegate { CannonMaster.CurrentUp(); });
        t = instance.cannonArrows[1].GetComponent <EventTrigger>();
        AddEventTriggerListener(t, EventTriggerType.PointerDown, delegate { CannonMaster.CurrentRight(); });
        AddEventTriggerListener(t, EventTriggerType.PointerUp, delegate { CannonMaster.CurrentRight(); });
        t = instance.cannonArrows[2].GetComponent <EventTrigger>();
        AddEventTriggerListener(t, EventTriggerType.PointerDown, delegate { CannonMaster.CurrentDown(); });
        AddEventTriggerListener(t, EventTriggerType.PointerUp, delegate { CannonMaster.CurrentDown(); });
        t = instance.cannonArrows[3].GetComponent <EventTrigger>();
        AddEventTriggerListener(t, EventTriggerType.PointerDown, delegate { CannonMaster.CurrentLeft(); });
        AddEventTriggerListener(t, EventTriggerType.PointerUp, delegate { CannonMaster.CurrentLeft(); });

        instance.cannonArrows[4].onClick.AddListener(CannonMaster.CurrentUpPower);
        instance.cannonArrows[5].onClick.AddListener(CannonMaster.CurrentDownPower);
        instance.fireButton.onClick.AddListener(CannonMaster.CurrentFire);
        instance.exitCannon.onClick.AddListener(CannonMaster.ExitCannon);
        instance.exitView.onClick.AddListener(ViewMaster.ExitView);
    }
示例#7
0
 private static void ScanForCannon()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0) /*&& Events.GetComponent<Pause>().paused == false*/)
     {
         Ray        ray;
         RaycastHit hit;
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit))
         {
             Cannon c = hit.transform.gameObject.GetComponent <Cannon>();
             if (c != null)
             {
                 if (c.player == PlayerMaster.CurrentTurn && !c.Moved && c.shots != 0)
                 {
                     currentCannon = hit.transform.GetComponentInChildren <CannonControll>();
                     CurrentPowerShow();
                     currentCannon.Selected = true;
                     currentCannon.StartCoroutine(CannonMaster.MoveToCannon());
                 }
             }
         }
     }
 }
示例#8
0
    static IEnumerator Fight() //Handles and manages the FightScene
    {
        gP = GamePhase.Attack;

        while (AttackMaster.CombatCount != 0)
        {
            float rotation;
            if (PlayerMaster.CurrentTurn == 0)
            {
                rotation = 180;
            }
            else
            {
                rotation = 0;
            }

            instance.StartCoroutine(TopDownCamera.LerpToPosition(AttackMaster.CenterOfCombat(), Quaternion.Euler(90, rotation, 0)));
            yield return(new WaitForSeconds(2.0f));               //Wait to give the player a chance to see stuff

            instance.StartCoroutine(UIMaster.MoveCurtains(true)); //lower curtains
            yield return(null);                                   //Wait at least one frame so that UIMaster.MovingCurtians can change value

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            List <Unit> currentCombat = AttackMaster.CurrentCombatArea;
            List <Unit> toKill        = AttackMaster.FightResults();
            FightSceneMaster.SetUpFight(currentCombat, toKill);    //Prepare the fightscene

            yield return(new WaitForSeconds(1.0f));                //Pause for dramatic effect

            instance.StartCoroutine(UIMaster.MoveCurtains(false)); //Raise Curtains
            yield return(null);

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            SoundMaster.AttackCharge();
            instance.StartCoroutine(FightSceneMaster.ToBattle()); //Begins FightScene
            yield return(null);                                   //Wait at least one frame so that FightSceneMaster.Fighting can change value

            while (FightSceneMaster.Fighting)
            {
                yield return(null);
            }

            //SoundMaster.AttackResolution();
            instance.StartCoroutine(UIMaster.MoveCurtains(true)); //Lower curtains again
            yield return(null);                                   //Wait at least one frame so that UIMaster.MovingCurtians can change value

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            FightSceneMaster.CleanUp();                            //Resets FightScene

            yield return(new WaitForSeconds(0.25f));               //Pause

            instance.StartCoroutine(UIMaster.MoveCurtains(false)); //Raise curtains
            yield return(new WaitForFixedUpdate());                //Wait at least one frame so that UIMaster.MovingCurtians can change value

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            yield return(new WaitForSeconds(1.0f));

            foreach (Unit u in toKill)
            {
                PlayerMaster.KillUnit(u);           //Kills dead units
            }
            yield return(new WaitForSeconds(1.0f)); //Pause to see aftermath
        }

        //return to player's position after the fight
        instance.StartCoroutine(TopDownCamera.LerpToPosition(PlayerMaster.CurrentPlayer.CameraPosistion, PlayerMaster.CurrentPlayer.CameraRotation));

        DeactivateCannonByMove(PlayerMaster.OtherPlayer);

        if (PlayerMaster.CurrentTurn == 0)
        {
            HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer);
        }

        UIMaster.DisplayScore();

        // WinByMove();

        UIMaster.SetActionPanel(true); //Turns action pannel back on
        UIMaster.FadePhanel((int)UIPannels.Action);

        CannonMaster.CheckCannonCapture();

        gP = GamePhase.Move;
        yield return(ChangeTurn());

        acceptInput = true;
    }
示例#9
0
    //Alters aspects of the game state (such as highlights or unit numbers) based on phase and other information
    private static IEnumerator AlterState()
    {
        switch (gP)
        {
        case (GamePhase.Deploy):

            if (DeployMaster.instance.uoList.Count != 0)
            {
                yield return(DeployMaster.DeployUnitsCoroutine());

                yield return(new WaitForSeconds(1.5f));
            }
            UIMaster.UpdateDeployAmount();
            break;

        case (GamePhase.Cannon):
            // CheckSkip();

            /*      if (PlayerMaster.CurrentTurn == 0)
             *    {
             *        CheckSkip();
             *    } */

            CannonMaster.ExitCannon();
            HighlightMaster.UnhighlightCannons(PlayerMaster.CurrentPlayer);
            DeactivateCannonByCannon(PlayerMaster.OtherPlayer);

            if (PlayerMaster.CurrentTurn == 0)
            {
                //DeactivateCannonByMove(PlayerMaster.OtherPlayer);
                HighlightMaster.HighlightActiveCannons(PlayerMaster.OtherPlayer);
            }
            break;

        case (GamePhase.Move):

            if (MoveMaster.UnitsToMove != 0)
            {
                HighlightMaster.UnhighlightMovable(PlayerMaster.CurrentPlayer);
                MoveMaster.ClearMoveVariables();
            }
            AttackMaster.BuildCombatAreas();

            ActivateCannonByMove(PlayerMaster.CurrentPlayer);
            DeactivateCannonByMove(PlayerMaster.CurrentPlayer);

            if (AttackMaster.CombatCount == 0)
            {
                CannonMaster.CheckCannonCapture();
                yield return(WinByMove());

                if (PlayerMaster.CurrentTurn == 0)
                {
                    MoveMaster.PrimeMoveVariables(PlayerMaster.OtherPlayer);
                    HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer);
                }
            }

            else if (AttackMaster.CombatCount != 0)
            {
                //  AttackMaster.BuildCombatAreas();
                //gP = GamePhase.Attack;

                UIMaster.SetActionPanel(false);     //Deactivates off action panel
                UIMaster.FadePhanel((int)UIPannels.Action);
                acceptInput = false;

                instance.StartCoroutine(Fight());
                //yield return Fight();
            }
            break;

        case (GamePhase.Attack):
            break;

        default:
            yield return(null);

            break;
        }
    }
示例#10
0
    void Update()
    {
        Debug.Log(PlayerMaster.PriorTurn);

        if (acceptInput)
        {
            switch (phase)
            {
            case T_Phases.Deploy:
                DeployMaster.SetTutorialTiles();
                if (d_markers.transform.childCount == 0)
                {
                    turn_button.interactable = true;
                }
                if (PlayerMaster.CurrentTurn == 1)
                {
                    acceptInput = false;
                    ai_turn     = true;
                    instance.StartCoroutine(TutorialAI.Deploy());
                }
                break;

            case T_Phases.Move:
                MoveMaster.DecideMove();
                if (PlayerMaster.CurrentTurn == 1)
                {
                    acceptInput = false;
                    ai_turn     = true;
                    instance.StartCoroutine(TutorialAI.Move());
                }
                break;

            case T_Phases.Cannon:
                CannonMaster.HandleCannons();
                if (PlayerMaster.CurrentTurn == 1)
                {
                    acceptInput = false;
                    ai_turn     = true;
                    instance.StartCoroutine(TutorialAI.IDontHaveCannons());
                }
                break;

            case T_Phases.Fight:
                MoveMaster.DecideMove();
                if (PlayerMaster.CurrentTurn == 1)
                {
                    acceptInput = false;
                    ai_turn     = true;
                    instance.StartCoroutine(TutorialAI.Move());
                }
                break;

            default:
                Debug.Log("Default");
                break;
            }
        }

        if (ai_turn)
        {
            if (PlayerMaster.CurrentTurn == 0)
            {
                ai_turn = false;
                TutorialUIMaster.c_bool = false;
                TutorialUIMaster.SetContinue(false);
                NextPhase();
                instance.StartCoroutine(TutorialUIMaster.MoveTextbox());
            }
        }
    }
示例#11
0
    IEnumerator HandleCannons(Cannon can)
    {
        Debug.Log("handling " + can.gameObject.name);
        CannonMaster.SetAICannon(can);
        canc  = can.transform.GetChild(0).transform.GetChild(0).GetComponent <CannonControll>();
        aimAt = CenterOfCluster(); //asigns aimAt as the center of the cluster
        cube.transform.position = aimAt;
        Vector3 dir = aimAt - can.transform.position;

        angle = Vector3.SignedAngle(dir, can.transform.GetChild(0).transform.forward, Vector3.up); //math to figure out the difference between the target's position and where the cannon is currently looking

        if (angle > 0)
        {
            while (angle > 2.0f)
            {
                //moves cannon left until it is lined up with target
                canc.lefts();
                angle = Vector3.SignedAngle(dir, can.transform.GetChild(0).transform.forward, Vector3.up);
                yield return(null);
            }
        }
        else
        {
            while (angle < -2.0f)
            {
                //moves cannon right until it is lined up with target
                canc.rights();
                angle = Vector3.SignedAngle(dir, can.transform.GetChild(0).transform.forward, Vector3.up);
                yield return(null);
            }
        }
        for (int i = 17; i >= 0; --i)
        {
            //Moves cannon's aim downward so that later we only have to move it up to line up shots
            canc.downs();
            yield return(null);
        }
        for (int i = 30; i >= 0; --i)
        {
            //Sets cannon at max power to more easily line up shots. Will more than likely be changed later to make lob shots possible
            canc.Powerup();
            yield return(null);
        }
        RaycastHit ray;
        int        num = canc.RayCastEnemies(out ray); //function created in CannonControl. Checks if a unit is within the current cannon's path

        RaycastHit hit;

        Physics.Raycast(new Ray(cube.gameObject.transform.position + Vector3.up, Vector3.down), out hit, 2.0f, 1 << 8);

        if (hit.transform != null)
        {
            Debug.Log(hit.transform);
            if (hit.transform.gameObject.GetComponent <HexCell>() != null)
            {
                GeneticCannon.goal = hit.transform.gameObject.GetComponent <HexCell>();
                Debug.Log(GeneticCannon.goal.ToString());
                yield return(GeneticCannon.SolveCannon());
            }
            else
            {
                GeneticCannon.goal = currentCluster[0].CurrentHex;
            }
        }

        while (num != -1)
        {
            //Move aim up until a unit is found
            //Needs to be modified to confirm the current target and avoid allies
            canc.ups();
            num = canc.RayCastEnemies(out ray);
            yield return(null);
        }

        canc.firecannon();


        //StartCoroutine(AimAndShoot(can));

        while (!combat.checkUnits)
        {
            yield return(null);
        }
        //Check units becomes true when a unit has been touched by a cannonball and becomes false once all "dead" units are removed from play
        while (combat.checkUnits)
        {
            yield return(null);
        }

        //if (inRangeTargets[target] == null)
        // ++target; //If target is dead, move to the next one
        //need proper target reprioritizing

        if (can.shots != 0) //if there is ammo left in the cannon, shoot again with the same cannon
        {
            inRangeTargets.Clear();
            currentCluster.Clear();
            biggestCluster.Clear();
            //yield return new WaitForSeconds(10f);
            FindTargets(can);
        }
        else
        {
            while (currentCannon < PlayerMaster.CurrentPlayer.Can.Count && PlayerMaster.CurrentPlayer.Can[currentCannon].shots == 0) //Moves through cannons until we are out of available cannons or we find one with enough shots
            {
                ++currentCannon;
            }

            if (currentCannon < PlayerMaster.CurrentPlayer.Can.Count && PlayerMaster.OtherPlayer.Inf.Count > 0) //If we found a cannon that can be shot
            {
                //yield return new WaitForSeconds(10f);
                inRangeTargets.Clear();
                currentCluster.Clear();
                biggestCluster.Clear();
                FindTargets(PlayerMaster.CurrentPlayer.Can[currentCannon]); //Find the targets within it's range and continue from there
            }
            else
            {
                Debug.Log("Out of cannons");
                StartCoroutine(CannonMaster.LeaveCannon()); //If we are out of cannons then zoom back out
                GameBrain.ChangeTurn();
            }
        }
    }
示例#12
0
 public static void SetAICannon(Cannon can)
 {
     currentCannon          = can.GetComponentInChildren <CannonControll>();
     currentCannon.Selected = true;
     currentCannon.StartCoroutine(CannonMaster.MoveToCannon());
 }