Пример #1
0
        private static void take_action(Player p, List <string> options, int choice, ref bool turn_is_over,
                                        ref bool has_rolled, ref bool turn_ended, ref bool rent_paid, ref int dice_roll)
        {
            string action = options[choice];


            if (action.Equals(OPTION_ROLL_DICE))
            {
                bool doubles = false;
                dice_roll = roll_dice(dice, ref doubles);
                if (doubles && p.get_double_count() < 2)
                {
                    Console.WriteLine("You rolled a {0} on doubles!", dice_roll);
                    turn_is_over = false;
                    rent_paid    = false;
                    p.increment_double_count();
                    has_rolled = true;
                    p.advance(dice_roll);
                }
                else if (doubles && p.get_double_count() == 2)
                {
                    Console.WriteLine("Cheater! You rolled doubles three times in a row; you're going to jail!");
                    turn_is_over = true;
                    has_rolled   = true;
                    p.go_to_jail();
                }
                else
                {
                    Console.WriteLine("You rolled a {0}.", dice_roll);
                    turn_is_over = true;
                    rent_paid    = false;
                    has_rolled   = true;
                    p.advance(dice_roll);
                }


                if (board[p.get_position()].get_name().Equals("Go To Jail"))
                {
                    Console.WriteLine("\nOof - you landed on go to jail!");
                    has_rolled   = false;
                    turn_is_over = true;
                    p.go_to_jail();
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_PAY_JAIL))
            {
                p.pay_for_jail(JAIL_FEE);
                add_free_parking(JAIL_FEE);
                Console.WriteLine("You've successfully paid ${0} in bond to escape jail. You now have ${1}. The free parking pot now has ${2}.",
                                  JAIL_FEE, p.get_money(), free_parking);
                turn_is_over = true;
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_ROLL_DICE_JAIL))
            {
                bool doubles = false;
                roll_dice(dice, ref doubles);
                if (doubles)
                {
                    p.release_from_jail();
                    Console.WriteLine("Congratulations! You rolled doubles, and are free from jail!");
                    turn_is_over = true;
                }
                else
                {
                    p.increment_jail();
                    Console.WriteLine("Darn! You didn't roll doubles, and are still in jail. You have {0} more chances " +
                                      "to roll doubles before you'll have to pay bond.", 3 - p.jailed() + 1);
                    turn_is_over = true;
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_JAIL_CARD))
            {
                Console.WriteLine("Congratulations - you've successfully used your get out of jail free card to escape jail.");
                Card jail_free = p.use_jail_free_card();
                if (jail_free.get_type().Equals("Chance"))
                {
                    chance.Add(jail_free);
                }
                else
                {
                    chest.Add(jail_free);
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_PAY_RENT))
            {
                rent_paid = true;
                int rent = board[p.get_position()].get_rent(dice_roll);
                if (p.get_money() > rent)
                {
                    Player owner = board[p.get_position()].get_owner();
                    p.pay_rent(owner, rent);
                    Console.WriteLine("Thank you for paying ${0} in rent to {1}.", rent, owner.get_nickname());
                    Console.WriteLine("{0} now has ${1}.", owner.get_nickname(), owner.get_money());
                    Console.WriteLine("{0} now has ${1}.", p.get_nickname(), p.get_money());
                }
                else
                {
                    Player owner = board[p.get_position()].get_owner();
                    Console.WriteLine("You cannot afford rent!");
                    p.pay_rent(owner, rent);
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_BUY))
            {
                p.buy(board[p.get_position()]);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_INCOME_TAX_FIXED))
            {
                rent_paid = true;
                p.pay(INCOME_TAX);
                add_free_parking(INCOME_TAX);
                Console.WriteLine("Thank you for paying ${0} in fixed income tax. You now have ${1}. The free parking pot now has ${2}.",
                                  INCOME_TAX, p.get_money(), free_parking);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_INCOME_TAX_PCT))
            {
                rent_paid = true;
                int net_worth = p.get_net_worth();
                int tax       = Convert.ToInt32((double)net_worth * ((double)INCOME_TAX_PCT / 100.0));
                p.pay(tax);
                add_free_parking(tax);
                Console.WriteLine("Thank you for paying ${0} as {1}% income tax on your net worth of ${2}. You now have ${3}. " +
                                  "The free parking pot now has ${4}.",
                                  tax, INCOME_TAX_PCT, net_worth, p.get_money(), free_parking);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_LUXURY_TAX))
            {
                rent_paid = true;
                p.pay(LUXURY_TAX);
                add_free_parking(LUXURY_TAX);
                Console.WriteLine("Thank you for paying ${0} in fixed luxury tax. You now have ${1}. The free parking pot now has ${2}.",
                                  LUXURY_TAX, p.get_money(), free_parking);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_FREE_PARKING))
            {
                rent_paid = true;
                p.receive_payment(free_parking);
                Console.WriteLine("You've collected ${0} in free parking. You now have ${1}. The free parking pot now has ${2}.",
                                  free_parking, p.get_money(), free_parking_default);
                reset_free_parking();
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_CHANCE))
            {
                rent_paid = true;
                bool has_moved = false;
                // do chance draw from front of queue then replace at back of queue
                Console.WriteLine("You've drawn the following Chance card:");
                Card draw = chance[0];
                Console.WriteLine(draw);
                chance.Remove(draw);
                if (!draw.get_category().Equals("item"))
                {
                    chance.Add(draw); // add back to end of queue if NOT get out of jail free card; else, player keeps get out of jail free card
                }
                int parking_addition = p.take_card_action(draw, ref players, ref has_moved);
                add_free_parking(parking_addition);
                if (has_moved)
                {
                    has_rolled = true;
                    rent_paid  = false;
                }
                Console.WriteLine("Chance action successfully taken. The new status of each player is displayed below.\n");
                foreach (Player other in players)
                {
                    Console.WriteLine(other + "\n");
                }
                Console.WriteLine("The free parking pot now has ${0}.", free_parking);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_CHEST))
            {
                rent_paid = true;
                bool has_moved = false;
                // do chest draw from front of queue then replace at back of queue
                Console.WriteLine("You've drawn the following Community Chest card:");
                Card draw = chest[0];
                Console.WriteLine(draw);
                chest.Remove(draw);
                if (!draw.get_category().Equals("item"))
                {
                    chest.Add(draw); // add back to end of queue if NOT get out of jail free card; else, player keeps get out of jail free card
                }
                int parking_addition = p.take_card_action(draw, ref players, ref has_moved);
                add_free_parking(parking_addition);
                if (has_moved)
                {
                    has_rolled = true;
                    rent_paid  = false;
                }
                Console.WriteLine("Community Chest action successfully taken. The new status of each player is displayed below.\n");
                foreach (Player other in players)
                {
                    Console.WriteLine(other + "\n");
                }
                Console.WriteLine("The free parking pot now has ${0}.", free_parking);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_VIEW_PROPERTIES))
            {
                Console.WriteLine("Owned Properties:\n");
                foreach (Property property in p.get_properties())
                {
                    Console.WriteLine(property + "\n");
                }
                if (p.get_properties().Count == 0)
                {
                    Console.WriteLine("You do not own any properties.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_PERSONAL_DATA))
            {
                Console.WriteLine("Personal Data:\n");
                Console.WriteLine(p.ToString());
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_VIEW_MONOPOLIES))
            {
                Console.WriteLine("Owned Monopolies:\n");
                foreach (Property property in p.get_monopolies())
                {
                    Console.WriteLine(property + "\n");
                }
                if (p.get_monopolies().Count == 0)
                {
                    Console.WriteLine("You do not own any monopolies.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_VIEW_MORTGAGES))
            {
                Console.WriteLine("Mortgaged properties:\n");
                foreach (Property property in p.get_mortgaged_properties())
                {
                    Console.WriteLine(property + "\n");
                }
                if (p.get_mortgaged_properties().Count == 0)
                {
                    Console.WriteLine("You do not own any mortgaged properties.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_TILE_INFO))
            {
                Console.WriteLine("Current Tile:\n\n" + board[p.get_position()]);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_BOARD_INFO))
            {
                string available_properties = "";
                string mortgaged_properties = "";
                string owned_properties     = "";
                string active_players       = "";
                string detailed_players     = "";
                foreach (Property property in board)
                {
                    if (property.get_type().Equals("Street") || property.get_type().Equals("Railroad") || property.get_type().Equals("Utility"))
                    {
                        if (!property.owned())
                        {
                            available_properties += property.get_name() + ", ";
                        }
                        else if (property.mortgaged())
                        {
                            mortgaged_properties += property.get_name() + ", ";
                        }
                        else
                        {
                            owned_properties += property.get_name() + ", ";
                        }
                    }
                }
                foreach (Player other in players)
                {
                    active_players   += other.get_nickname() + ", ";
                    detailed_players += other.ToString() + "\n\n";
                }
                if (available_properties.Length > 0)
                {
                    available_properties = available_properties.Substring(0, available_properties.Length - 2);
                }
                if (mortgaged_properties.Length > 0)
                {
                    mortgaged_properties = mortgaged_properties.Substring(0, mortgaged_properties.Length - 2);
                }
                if (owned_properties.Length > 0)
                {
                    owned_properties = owned_properties.Substring(0, owned_properties.Length - 2);
                }
                if (active_players.Length > 0)
                {
                    active_players = active_players.Substring(0, active_players.Length - 2);
                }
                if (detailed_players.Length > 0)
                {
                    detailed_players = detailed_players.Substring(0, detailed_players.Length - 2);
                }
                Console.WriteLine("Global Board Information:\n");
                Console.WriteLine(@"Free Parking: ${0}
Free Parking Default: ${1}
Passing Go Value: ${2}
Landing on Go Bonus: ${3}
Number of Houses in Bank: {4}
Number of Hotels in Bank: {5}

Owned Properties: {6}

Mortgaged Properties: {7}

Available Properties: {8}

Active Players: {9}

Detailed Player Information:

{10}", free_parking, free_parking_default, go_value, go_bonus, bank_houses, bank_hotels, owned_properties,
                                  mortgaged_properties, available_properties, active_players, detailed_players);
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_GRAPHICS))
            {
                string[] rendered = Graphics.render(players, board, spaces_player, spaces_houses, board_art, free_parking);
                foreach (String row in rendered)
                {
                    Console.WriteLine(row);
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_TRADE))
            {
                rent_paid = true;
                //select trading partner
                Console.WriteLine("With whom would you like to trade?:\n");
                List <Player> others = new List <Player>();
                foreach (Player other in players) //compile list of potential trading partners
                {
                    if (!p.Equals(other))
                    {
                        others.Add(other);
                    }
                }
                for (int i = 0; i < others.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, others[i].get_nickname());
                }
                int    input  = input_int("\nEnter the number corresponding to the desired player.", 0, others.Count - 1);
                Player trader = others[input];

                //select property to receive
                Console.WriteLine("Below are the properties owned by {0} available for trading:\n", trader.get_nickname());
                List <Property> trader_properties = trader.get_tradable_properties();

                foreach (Property property in trader_properties)
                {
                    Console.WriteLine(property + "\n");
                }
                Console.WriteLine("Select the property you would like to receive from {0} from the list below.", trader.get_nickname());
                for (int i = 0; i < trader_properties.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, trader_properties[i].get_name());
                }
                Console.WriteLine("{0}: None", trader_properties.Count);
                trader_properties.Add(new Property());
                input = input_int("\nEnter the number corresponding to the desired property.", 0, trader_properties.Count - 1);
                Property property_to_receive = trader_properties[input];

                //select property to give
                Console.WriteLine("Below are your properties available for trading:\n");
                List <Property> my_properties = p.get_tradable_properties();
                foreach (Property property in my_properties)
                {
                    Console.WriteLine(property + "\n");
                }
                Console.WriteLine("Select the property you would like to give up from the list below.");
                for (int i = 0; i < my_properties.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, my_properties[i].get_name());
                }
                Console.WriteLine("{0}: None", my_properties.Count);
                my_properties.Add(new Property());

                input = input_int("\nEnter the number corresponding to the desired property.", 0, my_properties.Count - 1);
                Property property_to_give = my_properties[input];

                //determine trade amount
                Console.WriteLine("Who will be paying whom for this trade?\n");
                Console.WriteLine("0: I'm paying {0}", trader.get_nickname());
                Console.WriteLine("1: {0} is paying me", trader.get_nickname());
                Console.WriteLine("2: No money is being exchanged in this trade");
                input = input_int("\nEnter the number corresponding to your choice", 0, 2);

                //make trade
                if (input == 0)
                {
                    //p pays trader
                    int amount = input_int(String.Format("Enter the emount of money you are paying {0} for the trade.", trader.get_nickname()), 0, int.MaxValue);
                    p.pay(amount);
                    trader.receive_payment(amount);
                    p.send_property(trader, property_to_give);
                    trader.send_property(p, property_to_receive);
                    Console.WriteLine("Trade successful. Each player's updated status is displayed below:\n");
                    Console.WriteLine(p + "\n");
                    Console.WriteLine(trader);
                }
                else if (input == 1)
                {
                    //trader pays p
                    int amount = input_int(String.Format("Enter the emount of money {0} is paying for the trade.", trader.get_nickname()), 0, int.MaxValue);
                    trader.pay(amount);
                    p.receive_payment(amount);
                    p.send_property(trader, property_to_give);
                    trader.send_property(p, property_to_receive);
                    Console.WriteLine("Trade successful. Each player's updated status is displayed below:\n");
                    Console.WriteLine(p + "\n");
                    Console.WriteLine(trader);
                }
                else
                {
                    //no money is moved; just swap owners
                    p.send_property(trader, property_to_give);
                    trader.send_property(p, property_to_receive);
                    Console.WriteLine("Trade successful. Each player's updated status is displayed below:\n");
                    Console.WriteLine(p + "\n");
                    Console.WriteLine(trader);
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_MORTGAGE))
            {
                List <Property> properties = p.get_tradable_properties(); //only get properties without houses on them
                Console.WriteLine("You may mortgage one of the following properties:\n");
                foreach (Property property in properties)
                {
                    Console.WriteLine(property + "\n");
                }
                Console.WriteLine("\nSelect a property from the list below to mortgage: (note: properties with houses / hotels may not be mortgaged; houses / hotels must first be sold to the bank.)");
                for (int i = 0; i < properties.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, properties[i].get_name());
                }
                Console.WriteLine("{0}: Cancel", properties.Count);
                int number = input_int("\nEnter the number corresponding to the desired property.", 0, properties.Count);
                if (number < properties.Count)
                {
                    p.mortgage_property(properties[number]);
                    Console.WriteLine("{0} is now mortgaged.", properties[number].get_name());
                }
                else
                {
                    Console.WriteLine("Mortgaging cancelled.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_UNMORTGAGE))
            {
                List <Property> mortgaged = p.get_mortgaged_properties();
                Console.WriteLine("You may unmortgage one of the following properties:\n");
                foreach (Property property in mortgaged)
                {
                    Console.WriteLine(property + "\n");
                }
                Console.WriteLine("\nSelect a property from the list below to unmortgage:");
                for (int i = 0; i < mortgaged.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, mortgaged[i].get_name());
                }
                Console.WriteLine("{0}: Cancel", mortgaged.Count);
                int number = input_int("\nEnter the number corresponding to the desired property.", 0, mortgaged.Count);
                if (number < mortgaged.Count)
                {
                    Property property = mortgaged[number];
                    p.unmortgage_property(property);
                    Console.WriteLine("{0} is now unmortgaged.", property.get_name());
                }
                else
                {
                    Console.WriteLine("Unmortgaging cancelled.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_BUILD))
            {
                List <Property> monopolies = p.get_monopolies();
                List <Property> buildable  = new List <Property>();
                Console.WriteLine("You may build on one of the following properties:\n");
                foreach (Property property in monopolies)
                {
                    if (property.get_houses() < 5 && property.is_buildable(monopolies))
                    {
                        Console.WriteLine(property + "\n");
                        buildable.Add(property);
                    }
                }
                Console.WriteLine("\nSelect a property from the list below to build upon:");
                for (int i = 0; i < buildable.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, buildable[i].get_name());
                }
                Console.WriteLine("{0}: Cancel", buildable.Count);
                int number = input_int("\nEnter the number corresponding to the desired property.", 0, buildable.Count);
                if (number < buildable.Count)
                {
                    Property property = buildable[number];
                    property.build();
                    if (property.get_houses() < 5)
                    {
                        // houses
                        Console.WriteLine("Congratulations! {0} now has {1} houses on it. You now have ${2}.", property.get_name(), property.get_houses(), p.get_money());
                        bank_houses--;
                    }
                    else
                    {
                        // hotel
                        Console.WriteLine("Congratulations! {0} now has a hotel on it! You may not build any further on this property. You now have ${1}.", property.get_name(), p.get_money());
                        bank_houses += 4;
                        bank_hotels--;
                    }
                }
                else
                {
                    Console.WriteLine("House building cancelled.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_SELL_HOUSE))
            {
                List <Property> sellable = p.get_house_properties();

                Console.WriteLine("You may sell a house / hotel from one of the following properties:\n");
                foreach (Property property in sellable)
                {
                    Console.WriteLine(property + "\n");
                }
                Console.WriteLine("\nSelect a property from the list below to sell from:");
                for (int i = 0; i < sellable.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, sellable[i].get_name());
                }
                Console.WriteLine("{0}: Cancel", sellable.Count);
                int number = input_int("\nEnter the number corresponding to the desired action.", 0, sellable.Count);
                if (number < sellable.Count)
                {
                    Property property = sellable[number];
                    if (property.get_houses() == 5)
                    {
                        bank_hotels++;
                        bank_houses -= 4;
                    }
                    else
                    {
                        bank_houses++;
                    }
                    property.sell_house();
                    Console.WriteLine("{0} now has {1} houses on it. You now have ${2}.", property.get_name(), property.get_houses(), p.get_money());
                }
                else
                {
                    Console.WriteLine("House / hotel selling cancelled.");
                }
            }
            //////////////////////////////////////////////////////////////////////////
            if (action.Equals(OPTION_END_TURN))
            {
                turn_ended = true;
            }
        }
Пример #2
0
        public int take_card_action(Card card, ref List <Player> players, ref bool has_moved) //return amount of money going to free parking
        {
            string category = card.get_category();

            if (category.Equals("item"))
            {
                //only item is get out of jail free card
                get_out_of_jail_free = card;
                return(0);
            }
            else if (category.Equals("move"))
            {
                //move forward to a select index
                has_moved = true;
                int goto_index = card.get_effect();
                int distance   = (goto_index - position + 40) % 40; //ensure movement is forward
                advance(distance);
                return(0);
            }
            else if (category.Equals("move_abs"))
            {
                //move absolute distance from current pos
                has_moved = true;
                int distance = card.get_effect();
                advance(distance);
                return(0);
            }
            else if (category.Equals("move_utility"))
            {
                int dist_to_electric = (12 - position + 40) % 40;
                int dist_to_water    = (28 - position + 40) % 40;
                if (dist_to_electric < dist_to_water)
                {
                    advance(dist_to_electric);
                    return(0);
                }
                else
                {
                    advance(dist_to_water);
                    return(0);
                }
            }
            else if (category.Equals("move_rr"))
            {
                int dist_to_reading = (5 - position + 40) % 40;
                int dist_to_penn    = (15 - position + 40) % 40;
                int dist_to_bo      = (25 - position + 40) % 40;
                int dist_to_short   = (35 - position + 40) % 40;
                int min_dist        = Math.Min(Math.Min(dist_to_reading, dist_to_penn), Math.Min(dist_to_bo, dist_to_short));
                if (min_dist == dist_to_reading)
                {
                    advance(dist_to_reading);
                    return(0);
                }
                else if (min_dist == dist_to_penn)
                {
                    advance(dist_to_penn);
                    return(0);
                }
                else if (min_dist == dist_to_bo)
                {
                    advance(dist_to_bo);
                    return(0);
                }
                else //min_dist == dist_to_short
                {
                    advance(dist_to_short);
                    return(0);
                }
            }
            else if (category.Equals("move_jail"))
            {
                //go to jail
                go_to_jail();
                return(0);
            }
            else if (category.Equals("money"))
            {
                int amount = card.get_effect();
                //gain or lose money to free parking
                if (amount > 0)
                {
                    //receive money from bank
                    money += amount;
                    return(0);
                }
                else
                {
                    //pay positive money to free parking from personal finances
                    amount = Math.Abs(amount);
                    money -= amount;
                    return(amount);
                }
            }
            else if (category.Equals("money_houses"))
            {
                //pay based on houses
                int num_houses = 0;
                int num_hotels = 0;
                foreach (Property property in monopolies) //can only have buildings on monopolies
                {
                    if (property.get_houses() > 0 && property.get_houses() < 5)
                    {
                        num_houses += property.get_houses();
                    }
                    else if (property.get_houses() == 5)
                    {
                        num_hotels++;
                    }
                }

                if (card.get_tag().Equals("GENRP"))
                {
                    // cost is $25 per house and $100 per hotel
                    int amount = (25 * num_houses) + (100 * num_hotels);
                    money -= amount;
                    return(amount);
                }
                else if (card.get_tag().Equals("STRRP"))
                {
                    //cost is $40 per house and $115 per hotel
                    int amount = (40 * num_houses) + (115 * num_hotels);
                    money -= amount;
                    return(amount);
                }
                //shouldn't get here - catch case at end
            }
            else if (category.Equals("money_players"))
            {
                //pay money to other players
                int amount = card.get_effect();
                if (amount > 0)
                {
                    //receive money from other players
                    foreach (Player p in players)
                    {
                        p.pay(amount);
                        money += amount;
                    }
                }
                else
                {
                    //pay money to other players
                    amount = Math.Abs(amount);
                    foreach (Player p in players)
                    {
                        p.receive_payment(amount);
                        money -= amount;
                    }
                }
                return(0);
            }
            //shouldn't get here
            Console.WriteLine("Something's wrong -- card category not recognized.");
            return(0);
        }