public void DeterminePlayerOrder(Player[] arrayOfPlayers, ref List <Player> ListOfPlayers) { // Note! // arrayOfPlayers is the order the players are sitting in around the board. // So the order is determined by starting at the player with the highest roll // and moving clockwise around the board Game1.debugMessageQueue.addMessageToQueue("Players rolling to determine Order"); int[] playerRolls = new int[arrayOfPlayers.Length]; // An array the size of the number of players to hold their dice rolls List <Player> tiedPlayers = new List <Player>(); // List of players that are tied for highest roll int currentHighestPlayer = 0; // Current player index in arrayOfPlayers with the highest roll // Have each player roll a pair of dice and store the result in the playerRolls array for (int i = 0; i < arrayOfPlayers.Length; i++) { SoshiLandGameFunctions.RollDice(arrayOfPlayers[i]); playerRolls[i] = SoshilandGame.currentDiceRoll; // If the current highest player's roll is less than the new player's roll // Replace that player with the new player with the highest roll if (playerRolls[currentHighestPlayer] < playerRolls[i] && i != currentHighestPlayer) { // Set the new Highest Player roll currentHighestPlayer = i; // Clear the list of tied players tiedPlayers.Clear(); } else if (playerRolls[currentHighestPlayer] == playerRolls[i] && i != currentHighestPlayer) { // Only add the current highest player if the list is empty // That player would've already been added to the list if (tiedPlayers.Count == 0) { tiedPlayers.Add(arrayOfPlayers[currentHighestPlayer]); } // Add the new player to the list of tied players tiedPlayers.Add(arrayOfPlayers[i]); } Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + arrayOfPlayers[currentHighestPlayer].getName + "\"" + " is the current highest roller with: " + playerRolls[currentHighestPlayer]); } // Initialize the list of players ListOfPlayers = new List <Player>(); // Check if there is a tie with highest rolls if (tiedPlayers.Count > 0) { Game1.debugMessageQueue.addMessageToQueue("There's a tie!"); // New list to store second round of tied players List <Player> secondRoundOfTied = new List <Player>(); // Keep rolling until no more tied players while (secondRoundOfTied.Count != 1) { int currentHighestRoll = 0; // Roll the dice for each player foreach (Player p in tiedPlayers) { SoshiLandGameFunctions.RollDice(p); // Roll the dice for the player // If the new roll is higher than the current highest roll if (SoshilandGame.currentDiceRoll > currentHighestRoll) { // Clear the list since everyone who may have been in the list is lower secondRoundOfTied.Clear(); // Set the new highest roll currentHighestRoll = SoshilandGame.currentDiceRoll; secondRoundOfTied.Add(p); } // If there's another tie, just add it to the new array without clearing it else if (SoshilandGame.currentDiceRoll == currentHighestRoll) { secondRoundOfTied.Add(p); } // Otherwise, the player rolled less and is removed } // If there are still tied players, transfer them into the old List and clear the new List if (secondRoundOfTied.Count > 1) { // Clear the players that did not roll high enough tiedPlayers.Clear(); foreach (Player p in secondRoundOfTied) { tiedPlayers.Add(p); } secondRoundOfTied.Clear(); } } // Should be one clear winner now ListOfPlayers.Add(secondRoundOfTied[0]); } if (ListOfPlayers.Count == 0) { ListOfPlayers.Add(arrayOfPlayers[currentHighestPlayer]); } int firstPlayer = 0; // Search for the first player in the player array while (arrayOfPlayers[firstPlayer] != ListOfPlayers[0]) { firstPlayer++; } // Populate the players in clockwise order for (int a = firstPlayer + 1; a < arrayOfPlayers.Length; a++) { ListOfPlayers.Add(arrayOfPlayers[a]); } if (firstPlayer != 0) { for (int b = 0; b < firstPlayer; b++) { ListOfPlayers.Add(arrayOfPlayers[b]); } } if (Game1.DEBUG) { Game1.debugMessageQueue.addMessageToQueue("Player Order Determined! "); for (int i = 1; i < ListOfPlayers.Count + 1; i++) { Game1.debugMessageQueue.addMessageToQueue(i + ": " + ListOfPlayers[i - 1].getName); } } }
public void PlayerInputUpdate() { KeyboardState kbInput = Keyboard.GetState(); switch (turnPhase) { // Pre Roll Phase case 0: // Check if player is in jail if (currentTurnsPlayers.inJail) { if (Game1.DEBUG && displayJailMessageOnce) { Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + currentTurnsPlayers.getName + "\"" + " is currently in jail"); Game1.debugMessageQueue.addMessageToQueue("Press T to pay $50 to get out of jail, or R to try and roll doubles"); displayJailMessageOnce = false; } // Player decides to roll for doubles if (kbInput.IsKeyDown(Keys.R) && previousKeyboardInput.IsKeyUp(Keys.R)) { // Roll Dice SoshiLandGameFunctions.RollDice(currentTurnsPlayers); // Only move if doubles were rolled or if player has been in jail for the third turn if (DoublesRolled || currentTurnsPlayers.turnsInJail == 2) { if (currentTurnsPlayers.turnsInJail == 2) { Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + currentTurnsPlayers.getName + "\"" + " must pay $50 to get out of jail on third turn."); currentTurnsPlayers.PlayerPaysBank(50); // Pay bank fine } currentTurnsPlayers.turnsInJail = 0; // Set turns in jail back to zero currentTurnsPlayers.inJail = false; // Set player out of jail Game1.debugMessageQueue.addMessageToQueue("Player is no longer in jail!"); SoshiLandGameFunctions.MovePlayerDiceRoll(currentTurnsPlayers, currentDiceRoll); // Move player piece turnPhase = 1; // Set the next phase PlayerOptions(currentTurnsPlayers); // Calculate options for player DoublesRolled = false; // Turn off doubles rolled flag because player is not supposed to take another turn after getting out of jail break; } else { Game1.debugMessageQueue.addMessageToQueue("You failed to roll doubles and stay in jail."); currentTurnsPlayers.turnsInJail++; turnPhase = 2; break; } } // If player chooses to pay to get out of jail if (kbInput.IsKeyDown(Keys.T) && previousKeyboardInput.IsKeyUp(Keys.T)) { Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + currentTurnsPlayers.getName + "\"" + " pays $50 to escape from Babysitting Kyungsan"); currentTurnsPlayers.PlayerPaysBank(50); // Pay bank fine currentTurnsPlayers.turnsInJail = 0; // Set turns in jail back to zero currentTurnsPlayers.inJail = false; // Set player to be out of Jail Game1.debugMessageQueue.addMessageToQueue("Player is no longer in jail!"); SoshiLandGameFunctions.RollDice(currentTurnsPlayers); // Rolls Dice and Move Piece to Tile turnPhase = 1; // Set next phase PlayerOptions(currentTurnsPlayers); // Calculate options for player break; } } else { // Roll Dice if (kbInput.IsKeyDown(Keys.R) && previousKeyboardInput.IsKeyUp(Keys.R)) { SoshiLandGameFunctions.RollDice(currentTurnsPlayers); // Rolls Dice and Move Piece to Tile turnPhase = 1; // Set next phase PlayerOptions(currentTurnsPlayers); // Calculate options for player } } break; // Roll Phase case 1: if (optionsCalculated) { // Player chooses to purchase property if (kbInput.IsKeyDown(Keys.P) && previousKeyboardInput.IsKeyUp(Keys.P)) { bool successfulPurchase = false; // Purchase Property if (optionPurchaseOrAuctionProperty) { successfulPurchase = currentTurnsPlayers.PurchaseProperty((PropertyTile)Tiles[currentTurnsPlayers.CurrentBoardPosition]); } // Purchase Utility else if (optionPurchaseOrAuctionUtility) { successfulPurchase = currentTurnsPlayers.PurchaseUtility((UtilityTile)Tiles[currentTurnsPlayers.CurrentBoardPosition]); } // Player cannot purchase right now else { Game1.debugMessageQueue.addMessageToQueue( "Player " + "\"" + currentTurnsPlayers.getName + "\"" + " cannot purchase \"" + Tiles[currentTurnsPlayers.CurrentBoardPosition].getName + "\""); } // Turn off option to purchase if successful purchase has been made if (successfulPurchase) { // Set flags for purchase/auction off optionPurchaseOrAuctionUtility = false; optionPurchaseOrAuctionProperty = false; // Set the next phase turnPhase = 2; } } // Player chooses to Auction if (optionPromptLuxuryTax) { bool successfulTaxPayment = false; // Player chooses to pay 10% (Luxury Tax) if (kbInput.IsKeyDown(Keys.K) && previousKeyboardInput.IsKeyUp(Keys.K) && !taxesMustPayTwoHundred) { successfulTaxPayment = SoshiLandGameFunctions.PayTenPercentWorthToBank(currentTurnsPlayers); // Pay 10% to bank if (successfulTaxPayment) { turnPhase = 2; optionPromptLuxuryTax = false; // Turn off the tax flag } else { taxesMustPayTenPercent = true; // Turn flag for paying 10% optionPromptMortgageOrTrade = true; // Player is forced to mortgage } } // Player chooses to pay $200 (Luxury Tax) else if (kbInput.IsKeyDown(Keys.L) && previousKeyboardInput.IsKeyUp(Keys.L) && !taxesMustPayTenPercent) { if (currentTurnsPlayers.getMoney >= 200) // Check if player has enough money { currentTurnsPlayers.PlayerPaysBank(200); // Pay $200 to bank optionPromptLuxuryTax = false; // Turn off the tax flag turnPhase = 2; // Go to next phase } else { taxesMustPayTwoHundred = true; // Turn flag on for paying $200 optionPromptMortgageOrTrade = true; // Player is forced to mortgage } } } // Player chooses to mortgage // Player chooses to trade } break; // Post Roll Phase case 2: // Player chooses to end turn if (kbInput.IsKeyDown(Keys.E) && previousKeyboardInput.IsKeyUp(Keys.E)) { // Check if doubles has been rolled if (DoublesRolled && !currentTurnsPlayers.inJail) { // Go back to phase 0 for current player turnPhase = 0; Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + currentTurnsPlayers.getName + "\"" + " gets to roll again!"); } else { // Start next player's turn SoshiLandGameFunctions.startNextPlayerTurn(ListOfPlayers); // Set phase back to 0 for next player turnPhase = 0; optionsCalculated = false; taxesMustPayTenPercent = false; taxesMustPayTwoHundred = false; displayJailMessageOnce = true; // set number of doubles back to zero numberOfDoubles = 0; } } break; } previousKeyboardInput = kbInput; }