Exemplo n.º 1
0
        public void CurrentPlayerPaysPlayer(Player paidPlayer, int amountPaid)
        {
            // This function assumes the Player has sufficient funds to pay.
            // There is a separate function that will deal with the case where
            // The player does not have enough funds to pay

            Game1.debugMessageQueue.addMessageToQueue("Player \"" + paidPlayer.getName + "\" receives $" + amountPaid + " from Player \"" + this.getName + "\"");

            paidPlayer.addMoney(amountPaid);
            removeMoney(amountPaid);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 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);

            }
        }
Exemplo n.º 6
0
        public static void MovePlayerToJail(Player p)
        {
            Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + p.getName + "\"" + " goes to jail!");
            // Set jail flag for player
            p.inJail = true;
            MovePlayer(p, 12);

            // Set phase to Post Roll Phase
            SoshilandGame.turnPhase = 2;
        }
Exemplo n.º 7
0
 public static void MovePlayer(Player p, int position)
 {
     // Update the player's current position to the new position
     p.CurrentBoardPosition = position;
     Game1.debugMessageQueue.addMessageToQueue("Player " + "\"" + p.getName + "\"" + " moves to Tile \"" + SoshilandGame.Tiles[position].getName + "\"");
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public static void FollowCardInstructions(Card card, Player player, List<Player> listOfPlayers)
        {
            if (card.getMoneyModifier != 0)             // Check if we need to do anything money related
            {
                bool negative = false;                  // Temporary bool to check if the money modifier is negative
                if (card.getMoneyModifier < 0)
                    negative = true;                    // Set negative flag

                switch (card.getPerPlayer)              // Check if the card affects all players
                {
                    case true:                          // Case when card affects all players
                        switch (negative)               // Check if we're removing money
                        {
                            case true:                  // Case when we're removing money from current player (current player pays all other players)
                                foreach (Player p in listOfPlayers)
                                    if (player != p)    // Player cannot pay him/herself
                                        player.CurrentPlayerPaysPlayer(p, Math.Abs(card.getMoneyModifier));     // Pay each player the amount
                                break;
                            case false:                 // Case when player pays the bank
                                foreach (Player p in listOfPlayers)
                                    if (player != p)    // Player cannot be paid by him/herself
                                        p.CurrentPlayerPaysPlayer(player, Math.Abs(card.getMoneyModifier));     // Each player pays the current player the amount
                                break;
                        }
                        break;
                    case false:                         // Case when card does not affect all players
                        switch (negative)               // Check if we're removing money
                        {
                            case true:                  // Case when we're removing money
                                player.PlayerPaysBank(Math.Abs(card.getMoneyModifier));         // Player pays bank
                                break;
                            case false:                 // Case when we're adding money
                                player.BankPaysPlayer(Math.Abs(card.getMoneyModifier));         // Bank pays player
                                break;
                        }
                        break;
                }
            }

            if (card.getMoveModifier != 0)              // Check if we need to do a move modification
            {
                // Note: since there are no cards that do this yet, going to skip this for now
            }

            if (card.getMovePosition != 0)              // Check if we need to do a position movement
            {
                if (card.getSpecialCardType == SpecialCardType.CanPassGo)   // Check if the card actually moves around the board
                {
                    if (player.CurrentBoardPosition > card.getMovePosition && player.CurrentBoardPosition <= 47)    // Check if the player will pass Go from his or her current location
                        player.BankPaysPlayer(200);         // Pay 200 since player will pass Go

                }
                MovePlayer(player, card.getMovePosition);
            }

            if (card.getSpecialCardType == SpecialCardType.GetOutOfJailFreeCard)
            {
                player.FreeJailCards += 1;          // Give player a get out of jail free card
                Game1.debugMessageQueue.addMessageToQueue("Player \"" + player.getName + "\" gets a Get Out of Jail Free Card");
            }
        }
Exemplo n.º 10
0
        public static bool PayTenPercentWorthToBank(Player player)
        {
            int tenPercent = (int)Math.Round(player.getNetWorth * 0.10);  // Calculate 10% of Player's money

            if (player.getMoney >= tenPercent)              // Check if player has enough money to pay 10%
            {
                SoshilandGame.currentTurnsPlayers.PlayerPaysBank(tenPercent);                 // Player pays bank 10%
                Game1.debugMessageQueue.addMessageToQueue(
                    "Player " + "\"" + SoshilandGame.currentTurnsPlayers.getName + "\"" + " pays $" + tenPercent + " in taxes");
                return true;
            }
            else
            {
                Game1.debugMessageQueue.addMessageToQueue(
                    "Player " + "\"" + SoshilandGame.currentTurnsPlayers.getName + "\"" + " needs to pay $" + tenPercent + " but does not have enough money");
                return false;
            }
        }