示例#1
0
        public void PayToBank(ref int amount)
        {
            if (Money < amount)
            {
                Console.WriteLine($"{DisplayName} only has ${Money} of ${amount} to pay.");

                var unmortgagedTiles = OwnedTiles.Where(tile => !tile.IsMortgaged).OrderBy(tile => tile.TileOptions.Cost);
                if (unmortgagedTiles.Count() > 0)
                {
                    foreach (var tile in unmortgagedTiles)
                    {
                        foreach (int soldPrice in tile.Mortgage())
                        {
                            if (Money > amount)
                            {
                                break;                 // Sold enough
                            }
                        }
                        if (Money > amount)
                        {
                            break;                 // Sold enough
                        }
                    }
                }

                if (Money < amount) // After mortgaging (or nothing to mortgage) and still unable to pay, pay with whatever the player is left and disown all properties.
                {
                    amount = Money;
                    OwnedTiles.ForEach(tile => tile.Disown());
                    OwnedTiles.Clear();
                    IsBankrupt = true;
                }
            }
            Money -= amount;
        }
示例#2
0
        public virtual void TakeTurn(Board board)
        {
            Console.WriteLine($"{DisplayName} [${Money} | {OwnedTiles.Count} properties | {MortgagedTiles.Count} mortgaged].");

            if (boardLocation == board.GetSpecialTile(SpecialTileType.Jail).BoardPosition&& JailTurnRemaining > 0)  // In jail
            {
                Console.WriteLine($"{DisplayName} is in jail. {JailTurnRemaining} turn{(JailTurnRemaining > 1 ? "s" : "")} remaining.");
                if (OutOfJailCards.Count > 0)
                {
                    if (IsHuman)
                    {
                        Console.WriteLine($"Do you want to use 1 Get out of Jail card? (You have {OutOfJailCards.Count}) (Y/n)");
                    }

                    if (!IsHuman || Console.ReadKey(true).Key == ConsoleKey.Y)
                    {
                        JailTurnRemaining = 0;
                        Console.WriteLine($"{DisplayName} used 1 Get out of Jail card.");
                    }
                }
            }
            else
            {
                DiceRoll = random.Next(1, 7);
                Tile tile = AdvanceBoardPostiion(board, DiceRoll, false);

                Console.WriteLine($"{DisplayName} rolled a {DiceRoll}.");
                Console.WriteLine($"{DisplayName} is visiting {tile.DisplayName}. {((tile is PropertyTile && ((PropertyTile)tile).Owner != null) ? $"[{((PropertyTile)tile).Owner.DisplayName}]" : String.Empty)}");
                tile.OnVisit(this, board);
            }

            var canUnmortgage = MortgagedTiles.Where(tile => Money > tile.TileOptions.UnMortgageValue).ToList();

            if (canUnmortgage.Count > 0)
            {
                if (IsHuman)
                {
                    Console.WriteLine($"Do you want to buy back any mortgaged property? (Y/n)");
                    ConsoleKey key = Console.ReadKey(true).Key;

                    if (key == ConsoleKey.Y)
                    {
                        do
                        {
                            for (int i = 0; i < canUnmortgage.Count(); i++)
                            {
                                PurchasableRentTile tile = canUnmortgage[i];
                                Console.WriteLine($"Choose the property to unmortgage by entering the corressponding number:");
                                Console.WriteLine($"{i + 1}. {tile.DisplayName} for ${tile.TileOptions.UnMortgageValue}.");
                            }

                            char c;
                            bool isDigit, isValid;
                            int  choice = 0;
                            do
                            {
                                c       = Console.ReadKey(true).KeyChar;
                                isDigit = isValid = char.IsDigit(c);
                                if (c == 'q' || c == 'Q') // Quit
                                {
                                    key = ConsoleKey.N;
                                    break;
                                }
                                else if (!isDigit)
                                {
                                    Console.WriteLine("The value you have entered is not a number. To exit, enter 'Q'.");
                                }
                                else
                                {
                                    choice = int.Parse(c.ToString());
                                    if (choice < 0 || choice >= canUnmortgage.Count())
                                    {
                                        Console.WriteLine("The number you have entered is not a valid choice.");
                                        isValid = false;
                                    }
                                }
                            }while (!(isDigit && isValid));

                            PurchasableRentTile tileToBuyBack = canUnmortgage[choice];
                            tileToBuyBack.UnMortgage();

                            Console.WriteLine($"Continue rebuying more mortgaged property? (Y/n)");
                            key = Console.ReadKey(true).Key;
                        }while (key == ConsoleKey.Y);
                    }
                }
                else
                {
                    canUnmortgage = canUnmortgage.OrderBy(tile => tile.TileOptions.UnMortgageValue).ToList();
                    while (MortgagedTiles.Count > 0 && Money > canUnmortgage.Min(tile => tile.TileOptions.UnMortgageValue * 3 / 2))
                    {
                        PurchasableRentTile tileToBuyBack = canUnmortgage.SkipWhile(tile => !tile.IsMortgaged).First();
                        tileToBuyBack.UnMortgage();
                    }
                }
            }

            if (JailTurnRemaining > 0)
            {
                JailTurnRemaining--;
            }

            Console.WriteLine($"{DisplayName} [${Money} | {OwnedTiles.Count} properties | {OwnedTiles.Where(tile => tile.IsMortgaged).Count()} mortgaged].");
        }