Exemplo n.º 1
0
def main():
    print("random",random.randint(0,6))
    # ALL THE STUFF!

    # Trade
    def trade(p1, p2):
        """
        :param p1: Player 1
        :param p2: Player 2
        :return: None
        """
        deal = input("Are properties being traded? (y/n) ")
        temp = None
        if deal == "y":
            print("---- PROPERTY NAMES ARE CASE SENSITIVE ----")
            deal = input("Is Player one giving a property? (y/n) ")
            if deal == "y":
                print("Player one's properties:")
                print(p1.getProperties())
                temp = input("What would you like to trade, Player one? ")
                p1.loseProperty(temp)
            deal = input("Is Player two giving a property (y/n) ")
            if deal == "y":
                print("Player two's properties:")
                print(p2.getProperties())
                if temp != None:
                    p2.gainProperty(temp)
                temp = input("What would you like to trade, Player two? ")
                p1.gainProperty(temp)
                p2.loseProperty(temp)
        money = input("Is there money involved in this trade? (y/n) ")
        if money == "y":
            money = input("Is player one giving money? (y/n) ")
            if money == "y":
                p2.gainMoney(int(input("How much money is Player one giving? $")))
            money = input("Is player two giving money? (y/n) ")
            if money == "y":
                p1.gainMoney(int(input("How much money is Player two giving? $")))
        return

    # Die
    Die1 = Die()
    Die2 = Die()

    # Properties:

    # Purple
    Mediterranean = Property("Mediterranean Avenue", "brown", 60, 50, 50, 30, [2, 10, 30, 90, 160, 250])
    Baltic = Property("Baltic Avenue", "brown", 60, 50, 50, 30, [4, 20, 60, 180, 320, 450])

    # Light Blue
    Oriental = Property("Oriental Avenue", "light blue", 100, 50, 50, 50, [6, 30, 90, 270, 400, 550])
    Vermont = Property("Vermont Avenue", "light blue", 100, 50, 50, 50, [6, 30, 90, 270, 400, 550])
    Connecticut = Property("Connecticut Avenue", "light blue", 120, 50, 50, 60, [8, 40, 100, 300, 450, 600])

    # Fuschia
    StCharles = Property("St. Charles Place", "fuschia", 140, 100, 100, 70, [10, 50, 150, 450, 625, 750])
    States = Property("States Avenue", "fuschia", 140, 100, 100, 70, [10, 50, 150, 450, 625, 750])
    Virginia = Property("Virginia Avenue", "fuschia", 160, 100, 100, 80, [12, 60, 180, 500, 700, 900])

    # Orange
    StJames = Property("St. James Place", "orange", 180, 100, 100, 90, [14, 70, 200, 550, 750, 950])
    Tennessee = Property("Tennessee Avenue", "orange", 180, 100, 100, 90, [14, 70, 200, 550, 750, 950])
    NewYork = Property("New York Avenue", "orange", 200, 100, 100, 100, [12, 80, 220, 600, 800, 1000])

    # Red
    Kentucky = Property("Kentucky Avenue", "red", 220, 150, 150, 110, [18, 90, 250, 700, 875, 1050])
    Indiana = Property("Indiana Avenue", "red", 220, 150, 150, 110, [18, 90, 250, 700, 875, 1050])
    Illinois = Property("Illinois Avenue", "red", 240, 150, 150, 120, [20, 100, 300, 750, 925, 1100])

    # Yellow
    Atlantic = Property("Atlantic Avenue", "yellow", 260, 150, 150, 130, [22, 1110, 330, 800, 975, 1150])
    Ventnor = Property("Ventnor Avenue", "yellow", 260, 150, 150, 130, [22, 1110, 330, 800, 975, 1150])
    Marvin = Property("Marvin Gardens", "yellow", 280, 150, 150, 140, [24, 120, 360, 850, 1025, 1200])

    # Green
    Pacific = Property("Pacific Avenue", "green", 300, 200, 200, 150, [26, 130, 390, 900, 110, 1275])
    NorthCarolina = Property("North Carolina Avenue", "green", 300, 200, 200, 150, [26, 130, 390, 900, 110, 1275])
    PennsylvaniaAve = Property("Pennsylvania Avenue", "green", 320, 200, 200, 160, [28, 150, 450, 1000, 1200, 1400])

    # Blue
    Park = Property("Park Place", "blue", 350, 200, 200, 175, [35, 175, 500, 1100, 1300, 1500])
    Boardwalk = Property("Boardwalk", "blue", 400, 200, 200, 30, [50, 200, 600, 1400, 1700])


    #Railroads:
    Pennsylvania = Railroad("Pennsylvania Railroad")

    Reading = Railroad("Reading Railroad")

    Short_Line = Railroad("Short Line")

    BO = Railroad("B. &. O. Railroad")  # lol

    # Utilities:
    Water = Utility("Water Works", Die1, Die2)
    Electric = Utility("Electric Company", Die1, Die2)

    # Extra Spaces:

    # Just Visiting
    # Nothing happens :D

    # Free Parking
    # Put in the turn code

    # Luxury Tax/Income Tax
    # Turn code
    # Variables

    hotels = 12

    houses = 32

    pieces = ["Dog","Top Hat", "Car", "Iron", "Boat", "Thimble", "Boot", "Wheelbarrow"]

    spaces = ["Go", Mediterranean, "Community Chest", Baltic, "Income Tax", Reading, Oriental,
              "Chance", Vermont, Connecticut, "Jail", StCharles, Electric, States, Virginia, Pennsylvania,
              StJames, "Community Chest", Tennessee, NewYork, "Free Parking", Kentucky, "Chance",
              Indiana, Illinois, BO, Atlantic, Ventnor, Water, Marvin, "Go To Jail", Pacific, NorthCarolina,
              "Community Chest", PennsylvaniaAve, Short_Line, "Chance", Park, "Luxury Tax", Boardwalk]
    print("debug", spaces[39])
    # Cards:

    # Community Chest:
    # kill me
    # textEffect, effect

    Chesta = CommunityChest("Life Insurance Matters - Collect $100",100)
    Chestb = CommunityChest("Income Tax Refund - Collect $20", 20)
    Chestc = CommunityChest("Receive for Services - Collect $25", 25)
    Chestd = CommunityChest("Pay Hospital $100", -100)
    Cheste = CommunityChest("Christmas Fund Matures - $100", 100)
    Chestf = CommunityChest("You have won second prize in a beauty contest! - Collect $10", 10)
    Chestg = CommunityChest("Doctors Fee! Pay $50", -50)
    Chesth = CommunityChest("From sale of stock you get $45", 45)
    Chesti = CommunityChest("Pay School Tax of $150", -150)
    Chestj = CommunityChest("Go To Jail", "Jail")
    Chestk = CommunityChest("Advance to Go", "go")
    Chestl = CommunityChest("You inherit $100", 100)
    Chestm = CommunityChest("Bank Error in Your Favor - Collect $200", 200)
    Chestn = CommunityChest("Get Out of Jail Free", "jail card")
    communityChestDeck = [Chesta, Chestb, Chestc, Chestd, Cheste, Chestf, Chestg, Chesth, Chesti, Chestj, Chestk, Chestl, Chestm, Chestn]

    # Chance Cards:
    # TextEffect, effect, type

    ChanceA = Chance("Your building and loan matures - Collect $150", "money", 150)
    ChanceB = Chance("Bank pays you dividend of $50", "money", 50)
    ChanceC = Chance("Advance token to nearest utility - if unowned, you may buy it from bank."
                     "If owned, throw dice and pay owner a total ten times the amount thrown","move",0)
    ChanceD = Chance("Advance to Illinois Ave","move",24)
    chanceDeck = [ChanceA, ChanceB, ChanceC, ChanceD]

    freeParking = 0  #Free Parking
    # TURN CODE
    # i want to die
    print("Welcome to MONOPOLY!!")  # this is more excited than I feel. I hate monopoly
    print("There are 4 people playing")

    # player inputs
    print("Hi players! What piece would you like to have? There are: ")
    for i in range(len(pieces)):
        print(pieces[i],end=" ")
    print("available! Please don't choose the same piece.")  # figure out how to make them not choose the same piece
    player1 = Player(input("Player 1! Input your piece here! "))
    #if player1.getPiece() not in pieces:
    #    print("This was not an acceptable piece to input. Try again")
    player2 = Player(input("Player 2! Input your piece here! "))
    player3 = Player(input("PLayer 3! Input your piece here! "))
    player4 = Player(input("Player 4! Input your piece here! "))

    print("Rolling die to see who goes first!")

    input("Player 1, roll the die!")
    p1d = Die1.rollDie() + Die2.rollDie()
    print("You rolled:", p1d)
    print()

    input("Player 2, roll the die!")
    p2d = Die1.rollDie() + Die2.rollDie()
    print("You rolled:", p2d)
    print()

    input("Player 3, roll the die!")
    p3d = Die1.rollDie() + Die2.rollDie()
    print("You rolled:", p3d)
    print()

    input("Player 4, roll the die!")
    p4d = Die1.rollDie() + Die2.rollDie()
    print("You rolled:", p4d)

    print()

    playerOrder = []
    if max(p1d, p2d, p3d, p4d) == p1d:
        print("Player 1 goes first!")
        playerOrder = [player1, player2, player3, player4]
    elif max(p1d, p2d, p3d, p4d) == p2d:
        print("Player 2 goes first!")
        playerOrder = [player2, player3, player4, player1]
    elif max(p1d, p2d, p3d, p4d) == p3d:
        print("Player 3 goes first!")
        playerOrder = [player3, player4, player1, player2]
    else:
        print("Player 4 goes first!")
        playerOrder = [player4, player1, player2, player3]

    # Beginning the game
    while playerOrder[0].getMoney() > 0 or playerOrder[1].getMoney() > 0 or playerOrder[2].getMoney() > 0 or playerOrder[3].getMoney() > 0:
        cp = 0

        # Cycling around the order of players
        while cp < 4:

            # Making sure player not in jail
            if not playerOrder[cp].getInJail():
                print()
                print(playerOrder[cp].getPiece(), " Press enter to roll the die!")
                input()
                Die1.rollDie()
                Die2.rollDie()

                # Think about doing the doubles x3 to jail-- maybe not?
                print("You've rolled:", Die1.getCurrentFace(), "and", Die2.getCurrentFace())

                # Passing Go
                if playerOrder[cp].getSpace() + (Die1.getCurrentFace()+Die2.getCurrentFace()) > 39:
                    sp = (Die1.getCurrentFace()+Die2.getCurrentFace()) - (39 - playerOrder[cp].getSpace())
                    playerOrder[cp].setSpace(sp)
                    playerOrder[cp].gainMoney(200)
                    print("You passed GO! You've collected $200!")
                else:
                    playerOrder[cp].moveSpace(Die1.getCurrentFace(), Die2.getCurrentFace())

                # Community Chest
                if playerOrder[cp].getSpace() == 2 or playerOrder[cp].getSpace() == 17 or playerOrder[cp].getSpace() == 33:  #community chest
                    print("You've landed on community chest!")
                    randomnum = random.randint(1, 13)
                    print(communityChestDeck[randomnum].getTextEffect())
                    communityChestDeck[randomnum].drawCard(playerOrder[cp])
                    if isinstance(communityChestDeck[randomnum].getEffect(), int):
                        print("Money!")
                        communityChestDeck[randomnum].applyEffect()
                    else:
                        if communityChestDeck[randomnum].getEffect() == "go":
                            print("You have been sent to GO and have collected $200")
                            communityChestDeck[randomnum].applyEffect()
                        elif communityChestDeck[randomnum].getEffect() == "Jail":
                            print("Oh no! You've been sent to jail!")
                            communityChestDeck[randomnum].applyEffect()
                        else:
                            print("You have a Get Out Of Jail Free card now!")
                            communityChestDeck[randomnum].applyEffect()

                # Chance
                elif playerOrder[cp].getSpace() == 7 or playerOrder[cp].getSpace() == 22 or playerOrder[cp].getSpace() == 36: #chance
                    print("Chance! D:")
                    print(playerOrder[cp].getSpace())

                # Income Taxes
                elif playerOrder[cp].getSpace() == 4 or playerOrder[cp].getSpace() == 38:
                    if playerOrder[cp].getSpace() == 4:
                        print("You've landed on income tax! You lost $200.")
                        playerOrder[cp].loseMoney(200)
                        print("Your current balance is:", playerOrder[cp].getMoney())
                        freeParking += 200
                    else:
                        print("You've landed on luxury tax! You lost $100.")
                        playerOrder[cp].loseMoney(100)
                        print("Your current balance is:", playerOrder[cp].getMoney())
                        freeParking += 200
                    print("debug", playerOrder[cp].getSpace())

                # Go To Jail
                elif playerOrder[cp].getSpace() == 31:  # Go To Jail
                    print("Oh no! Go to jail!")
                    playerOrder[cp].getArrested()
                    print(playerOrder[cp].getSpace())

                # Railroads
                elif playerOrder[cp].getSpace() == 5 or playerOrder[cp].getSpace() == 15 or playerOrder[cp].getSpace() == 25 or playerOrder[cp].getSpace() == 35: #railroads

                    print("You landed on", spaces[playerOrder[cp].getSpace()])
                    print("Your balance is", playerOrder[cp].getMoney())
                    if spaces[playerOrder[cp].getSpace()].getOwner() == "Bank":
                        buy = input("Would you like to buy the railroad for $200? (y/n)")
                        if buy == "y":
                            playerOrder[cp].gainProperty(spaces[playerOrder[cp].getSpace()])
                            playerOrder[cp].loseMoney(spaces[playerOrder[cp].getSpace()].getPrice())
                            print("You bought the railroad! Your properties now are:",playerOrder[cp].getProperties())
                            print("Your balance now is:", playerOrder[cp].getMoney())
                            spaces[playerOrder[cp].getSpace()].buyRailroad(playerOrder[cp])

                        else:
                            print()
                    else:
                        print("Oh no! You landed on someone else's railroad! You have to pay the rent now!")
                        playerOrder[cp].loseMoney((spaces[playerOrder[cp].getSpace()]).getRent())
                        (spaces[playerOrder[cp].getSpace()].getOwner).gainMoney(
                            spaces[playerOrder[cp].getSpace()]).getRent()
                        print("Now your balance is", playerOrder[cp].getMoney())

                # Utilities
                elif playerOrder[cp].getSpace() == 12 or playerOrder[cp].getSpace() == 28:
                    print("debug",playerOrder[cp].getSpace())
                    if Electric.getOwner() == "Bank" or Water.getOwner() == "Bank":
                        print("Would you like to buy the Utility?")
                        buy = input("(Y/N)")
                        if buy == "y".lower():
                            if playerOrder[cp].getSpace() == 12:
                                Electric.buyUtility(playerOrder[cp])
                                playerOrder[cp].gainProperty(Electric)
                                playerOrder[cp].loseMoney(Electric.getPrice())
                            else:
                                Water.buyUtility(playerOrder[cp])
                                playerOrder[cp].gainProperty(Water)
                                playerOrder[cp].loseMoney(Water.getPrice())
                        else:
                            print("Ok.")
                    else:
                        if playerOrder[cp].getSpace() == 12:
                            playerOrder[cp].loseMoney(1)  # you should change this
                    print("Utilities! yay!")

                # Free Parking
                elif playerOrder[cp].getSpace() == 20:
                    if freeParking == 0:
                        print("You landed on Free Parking! Congratulations, you get 100 dollars!")
                        playerOrder[cp].gainMoney(100)
                    else:
                        print("You landed on Free Parking! Congratulations! You get",freeParking,"dollars!")
                        playerOrder[cp].gainMoney(freeParking)

                # Just Visiting
                elif playerOrder[cp].getSpace() == 10:
                    print("You've landed on Just Visiting!")

                # Properties
                else:
                    print(playerOrder[cp].getSpace())
                    print("You are on", spaces[playerOrder[cp].getSpace()])
                    print("You have", playerOrder[cp].getMoney(),"dollars")
                    if spaces[playerOrder[cp].getSpace()].getOwner() is None:
                        buy = input("Would you like to buy the property? (y/n)")
                        if buy == "y":
                            playerOrder[cp].gainProperty(spaces[playerOrder[cp].getSpace()])
                            playerOrder[cp].loseMoney(spaces[playerOrder[cp].getSpace()].getPrice())
                            print(playerOrder[cp].getProperties())
                            spaces[playerOrder[cp].getSpace()].buyProperty(playerOrder[cp].getPiece())
                            print("You bought the property! Your properties now are:", playerOrder[cp].getProperties())
                            print("Your balance now is:", playerOrder[cp].getMoney())
                            print(spaces[playerOrder[cp].getSpace()].buyProperty(playerOrder[cp].getPiece()))
                        else:
                            print("")
                    else:
                        print("Oh no! You landed on someone else's property! You have to pay the rent now!")
                        playerOrder[cp].loseMoney((spaces[playerOrder[cp].getSpace()]).getRent())
                        (spaces[playerOrder[cp].getSpace()].getOwner()).gainMoney(spaces[playerOrder[cp].getSpace()]).getRent()
                        print("Now your balance is",playerOrder[cp].getMoney())
                if Die1.getCurrentFace() == Die2.getCurrentFace():
                    if playerOrder[cp].getTimesDoubled() <= 3:
                        cp += 0
                        print("You rolled a double! Since you did, you get to go again!")
                    else:
                        print("You rolled doubles three times! You've been sent to jail!")
                        playerOrder[cp].getInJail()
                        cp += 1
                else:
                    cp += 1

            # Jail area
            else:
                count = 0
                if playerOrder[cp].getTimesJailed() <= 3:
                    while count < 3:
                        Die1.rollDie()
                        Die2.rollDie()
                        print("You rolled:",Die1.getCurrentFace(),"and",Die2.getCurrentFace())
                        if Die1.getCurrentFace() == Die2.getCurrentFace():
                            print("You rolled a double! Have fun out of jail!")
                            playerOrder[cp].outOfJail()
                        else:
                            print("Roll again!")
                            count += 1
                    print("Aw, you didn't roll a double in 3 rolls! Try again next time!")
                    playerOrder[cp].moreTimesInJail()
                    cp += 1
                else:
                    print("You've spent more than three turns in jail!")
                    print("You now have to pay $50")
                    playerOrder[cp].loseMoney(50)
                    print("Your current balance is", playerOrder[cp].getMoney())
                    playerOrder[cp].outOfJail()

    print("Monopoly is over. Hope you had fun.")