// Use this for initialization void Start() { //scripts m_EndSceneDataScript = this.GetComponent <GSP.EndSceneData>(); m_MiscScript = this.GetComponent <GSP.Misc>(); ScaleValues(); m_EndSceneCharDataObject = m_EndSceneDataScript.GetData(m_MiscScript.DetermineWinner()); m_headerString = ""; m_headerString = "Player " + (m_EndSceneCharDataObject.PlayerNumber).ToString() + " is the Winner!\n" + "Player " + (m_EndSceneCharDataObject.PlayerNumber).ToString() + " collected " + (m_EndSceneCharDataObject.PlayerCurrency).ToString() + " Gold."; List <KeyValuePair <int, int> > playerList = m_MiscScript.GetList(); m_bodyString = ""; for (int i = 1; i <= (m_EndSceneDataScript.Count - 1); i++) { m_EndSceneCharDataObject = m_EndSceneDataScript.GetData(playerList[i].Key); m_bodyString = m_bodyString + "[" + (i + 1).ToString() + " Place] " + "Player " + (m_EndSceneCharDataObject.PlayerNumber).ToString() + " collected " + (m_EndSceneCharDataObject.PlayerCurrency).ToString() + " Gold.\n"; } m_isActionRunning = true; }
} //end void OnGUI() private void ScaleValues() { m_EndSceneDataScript = this.GetComponent <GSP.EndSceneData>(); m_mainWidth = Screen.width / 2; m_mainHeight = Screen.height / 1; m_mainStartX = (Screen.width / 2) - (m_mainWidth / 2); m_mainStartY = (Screen.height / 2) - ((m_mainHeight / 2)); //65 is just below the main GUI, and I added a gap of 32 from the end of that m_sectionsInY = 7; } //end private void ScaleValues()
} // end Update function // Determine who is the winner and fill in the sorted list. public int DetermineWinner() { // Get the game object with the end scene data tag. GameObject endSceneDataObject = GameObject.FindGameObjectWithTag("EndSceneDataTag"); // Get its script. EndSceneData endSceneScript = endSceneDataObject.GetComponent <EndSceneData>(); // Get the number of players. int numPlayers = endSceneScript.Count; // Loop over the data in the end scene data script. for (int index = 0; index < numPlayers; index++) { // Increase index by one to get the player number. int playerNum = index + 1; // Only proceed if the player's currency hasn't been added. if (!m_currencyDict.ContainsKey(playerNum)) { // Get the player's char data. EndSceneCharData endScenechardata = endSceneScript.GetData(playerNum); // Add the player's number as the key and its currency as the value to the dictionary. m_currencyDict.Add(playerNum, endScenechardata.PlayerCurrency); } // end if statement } // end for loop // Now we sort the currency dictionary. IEnumerable <KeyValuePair <int, int> > sortedCurrency = from entry in m_currencyDict orderby entry.Value descending select entry; // Create a list from this ordering. currencyList = sortedCurrency.ToList(); // Now get and return the player at the front of the list as the winner. // This only happens because it was sorted to have the highest at the top. return(currencyList[0].Key); } // end DetermineWinner function
private void StateMachine() //--------------------------------------------------------------------- // +StateMachine in charge of displaying GUI that describes // what stage the gamePlay is in // +Uses a switch() statement for handling states // //--------------------------------------------------------------------- { var state = GameObject.FindGameObjectWithTag("GUITextTag").GetComponent <GUIText>(); switch (m_gamePlayState) { case GamePlayState.BEGINTURN: //Get All the Players values GetPlayerValues(); m_GUIBottomBarScript.RefreshBottomBarGUI(m_playerList[m_GUIPlayerTurn]); //tell the player to roll the dice m_gamePlayState = GamePlayState.ROLLDICE; break; case GamePlayState.ROLLDICE: //list start at 0 but I need GUI to start Display with player "1" int tmpPlayerTurn = m_GUIPlayerTurn + 1; state.text = "Player " + tmpPlayerTurn.ToString() + " roll dice"; //create a roll dice button m_GUIActionString = "Action\nRoll Dice"; //highlight button m_colorActionButtonDefault = false; //if button is clicked, destroy button if (m_GUIActionPressed) { //stop animation m_colorActionButtonDefault = true; m_GUIDiceDistVal = m_DieScript.Dice.Roll(1, 8); //Play die roll sound audioSrc.audio.PlayOneShot(GSP.AudioReference.sfxDice); //Play die roll sound //nextState() m_gamePlayState = GamePlayState.CALCDISTANCE; } break; // case GamePlayState.CALCDISTANCE: state.text = "Calculate Distance"; //get dice value /calculate m_allowedTravelDistance m_GUIDiceDistVal = m_GUIDiceDistVal * (m_GUIMaxWeight - m_GUIWeight) / m_GUIMaxWeight; //nextState() m_GUIActionPressed = false; m_gamePlayState = GamePlayState.DISPLAYDISTANCE; break; case GamePlayState.DISPLAYDISTANCE: state.text = "DisplayDistance"; //TODO: Add function to display tiles //nextState() m_gamePlayState = GamePlayState.SELECTPATHTOTAKE; //display arrows m_GUIMovementScript.InitThis(m_playerList[m_GUIPlayerTurn], m_GUIDiceDistVal); break; case GamePlayState.SELECTPATHTOTAKE: state.text = "Select Path To Take\nPress Action butotn to End Turn\nor X to start over."; m_GUIActionString = "End Turn"; //update new value of DiceDist if player pressed a move button m_GUIDiceDistVal = m_GUIMovementScript.GetTravelDistanceLeft(); //if ( Input.GetKeyDown( KeyCode.Alpha1 ) ) if (m_GUIActionPressed) { //find out what mapEvent Occured m_gamePlayState = GamePlayState.DOACTION; //TODO: REMOVE below line if test works. //m_NEWGUIMapEventScript.InitThis( m_playerList[m_GUIPlayerTurn] ); //update gui by getting new values //GetPlayerValues(); //TODO: after testing, delete command above and use this one below m_MapEventString = m_MapEventScript.DetermineEvent(m_playerList[m_GUIPlayerTurn]); m_MapEventResultString = m_MapEventScript.GetResultString(); m_GUIMapEventsScript.InitThis(m_playerList[m_GUIPlayerTurn], m_MapEventString, m_MapEventResultString); //m_GUIMapEventsScript.InitThis( m_playerList[m_GUIPlayerTurn], "ENEMY", null ); } break; case GamePlayState.DOACTION: //state.text = "Do Action/MapEvent"; state.text = ""; GetPlayerValues(); //map events if (m_GUIMapEventsScript.isActionRunning() == false) //TODO: remove bottome line if above line works //if( m_NEWGUIMapEventScript.GetIsActionRunning() == false ) { //TODO: After Testing, uncomment the following m_MapEventString = "NOTHING"; m_MapEventResultString = null; //NextState() m_gamePlayState = GamePlayState.ENDTURN; m_GUIActionPressed = false; } break; case GamePlayState.ENDTURN: state.text = "End Turn"; // Clear the board of any highlight tiles. Highlight.ClearHightlight(); //next players turn m_GUIPlayerTurn = m_GUIPlayerTurn + 1; //if exceeds the number of player playing, start back at player 1 if (m_GUIPlayerTurn >= m_GUINumOfPlayers) { m_GUIPlayerTurn = 0; } //new player gets new turn m_gamePlayState = GamePlayState.BEGINTURN; break; case GamePlayState.ENDGAME: state.text = "Universe Ending"; if (m_runEndStuff) { #region Selling Character resource stuff // Set it to not run this again. m_runEndStuff = false; // Get the number of players. int numPlayers = m_playerList.Count; // Loop through and sell the character's resources and their ally's resources. for (int playerSellIndex = 0; playerSellIndex < numPlayers; playerSellIndex++) { // We need to access the character script at the given index and sell the resources. m_playerScriptList[playerSellIndex].SellResource(); } // end for loop #endregion #region End Scene Quit Adding Stuff // Get the end scene data object's script. EndSceneData endSceneScript = m_endSceneCharData.GetComponent <EndSceneData>(); // Add the player stuff. for (int endSceneIndex = 0; endSceneIndex < numPlayers; endSceneIndex++) { // Add the current player to the end scene data object. // Note: Be sure to add 1 to index to get the player number correct. int playerNum = endSceneIndex + 1; // Check if the key doesn't exist. Only proceed if it doesn't. if (!endSceneScript.KeyExists(playerNum)) { // NOTE: Uncomment the below line for testing. Recomment it for the real game. //m_playerScriptList[endSceneIndex].Currency += m_DieScript.Dice.Roll(1, 100); endSceneScript.AddData(playerNum, m_playerList[endSceneIndex]); } // end if statement } // end for loop #endregion // Next load the end scene Application.LoadLevel("EndScene"); } break; default: //stage transition break; } //end switch (m_gamePlayState) } //end private void StateMachine()
// Update is called once per frame. void Update() { // Tests getting the player's info if (Input.GetKeyDown(KeyCode.A)) { // Get the game object with the end scene data tag. GameObject endSceneDataObject = GameObject.FindGameObjectWithTag("EndSceneDataTag"); // Get its script. EndSceneData endSceneScript = endSceneDataObject.GetComponent <EndSceneData>(); // Get the number of players. int numPlayers = endSceneScript.Count; // Loop over the data in the end scene data script. for (int index = 0; index < numPlayers; index++) { // Increase index by one to get the player number. int playerNum = index + 1; // Get the player's char data. EndSceneCharData endScenechardata = endSceneScript.GetData(playerNum); // Debug what's in the char data object. Debug.Log("Player Number: " + endScenechardata.PlayerNumber); Debug.Log("Player Name: " + endScenechardata.PlayerName); Debug.Log("Player Currency: " + endScenechardata.PlayerCurrency); } // end for loop } // end if statement // Tests checking to player's currency for a winner. if (Input.GetKeyDown(KeyCode.B)) { // Get the game object with the end scene data tag. GameObject endSceneDataObject = GameObject.FindGameObjectWithTag("EndSceneDataTag"); // Get its script. EndSceneData endSceneScript = endSceneDataObject.GetComponent <EndSceneData>(); // Get its misc script. Misc endSceneMisc = endSceneDataObject.GetComponent <Misc>(); // Get the winning player. int playerWinner = endSceneMisc.DetermineWinner(); // Show it on the console. Debug.Log("Player #" + playerWinner + " is the winner!"); // Get the winning players data. EndSceneCharData playerWinnerData = endSceneScript.GetData(playerWinner); // Show it on the console. Debug.Log(playerWinnerData.PlayerName + " has won with " + playerWinnerData.PlayerCurrency + " currency!"); } // end if statement // Tests checks for a winner and grabs the sorted list. Then loops over it. if (Input.GetKeyDown(KeyCode.C)) { // Get the game object with the end scene data tag. GameObject endSceneDataObject = GameObject.FindGameObjectWithTag("EndSceneDataTag"); // Get its script. EndSceneData endSceneScript = endSceneDataObject.GetComponent <EndSceneData>(); // Get its misc script. Misc endSceneMisc = endSceneDataObject.GetComponent <Misc>(); // Since we're getting the list, it doesn't matter if we assign the result to a variable here. endSceneMisc.DetermineWinner(); // Get the list. List <KeyValuePair <int, int> > playerList = endSceneMisc.GetList(); // Loop over the list. foreach (var pair in playerList) { // Get the player's data from the key in the pair. EndSceneCharData charData = endSceneScript.GetData(pair.Key); // Do stuff with it. Debug.Log("Player #" + charData.PlayerNumber + " has " + charData.PlayerCurrency + " currency!"); } // end foreach } // end if statement // Tests checks for a winner and grabs the sorted list. Uses it by index. if (Input.GetKeyDown(KeyCode.D)) { // Get the game object with the end scene data tag. GameObject endSceneDataObject = GameObject.FindGameObjectWithTag("EndSceneDataTag"); // Get its script. EndSceneData endSceneScript = endSceneDataObject.GetComponent <EndSceneData>(); // Get its misc script. Misc endSceneMisc = endSceneDataObject.GetComponent <Misc>(); // Since we're getting the list, it doesn't matter if we assign the result to a variable here. endSceneMisc.DetermineWinner(); // Get the list. List <KeyValuePair <int, int> > playerList = endSceneMisc.GetList(); // Do stuff with the list by index. // Get the char data for the 2nd place. EndSceneCharData charData = endSceneScript.GetData(playerList[1].Key); // Do something with it. Debug.Log("Player #" + charData.PlayerNumber + " has placed second with " + charData.PlayerCurrency + " currency!"); } // end if statement // Tests checks for a winner and grabs the sorted list. Uses it to grab the last player. if (Input.GetKeyDown(KeyCode.E)) { // Get the game object with the end scene data tag. GameObject endSceneDataObject = GameObject.FindGameObjectWithTag("EndSceneDataTag"); // Get its script. EndSceneData endSceneScript = endSceneDataObject.GetComponent <EndSceneData>(); // Get its misc script. Misc endSceneMisc = endSceneDataObject.GetComponent <Misc>(); // Since we're getting the list, it doesn't matter if we assign the result to a variable here. endSceneMisc.DetermineWinner(); // Get the list. List <KeyValuePair <int, int> > playerList = endSceneMisc.GetList(); // Get the number of players. int numPlayers = endSceneScript.Count; // Get the last player. Its index is the number of players minus one. int lastPlayerIndex = numPlayers - 1; // Get the char data for the last player. EndSceneCharData charData = endSceneScript.GetData(playerList[lastPlayerIndex].Key); // Do something with it. Debug.Log("Player #" + charData.PlayerNumber + " has placed last with " + charData.PlayerCurrency + " currency!"); } // end if statement } // end Update function