1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- # A ledger and calculator for Monopoly games
- # Enables equal distributions to all (other) players
- # This was the original experiment
- numPlayers = 0
- accounts = []
- # accounts[0] is the pot, players are after that
- def printBalances():
- for account in accounts:
- print(account[0] + ": " + str(account[1]))
- def initialize():
- global numPlayers
- global accounts
- numPlayers = int(input("How many players (>1)? "))
- if numPlayers < 2:
- initialize()
- return
- startingValue = int(input("How much for each player? "))
- accounts.append(["Pot",0])
- while len(accounts) < numPlayers + 1:
- i = len(accounts)
- accounts.append(["Player " + str(i), startingValue])
- print ("Created:\n")
- printBalances()
- print("Let the game begin!\n")
- def play():
- global accounts
- playing = True
- while playing:
- option = input("[b]alances, [s]end, [q]uit: ")
- if option == "q":
- print("Game over!")
- playing = False
- if option == "b":
- printBalances()
- if option == "s":
- fromAcc = input("From (Choose pot, bank, or 1-" +
- str(numPlayers) + " for players): ")
- toAcc = input("To (Choose pot, bank, 1-" +
- str(numPlayers) +
- " for players, or all): ")
- amount = int((input("Amount (integer): ")))
- #DEBIT
- if fromAcc != "bank":
- if fromAcc == "pot":
- fromAcc = 0
- else:
- fromAcc = int(fromAcc)
- accounts[fromAcc][1] = accounts[fromAcc][1] - amount
- #CREDIT
- if toAcc != "bank":
- if toAcc == "all":
- remainder = amount
- i = 1
- while remainder > 0:
- if i != fromAcc:
- remainder -= 1
- accounts[i][1] += 1
- i += 1
- if i > numPlayers:
- i = 1
- else:
- if toAcc == "pot":
- toAcc = 0
- else:
- toAcc = int(toAcc)
- accounts[toAcc][1] = accounts[toAcc][1] + amount
- printBalances()
- initialize()
- play()
|