未正确调用字典

我有一个老虎机程序,我试图使它不是很好地工作。我认为问题在于我从字典里取错了词。没有给出正确的硬币数量,我不确定为什么。它的规格是:
一人游戏以100枚硬币开始。
一轮5个硬币。
继续玩,直到你没有剩余的钱,或者玩家选择'套现'
每一步都会随机旋转这三个微调器。每个旋转器有5个符号:贝尔、樱桃、香蕉、美元、骷髅。
3个水果=50个硬币
2个同样的水果=10个硬币
3个铃铛=1000枚硬币
2个铃铛=100枚硬币
3美元=500枚硬币
2美元=50枚硬币
1美元=1枚硬币
金条意味着所有的钱都乘以10
如果任何旋转手柄上出现头骨,你可能赢不到任何钱。
以下是代码:

选择 | 换行 | 行号
  1. import tkinter as tk
  2. import random
  3.  
  4.  
  5. print("Welcome to the Virtual Slot Machine")
  6. global coins
  7. coins = 100
  8. symbols = ["bells", "cherries", "bananas", "dollars", "skull"]
  9. done = False
  10.  
  11. def sort(lists):
  12.   for i in range(len(lists)-1):
  13.     for x in range(len(lists)-1-i):
  14.       if lists[x] < lists[x + 1]:
  15.         lists[x], lists[x + 1] = lists[x + 1], lists[x]
  16.  
  17.   return lists
  18.  
  19. def open_file():
  20.   f = open("highscores.txt","r")
  21.   line = f.readlines()
  22.   f.close()
  23.   list1 = [int(i) for i in line[0].split(",")]
  24.   ordered = sort(list1)
  25.   return ordered
  26.  
  27. print("The highscores so far from higherst to smallest are: ")
  28. print(*open_file())
  29.  
  30. def Match(slot1, slot2, slot3):
  31.   if slot1 == slot2 and slot2 == slot3:
  32.     return slot1, 1
  33.   elif slot1 == slot2:
  34.     return slot1, 0
  35.   elif slot2 == slot3:
  36.     return slot2, 0
  37.   elif slot1 == slot3:
  38.     return slot3, 0
  39.   return None, None
  40.  
  41. def turn(coins):
  42.   coins -= 5
  43.   fruits = ["cherries", "bananas"]
  44.   slot1 = random.choice(symbols)
  45.   slot2 = random.choice(symbols)
  46.   slot3 = random.choice(symbols)
  47.   slots = [slot1, slot2, slot3]
  48.   reward_dict = {"dollars" : [50, 500], "bells": [100, 1000]}
  49.   for fruit in fruits:
  50.       reward_dict.update({fruit: [10, 50]})
  51.  
  52.   if random.randint(0,10000) == 1:
  53.     slot3 = "Gold Bar"
  54.  
  55.   print("You got {} {} {}".format(slot1,slot2,slot3))
  56.  
  57.   if "skull" not in slots:
  58.     match, number = Match(slot1, slot2, slot3)
  59.     if match != None:
  60.       coins += reward_dict[match][number-1]
  61.       print("You got {} {}! +{} coins!".format(number+2, match, reward_dict[match][number]))
  62.  
  63.   else:
  64.     print("Unlucky, you got a skull, you lose!")
  65.  
  66.   if slot1 == "dollar" or slot2 == "dollar" or slot3 == "dollar":
  67.     coins += 1
  68.  
  69.   if slot3 == "Gold Bar":
  70.     print("Jackpot! All coins times 10!")
  71.     coins = coins*10
  72.   return coins
  73.  
  74. while coins > 0 and done == False:
  75.   print("You have {0} coins".format(coins))
  76.   play = input("Do you want to play a round? It costs 5 coins? y/n ")
  77.   coins_left = coins - 5
  78.   if play == "y" and coins_left > 0:
  79.     coins = turn(coins)
  80.   else:
  81.     if coins_left < 0:
  82.       print("Sorry, you do not havwe enough money")
  83.       print("You ended with {0} coins".format(coins))
  84.     else:
  85.       print("Ok, thanks for playing")
  86.       print("You ended with {0} coins!".format(coins))
  87.       done = True
  88.  

谢谢!

标签: python

添加新评论