private void addShipToFleet(GameObject s) { _playerHangar.AddShipToFleet(s); addShipToFleetButton.SetActive(false); if (_playerHangar.GetFleet().Count == 3) { battleButton.SetActive(true); } else { battleButton.SetActive(false); } removeShipFromFleetButton.SetActive(true); removeShipFromFleetButton.GetComponent <Button>().onClick.AddListener(delegate() { removeShipFromFleet(s.gameObject); }); PersistantDataManager.Instance.SetPlayerHangar(_playerHangar); }
void Start() { canvas = FindObjectOfType <Canvas>(); HealthBarPrefab = Resources.Load("Prefabs/HealthBar") as GameObject; SCM = new SceneManagement(); scene = FindObjectOfType <SuperScene>(); computer = FindObjectOfType <EnemyAi>(); scene.LoadComputerShips(); scene.LoadPlayerShips(); this.playerHangar = PersistantDataManager.Instance.GetPlayerHangar(); makeHealthBars(); playerFleet = playerHangar.GetFleet(); computerFleet = computer.hangar.GetFleet(); DBM.createStateSelectionUIElement(); for (int i = 0; i < playerFleet.Count; i++) { print("creating target buttons and state buttons for " + playerFleet.ElementAt(i).Value.name); DBM.createTargetButton(playerFleet.ElementAt(i).Value); playerFleet.ElementAt(i).Value.GetComponent <Ship>().Init(); } for (int i = 0; i < computerFleet.Count; i++) { print("creating target buttons for " + computerFleet.ElementAt(i).Value.name); DBM.createTargetButton(computerFleet.ElementAt(i).Value); computerFleet.ElementAt(i).Value.GetComponent <Ship>().Init(); } StartCoroutine(StartTurn()); }
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()); }