В этой игре игрок начинает со 100 монетами, чтобы играть в слоты. Я пытался придумать способ вместо этого использовать ползунок, чтобы люди могли скользить вверх, скажем, до 100 или вниз, до минимума, скажем, 10. Когда пользователь собирается выбрать определенную сумму. Либо это, либо мне нужно было бы изменить его на ввод текста с минимальным и максимальным значениями 10-100.
Однако я изо всех сил пытался заставить что-то вроде работы в этом коде. В предыдущей программе у меня был рабочий слайдер, поэтому я знаю, что он может работать, однако мои попытки заставить его работать здесь не увенчались успехом. Любые идеи?
import tkinter as tk
import random
intro = """Panther's Den Slot Machine.
Welcome to my den!
You can win by rolling Ocelots, Jaguars, Boas, Caimans, Macaws or Tapirs.
You can also with big with three Ibis.
You'll lose a coin for anything else, and if you roll three Scorpions say good bye to 500 coins
Good luck kit!"""
root = tk.Tk()
root.geometry("700x500")
root.title("Slot Machine")
root.configure(background='seagreen')
INIT_STAKE = 100
ITEMS = ["OCELOT", "MACAW", "JAGUAR", "IBIS", "CAIMAN", "BOA", "SCORPION", "TAPIR", "CONDOR", "BAMBOO", "FROG"]
first = None
second = None
third = None
stake = INIT_STAKE
nameLabel = tk.Label(root, text = "PANTHER DEN", font=('Cambria', 60))
nameLabel.pack()
lbl = tk.Label(root, text=intro, background='seagreen', font=('Cambria', 12))
lbl.pack()
lbl2 = tk.Label(root, text=stake)
lbl2.pack()
def play():
global first, second, third
first = spin()
second = spin()
third = spin()
score()
def quit_play():
lbl.config(text = "Game has ended. You won a total of " + str(stake) + " coins")
def spin():
randomnumber = random.randint(0, 10)
return ITEMS[randomnumber]
def score():
global stake, first, second, third
if ((first == "OCELOT") and (second != "MACAW")):
win = 5
elif ((first == "JAGUAR") and (second == "JAGUAR") and (third != "JAGUAR")):
win = 8
elif ((first == "BOA") and (second == "BOA") and (third == "BOA")):
win = 10
elif ((first == "CAIMAN") and (second == "CAIMAN") and ((third == "CAIMAN") or (third == "BOA"))):
win = 8
elif ((first == "MACAW") and (second == "IBIS") and ((third == "MACAW"))):
win = 15
elif ((first == "TAPIR") and (second == "TAPIR") and ((third == "TAPIR"))):
win = 20
elif ((first == "IBIS") and (second == "IBIS") and (third == "IBIS")):
win = 300
elif ((first == "SCORPION") and (second == "SCORPION") and (third == "SCORPION")):
win = -500
else:
win = -1
stake += win
if (win > 0):
lbl.config(text = "{}\t{}\t{} -- You win {} Coins".format(first, second, third, win))
lbl2.config(text=stake)
else:
lbl.config(text = "{}\t{}\t{} -- You lose".format(first, second, third))
lbl2.config(text=stake)
tk.Button(root, text = "Play", command=play).pack()
tk.Button(root, text = "Quit", command=quit_play).pack()
tk.Button(root, text = "Exit", command=quit).pack()
root.mainloop()
🤔 А знаете ли вы, что...
С Python можно создавать веб-скраперы для извлечения данных из веб-сайтов.
Сначала вам нужно добавить ползунок, который устанавливает значение ставки с помощью команды - здесь я использовал глобальный, потому что вся ваша программа основана на этом, но вы можете инкапсулировать это в классе.
Затем используйте это значение ставки для корректировки суммы выигрыша / проигрыша.
Код здесь отражает это. (вы можете легко добавить некоторые элементы управления, которые избегают ставок, которые могут отрицательно сказаться на средствах игрока, или ограничивают значение ставок до% от доступных средств).
import tkinter as tk
import random
intro = """Panther's Den Slot Machine.
Welcome to my den!
You can win by rolling Ocelots, Jaguars, Boas, Caimans, Macaws or Tapirs.
You can also with big with three Ibis.
You'll lose a coin for anything else, and if you roll three Scorpions say good bye to 500 coins
Good luck kit!"""
def play():
global first, second, third
first = spin()
second = spin()
third = spin()
score()
def quit_play():
lbl.config(text = "Game has ended. You won a total of " + str(stake) + " coins")
def spin():
randomnumber = random.randint(0, 10)
return ITEMS[randomnumber]
def score():
global stake, first, second, third
if ((first == "OCELOT") and (second != "MACAW")):
win = 5 * bet
elif ((first == "JAGUAR") and (second == "JAGUAR") and (third != "JAGUAR")):
win = 8 * bet
elif ((first == "BOA") and (second == "BOA") and (third == "BOA")):
win = 10 * bet
elif ((first == "CAIMAN") and (second == "CAIMAN") and ((third == "CAIMAN") or (third == "BOA"))):
win = 8 * bet
elif ((first == "MACAW") and (second == "IBIS") and ((third == "MACAW"))):
win = 15 * bet
elif ((first == "TAPIR") and (second == "TAPIR") and ((third == "TAPIR"))):
win = 20 * bet
elif ((first == "IBIS") and (second == "IBIS") and (third == "IBIS")):
win = 300 * bet
elif ((first == "SCORPION") and (second == "SCORPION") and (third == "SCORPION")):
win = -500 * bet
else:
win = -1 * bet
stake += win
if (win > 0):
lbl.config(text = "{}\t{}\t{} -- You win {} Coins".format(first, second, third, win))
lbl2.config(text=stake)
else:
lbl.config(text = "{}\t{}\t{} -- You lose".format(first, second, third))
lbl2.config(text=stake)
def set_bet(value):
global bet
bet = int(value)
lbl2.config(text=str(bet))
root = tk.Tk()
root.geometry("700x500")
root.title("Slot Machine")
root.configure(background='seagreen')
INIT_STAKE = 100
ITEMS = ["OCELOT", "MACAW", "JAGUAR", "IBIS", "CAIMAN", "BOA", "SCORPION", "TAPIR", "CONDOR", "BAMBOO", "FROG"]
first = None
second = None
third = None
stake = INIT_STAKE
nameLabel = tk.Label(root, text = "PANTHER DEN", font=('Cambria', 60))
nameLabel.pack()
lbl = tk.Label(root, text=intro, background='seagreen', font=('Cambria', 12))
lbl.pack()
lbl2 = tk.Label(root, text=stake)
lbl2.pack()
tk.Button(root, text = "Play", command=play).pack()
tk.Button(root, text = "Quit", command=quit_play).pack()
tk.Button(root, text = "Exit", command=quit).pack()
bet = 0
bet_scale = tk.Scale(root, from_=0, to=stake, orient=tk.HORIZONTAL, length=200, bg='violet', command=set_bet)
bet_scale.pack()
root.mainloop()