コード例 #1
0
ファイル: SoshilandGame.cs プロジェクト: mikairi/SoshiLand
        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
        }
コード例 #2
0
ファイル: SoshilandGame.cs プロジェクト: mikairi/SoshiLand
        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.inJail = false;                                              // Set player out of jail
                            Game1.debugMessageQueue.addMessageToQueue("Player is no longer in jail!");
                            currentTurnsPlayers.turnsInJail = 0;                                             // Set turns in jail back to zero

                            SoshiLandGameFunctions.MovePlayerDiceRoll(currentTurnsPlayers, currentDiceRoll); // Move player piece
                            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

                            turnPhase = 1;              // Set the next phase
                            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;
        }