public IEnumerator ShowMenu_DoesNotShowMenu() { //Test if ShowMenu doesn't show the menu when the TurnState is not Move1 or the currentPlayer is not human. Setup(); yield return(null); Game.TurnState[] incorrectTurnStates = new Game.TurnState[] { Game.TurnState.Move2, Game.TurnState.EndOfTurn, Game.TurnState.NULL }; foreach (Game.TurnState turnState in incorrectTurnStates) { game.SetTurnState(turnState); //Change the turnState cardDeck.ShowMenu(); // Try to show the menu //Test that the menu remains hidden. Assert.IsFalse(cardDeck.menu.activeInHierarchy); Assert.IsTrue(map.gameObject.activeInHierarchy); } game.SetTurnState(Game.TurnState.Move1); //Reset the turnState game.currentPlayer.SetHuman(false); //Make current player nonHuman. cardDeck.ShowMenu(); // Try to show the menu //Test that the menu remains hidden. Assert.IsFalse(cardDeck.menu.activeInHierarchy); Assert.IsTrue(map.gameObject.activeInHierarchy); }
/** * makeMove(turnState): * this method is used by the non-human players to allow them to make a move during the turn state, "turnState". * If the turnState == Move1 or Move2, then the method will decide which unit is the best to move, and execute it. * * ADDITION: 01/02/18 */ public void makeMove(Game.TurnState turnState) { if (turnState == Game.TurnState.Move1 || turnState == Game.TurnState.Move2) { Sector moveFrom = null; Sector moveTo = null; int bestMoveScore = -1; foreach (Unit unit in this.units) { KeyValuePair <Sector, int> unitsBestMove = this.findBestMove(unit, unit.GetSector().GetAdjacentSectors()); if (unitsBestMove.Value > bestMoveScore || (unitsBestMove.Value == bestMoveScore && Random.Range(1, 10) <= 5)) //ADDITION: 13/02/18 added random element to AI { bestMoveScore = unitsBestMove.Value; moveFrom = unit.GetSector(); moveTo = unitsBestMove.Key; } } if (moveTo == null || moveFrom == null) { throw new System.Exception("No valid moves found for AI " + this.name); } //Debug.Log ("==========================Start=========================="); //Debug.Log (this.name + "\nTurnState:" + turnState); moveFrom.OnMouseUpAsButtonAccessible(); //Debug.Log ("Selected " + moveFrom.name.ToString()); moveTo.OnMouseUpAsButtonAccessible(); //Debug.Log ("Made move from " + moveFrom.name + " to " + moveTo.name.ToString()); //Debug.Log ("===========================End==========================="); } }
/// <summary> /// Fetches all data when called and assigns to properties /// </summary> /// <param name="game">The game to save</param> public void SetupGameData(Game game) { // Game properties this.turnState = game.GetTurnState(); this.gameFinished = game.IsFinished(); this.testMode = game.GetTestMode(); this.currentPlayerID = game.GetPlayerID(game.GetCurrentPlayer()); // Player properties Player[] players = game.GetPlayers(); // Attack this.player1Attack = players[0].GetAttack(); this.player2Attack = players[1].GetAttack(); this.player3Attack = players[2].GetAttack(); this.player4Attack = players[3].GetAttack(); // Defence this.player1Defence = players[0].GetDefence(); this.player2Defence = players[1].GetDefence(); this.player3Defence = players[2].GetDefence(); this.player4Defence = players[3].GetDefence(); // Color this.player1Color = players[0].GetColor(); this.player2Color = players[1].GetColor(); this.player3Color = players[2].GetColor(); this.player4Color = players[3].GetColor(); // Controller (Human, Neutral or None) this.player1Controller = players[0].GetController(); this.player2Controller = players[1].GetController(); this.player3Controller = players[2].GetController(); this.player4Controller = players[3].GetController(); // Sectors Sector[] sectors = game.GetSectors(); // Owner this.sector01Owner = game.GetPlayerID(sectors[0].GetOwner()); this.sector02Owner = game.GetPlayerID(sectors[1].GetOwner()); this.sector03Owner = game.GetPlayerID(sectors[2].GetOwner()); this.sector04Owner = game.GetPlayerID(sectors[3].GetOwner()); this.sector05Owner = game.GetPlayerID(sectors[4].GetOwner()); this.sector06Owner = game.GetPlayerID(sectors[5].GetOwner()); this.sector07Owner = game.GetPlayerID(sectors[6].GetOwner()); this.sector08Owner = game.GetPlayerID(sectors[7].GetOwner()); this.sector09Owner = game.GetPlayerID(sectors[8].GetOwner()); this.sector10Owner = game.GetPlayerID(sectors[9].GetOwner()); this.sector11Owner = game.GetPlayerID(sectors[10].GetOwner()); this.sector12Owner = game.GetPlayerID(sectors[11].GetOwner()); this.sector13Owner = game.GetPlayerID(sectors[12].GetOwner()); this.sector14Owner = game.GetPlayerID(sectors[13].GetOwner()); this.sector15Owner = game.GetPlayerID(sectors[14].GetOwner()); this.sector16Owner = game.GetPlayerID(sectors[15].GetOwner()); this.sector17Owner = game.GetPlayerID(sectors[16].GetOwner()); this.sector18Owner = game.GetPlayerID(sectors[17].GetOwner()); this.sector19Owner = game.GetPlayerID(sectors[18].GetOwner()); this.sector20Owner = game.GetPlayerID(sectors[19].GetOwner()); this.sector21Owner = game.GetPlayerID(sectors[20].GetOwner()); this.sector22Owner = game.GetPlayerID(sectors[21].GetOwner()); this.sector23Owner = game.GetPlayerID(sectors[22].GetOwner()); this.sector24Owner = game.GetPlayerID(sectors[23].GetOwner()); this.sector25Owner = game.GetPlayerID(sectors[24].GetOwner()); this.sector26Owner = game.GetPlayerID(sectors[25].GetOwner()); this.sector27Owner = game.GetPlayerID(sectors[26].GetOwner()); this.sector28Owner = game.GetPlayerID(sectors[27].GetOwner()); this.sector29Owner = game.GetPlayerID(sectors[28].GetOwner()); this.sector30Owner = game.GetPlayerID(sectors[29].GetOwner()); this.sector31Owner = game.GetPlayerID(sectors[30].GetOwner()); this.sector32Owner = game.GetPlayerID(sectors[31].GetOwner()); // Level this.sector01Level = sectors[0].GetLevel(); this.sector02Level = sectors[1].GetLevel(); this.sector03Level = sectors[2].GetLevel(); this.sector04Level = sectors[3].GetLevel(); this.sector05Level = sectors[4].GetLevel(); this.sector06Level = sectors[5].GetLevel(); this.sector07Level = sectors[6].GetLevel(); this.sector08Level = sectors[7].GetLevel(); this.sector09Level = sectors[8].GetLevel(); this.sector10Level = sectors[9].GetLevel(); this.sector11Level = sectors[10].GetLevel(); this.sector12Level = sectors[11].GetLevel(); this.sector13Level = sectors[12].GetLevel(); this.sector14Level = sectors[13].GetLevel(); this.sector15Level = sectors[14].GetLevel(); this.sector16Level = sectors[15].GetLevel(); this.sector17Level = sectors[16].GetLevel(); this.sector18Level = sectors[17].GetLevel(); this.sector19Level = sectors[18].GetLevel(); this.sector20Level = sectors[19].GetLevel(); this.sector21Level = sectors[20].GetLevel(); this.sector22Level = sectors[21].GetLevel(); this.sector23Level = sectors[22].GetLevel(); this.sector24Level = sectors[23].GetLevel(); this.sector25Level = sectors[24].GetLevel(); this.sector26Level = sectors[25].GetLevel(); this.sector27Level = sectors[26].GetLevel(); this.sector28Level = sectors[27].GetLevel(); this.sector29Level = sectors[28].GetLevel(); this.sector30Level = sectors[29].GetLevel(); this.sector31Level = sectors[30].GetLevel(); this.sector32Level = sectors[31].GetLevel(); // Vice Chancelor this.VCSector = game.GetVCSectorID(); }