Beispiel #1
0
        public void PlaceAllPiecesOnGo(List <Player> listOfPlayers)
        {
            Game1.debugMessageQueue.addMessageToQueue("Placing all players on Go");

            foreach (Player p in listOfPlayers)
            {
                // Move player to Go
                SoshiLandGameFunctions.MovePlayer(p, 0);
            }
            SoshilandGame.gameInitialized = true;
        }
Beispiel #2
0
        public static void MovePlayerDiceRoll(Player p, int roll)
        {
            int currentPosition = p.CurrentBoardPosition;
            int newPosition     = currentPosition + roll;

            // If player passes or lands on Go
            if (newPosition > 47)
            {
                newPosition = Math.Abs(newPosition - 48);           // Get absolute value of the difference and move player to that new Tile
                p.BankPaysPlayer(200);                              // Pay player $200 for passing Go
            }
            // Move player to the new position
            SoshiLandGameFunctions.MovePlayer(p, newPosition);
        }
Beispiel #3
0
        public SoshilandGame(string[] players)
        {
            Initialization gameInitialization = new Initialization();

            gameInitialization.InitializeTiles(Tiles);                            // Initialize Tiles on the board
            gameInitialization.InitializeCards(ChanceCards, CommunityChestCards); // Initialize Chance and Community Chest cards

            playerArray = new Player[players.Length];

            for (int i = 0; i < players.Length; i++)
            {
                playerArray[i] = new Player(players[i]);
            }

            gameInitialization.DeterminePlayerOrder(playerArray, ref ListOfPlayers);        // Determine order of players
            // Players choose pieces (this can be implemented later)


            gameInitialization.DistributeStartingMoney(ListOfPlayers);                      // Players are given starting money
            gameInitialization.PlaceAllPiecesOnGo(ListOfPlayers);                           // Place all Pieces on Go
            SoshiLandGameFunctions.startNextPlayerTurn(ListOfPlayers);                      // Start first player's turn
        }
Beispiel #4
0
        public static void RollDice(Player p)
        {
            SoshilandGame.DoublesRolled = false;
            int dice1Int = SoshilandGame.die.Next(1, 6);
            int dice2Int = SoshilandGame.die.Next(1, 6);

            int total = dice1Int + dice2Int;

            SoshilandGame.currentDiceRoll = total;                // Set the global dice roll variable

            if (dice1Int == dice2Int && SoshilandGame.gameInitialized)
            {
                SoshilandGame.DoublesRolled = true;
                // Check if it's the third consecutive double roll
                if (SoshilandGame.numberOfDoubles == 2)
                {
                    // Move player to jail
                    SoshiLandGameFunctions.MovePlayerToJail(p);
                }
                else
                {
                    // Increment number of doubles
                    SoshilandGame.numberOfDoubles++;
                }
            }

            Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + p.getName + "\"" + " rolls dice: " + dice1Int + " and " + dice2Int + ". Total: " + total);
            if (SoshilandGame.DoublesRolled)
            {
                Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + p.getName + "\"" + " rolled doubles!");
            }

            // Only move if the player is not in jail
            if ((!p.inJail) && SoshilandGame.gameInitialized)
            {
                SoshiLandGameFunctions.MovePlayerDiceRoll(p, total);
            }
        }
Beispiel #5
0
        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);
                }
            }
        }
Beispiel #6
0
        private void PlayerOptions(Player player)
        {
            int      currentTile     = player.CurrentBoardPosition;
            TileType currentTileType = Tiles[currentTile].getTileType;

            optionPurchaseOrAuctionProperty = false;
            optionDevelopProperty           = false;

            // Determine Player Options and take any actions required
            switch (currentTileType)
            {
            case TileType.Property:
                PropertyTile currentProperty = (PropertyTile)Tiles[currentTile];

                if (currentProperty.Owner == null)                      // If the property is not owned yet
                {
                    optionPurchaseOrAuctionProperty = true;
                }
                else if (currentProperty.Owner != player && !currentProperty.MortgageStatus)            // If the property is owned by another player and not mortgaged
                {
                    if (player.getMoney >= currentProperty.getRent)                                     // Check if the player has enough money to pay Rent
                    {
                        player.CurrentPlayerPaysPlayer(currentProperty.Owner, currentProperty.getRent); // Pay rent
                        turnPhase = 2;                                                                  // Go to next phase
                    }
                    else
                    {
                        optionPromptMortgageOrTrade = true;             // Player must decide to mortgage or trade to get money
                    }
                }
                else
                {
                    // Otherwise, player landed on his or her own property, so go to next phase
                    turnPhase = 2;
                }


                break;

            case TileType.Utility:
                UtilityTile currentUtility = (UtilityTile)Tiles[currentTile];
                UtilityTile otherUtility;

                if (currentTile == 15)
                {
                    otherUtility = (UtilityTile)Tiles[33];
                }
                else
                {
                    otherUtility = (UtilityTile)Tiles[15];
                }

                if (currentUtility.Owner == null)                   // If the property is not owned yet
                {
                    optionPurchaseOrAuctionUtility = true;
                }

                else if (currentUtility.Owner != player && !currentUtility.MortgageStatus) // If the property is owned by another player
                {
                    int utilityRent;                                                       // Calculate the amount to pay for Utility Rent

                    if (currentUtility.Owner == otherUtility.Owner)                        // Check if player owns both utilities
                    {
                        utilityRent = (int)currentDiceRoll * 10;
                    }
                    else
                    {
                        utilityRent = (int)currentDiceRoll * 4;
                    }


                    if (player.getMoney >= utilityRent)                                    // Check if the player has enough money to pay Rent
                    {
                        player.CurrentPlayerPaysPlayer(currentUtility.Owner, utilityRent); // Pay rent
                        turnPhase = 2;                                                     // Go to next phase
                    }
                    else
                    {
                        optionPromptMortgageOrTrade = true;                 // Player must decide to mortgage or trade to get money
                    }
                }
                else
                {
                    // Otherwise, player landed on his or her own property, so go to next phase
                    turnPhase = 2;
                }
                break;

            case TileType.Chance:
                Card drawnChanceCard = ChanceCards.drawCard();                                  // Draw the Chance card
                SoshiLandGameFunctions.FollowCardInstructions(drawnChanceCard, player, ListOfPlayers);
                turnPhase = 2;
                break;

            case TileType.CommunityChest:
                Card drawnCommunityChestCard = CommunityChestCards.drawCard();                  // Draw the Community Chest card
                SoshiLandGameFunctions.FollowCardInstructions(drawnCommunityChestCard, player, ListOfPlayers);
                turnPhase = 2;
                break;

            case TileType.FanMeeting:
                turnPhase = 2;                  // Nothing happens, so go to last phase
                break;

            case TileType.Jail:
                turnPhase = 2;                  // Nothing happens, so go to last phase
                break;

            case TileType.ShoppingSpree:
                currentTurnsPlayers.PlayerPaysBank(75);         // Pay Bank taxes
                turnPhase = 2;
                break;

            case TileType.SpecialLuxuryTax:
                Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + currentTurnsPlayers.getName + "\"" + " must choose to pay 10% of net worth, or $200");
                Game1.debugMessageQueue.addMessageToQueue("Press K to pay 10% of net worth, or L to pay $200");
                optionPromptLuxuryTax = true;
                break;

            case TileType.GoToJail:
                SoshiLandGameFunctions.MovePlayerToJail(player);
                break;

            case TileType.Go:
                turnPhase = 2;
                break;
            }

            optionsCalculated = true;

            if (Game1.DEBUG)
            {
                string optionsMessage = "Options Available: Trade,";
                if (optionDevelopProperty)
                {
                    optionsMessage = optionsMessage + " Develop,";
                }
                if (optionPurchaseOrAuctionProperty || optionPurchaseOrAuctionUtility)
                {
                    optionsMessage = optionsMessage + " Purchase/Auction";
                }

                Game1.debugMessageQueue.addMessageToQueue(optionsMessage);
            }
        }
Beispiel #7
0
        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;
        }