-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfruitGUIv1.py
More file actions
73 lines (66 loc) · 2.44 KB
/
Copy pathfruitGUIv1.py
File metadata and controls
73 lines (66 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#GUI VERSION
from guizero import App, Box, Text, Picture, PushButton
import random
#Actions
def checkWin():
global credit
credit = float(creditMoney.value[:4])
if bar1.value == "cherry.png":
if bar1.value == bar2.value == bar3.value:
print("Win: 3 ", bar1.value)
credit+=0.5
elif bar1.value == bar2.value:
print("Win: 2 ", bar1.value)
credit+=0.2
elif bar1.value == "bar.png":
if bar1.value == bar2.value == bar3.value:
print("Win: 3 ", bar1.value)
credit+=10.0
elif bar1.value == "lemon.png":
if bar1.value == bar2.value == bar3.value:
print("Win: 3 ", bar1.value)
credit+=1.0
elif bar1.value == "orange.png":
if bar1.value == bar2.value == bar3.value:
print("Win: 3 ", bar1.value)
credit+=2.0
elif bar1.value == "skull.png":
if bar1.value == bar2.value == bar3.value:
print("Unlucky! Lose because of 3 ", bar1.value)
credit = 0
credit = str(credit)
credit = credit[:4]
creditMoney.value = credit
def spinBars():
global credit
credit = float(creditMoney.value)
credit -= 0.20
credit = str(credit)
credit = credit[:4]
creditMoney.value = credit
bar1.value = random.choice(fruit)
bar2.value = random.choice(fruit)
bar3.value = random.choice(fruit)
checkWin()
def updateBalance():
global credit
credit = float(creditMoney.value)
credit = str(credit)
credit = credit[:4]
credit = 2.00
fruit = ["cherry.png","bar.png","cherry.png","lemon.png","orange.png","cherry.png","lemon.png","cherry.png","skull.png","orange.png","cherry.png"]
#Windows and Boxes
fruitMachine = App(title="Fruit Machine",width=400,height=600,layout="grid")
myMoney = Box(fruitMachine,layout="grid",grid=[0,0])
myButtons = Box(fruitMachine,layout="grid",grid=[0,1])
extraButtons = Box(fruitMachine,layout="grid",grid=[0,2])
#Text
creditText = Text(myMoney,text="CREDIT: £",size=16,grid=[0,0])
creditMoney = Text(myMoney,text=credit,size=16,grid=[1,0])
#Create and display bars
bar1 = Picture(myButtons,image="cherry.png",grid=[0,0])
bar2 = Picture(myButtons,image="cherry.png",grid=[1,0])
bar3 = Picture(myButtons,image="cherry.png",grid=[2,0])
spin = PushButton(myButtons,command=spinBars,text="SPIN",grid=[3,1])
#Run event loop for program
fruitMachine.display()