import random def get_roll(): return random.randint(1, 6) def get_land_on(roll): return board[roll - 1] def get_properties(land_on): return properties[land_on] def get_rent(properties): return rent[properties] def get_mortgage_payment(properties): return mortgage_payment[properties] def get_bank_balance(properties): return bank_balance[properties] def get_winner(players): return player[players.index(-1)] def play_game(players): # Initialize the board board = [] properties = [] rent = [] mortgage_payment = [] bank_balance = [] for i in range(40): board.append(i) properties.append({"name": "Property", "price": i}) rent.append({"name": "Rent", "value": 20}) mortgage_payment.append({"name": "Mortgage Payment", "value": 10}) bank_balance.append({"name": "Bank Balance", "value": 1000}) # Initialize the players players = [] for i in range(4): players.append({"name": "Player", "money": 1000}) # Roll the dice roll = get_roll() # Move the player land_on = get_land_on(roll) # Buy the property properties[land_on] = players[roll] # Pay the rent if properties[land_on] == players[roll]: players[roll] -= rent[land_on] # Collect rent if properties[land_on] != players[roll]: players[roll] += rent[land_on] # Get a mortgage if players[roll].money < properties[land_on].price: players[roll] += mortgage_payment[land_on] # Get out of jail if players[roll].is_in_jail: players[roll].is_in_jail = False # Go to jail if roll == 7: players[roll].is_in_jail = True # End of the game if there is only one player left: get_winner(players) return # Next turn roll = get_roll() # Play again! play_game(players)