示例#1
0
    IEnumerator StartTurn()
    {
        //update fleet
        playerFleet   = playerHangar.GetFleet();
        computerFleet = computer.hangar.GetFleet();

        for (int i = 0; i < playerFleet.Count; i++)
        {
            //TODO: highlight ship for which player has to select action
            List <Ship> shiplist = playerHangar.GetShipList();
            Ship        ship     = shiplist[i];
            if (ship != null)
            {
                ship.state = Ship.State.neutral;


                DBM.deActivateStateButtons();
                text.text = "what would you like " + ship.name + " to do?";



                //add listeners to the butons to select what the ship should to this turn
                List <GameObject> shipStateButtonList = new List <GameObject>();


                shipStateButtonList = DBM.getStateButtons();

                shipStateButtonList[0].GetComponent <Button>().onClick.AddListener(delegate() { ship.setState(Ship.State.attack); });
                shipStateButtonList[1].GetComponent <Button>().onClick.AddListener(delegate() { ship.setState(Ship.State.defend); });

                if (ship is SupportClass)
                {
                    shipStateButtonList[2].GetComponent <Button>().onClick.AddListener(delegate() { ship.setState(Ship.State.heal); });
                }
                DBM.setStateSelectionPosition(ship.gameObject.transform.position);


                DBM.activateStateButtons(ship);
                //wait for state selection
                while (ship.state == Ship.State.neutral)
                {
                    yield return(null);
                }
                DBM.deActivateStateButtons();
                removeListeners();


                text.text = string.Empty;
                yield return(new WaitForSeconds(1));
            }
        }
        print("state selection for player complete");

        //let the computer choose its states for each ship
        computer.stateSelection(computer.hangar.GetShipList());



        //select targets now
        List <GameObject> Ships = new List <GameObject>();

        Ships.AddRange(checkAttack(playerHangar.GetFleet()));
        Ships.AddRange(checkAttack(computer.hangar.GetFleet()));
        Ships = Ships.OrderByDescending(ship => ship.GetComponent <Ship>().GetSpeed()).ToList();

        foreach (GameObject s in Ships)
        {
            Ship _ship      = s.GetComponent <Ship>();
            bool isComputer = false;
            if (_ship.Side == 2)
            {
                isComputer = true;
            }
            StartCoroutine(SelectTarget(_ship, isComputer, false));
            while (_ship.GetSelectedTargets().Count < 1)
            {
                yield return(null);
            }

            yield return(new WaitForSeconds(1));
        }
        print("Starting attacking phase");
        StartCoroutine(ExecuteAttacks());
    }