所以我花了一天左右的時間在這個老虎機程序上做一個學校任務,出於某種原因,當我運行該程序時唯一會發生的事情是它將打印函數中的第一條語句,但隨後關閉腳本。Python基本老虎機沒有運行?
import random
STATS = {"Win": 0, "Lose": 0}
def playSlots():
player = Player("Player")
game = Game(player, [])
print("Welcome to my not as rough slot machine, now featuring classes!")
gaw = SlotMachine(1,1,1)
SlotMachine.playRound
if player.money < 1:
print("Out of Money")
class Player:
def __init__(self, name):
self.money = 10
def getMoney(self):
return self.money
def changeMoney(self, value):
self.credits += value
class Game:
def __init__(self, player, stats):
self.player = player
self.stats = stats
def statChange(self, outcome):
global STATS
if outcome == "Win":
STATS["Win"] += 1
elif outcome == "Lose":
STATS["Lose"] += 1
class SlotMachine:
def __init__(self, slotL, slotC, slotR):
self.slotL = 1
self.slotC = 1
self.slotR = 1
def randomSlots(self):
self.slotL = random.choice([1, 2, 3])
self.slotC = random.choice([1, 2, 3])
self.slotR = random.choice([1, 2, 3])
return self.slotL, self.slotC, self.slotR
def playRound(self):
while Player.getMoney > 1:
print("You have",Player.getMoney(), "tokens")
playerWager = int(input("Enter the amount of money you would like to wager: "))
if playerWager > Player.getMoney() or playerWager == 0:
print("Invalid Wager")
continue
Player.changeMoney(playerWager)
self.randomSlots
print(self.slotL, "|", self.slotC, "|", self.slotR)
if (self.slotL == self.slotC) and (self.slotC == self.slotR):
print("Win")
Player.changeMoney((playerWager * 2))
Game.statChange("Win")
print("Money: ", Player.getMoney())
else:
print("Lose")
Game.statChange("Lose")
print("Money: ", Player.getMoney())
if Player.getMoney() < 1:
print("Out of Money")
break
userContinue = input("Continue? (q to quit): ")
if userContinue == "q":
break
def main():
playSlots()
main()
我有點在這方面的損失,所以任何幫助將不勝感激!
嘗試'SlotMachine.playRound()' –