-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaingame2.py
More file actions
185 lines (162 loc) · 5.09 KB
/
maingame2.py
File metadata and controls
185 lines (162 loc) · 5.09 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import tkinter as tk
from tkinter import *
import random
from functools import partial
def main2():
n = 10 #this is the length of the list l
lngt = 900 // 15 #this is the dimension of the squares that I want
root= tk.Toplevel()
root.geometry("800x800")
root.title("MASTERMIND.")
root.iconbitmap('brain.ico')
root.configure(background='lightblue')
#to create a table of 4 rows on canvas
#each row should contain 4 squares
can =Canvas(root, width=800, height=800,bg='tomato2')
can.pack(side=LEFT)
for i in range(n):
y = i * lngt
for j in range(4):
x = j * lngt
can.create_rectangle(x, y, x+lngt, y+lngt, fill="wheat1")
orde=0
x0=10
x1=50
y0=10
y1=50
st=[]
trial=1
comp_generated=random.sample('brpgyon',4)
#functions
def Hint(i_l):
nonlocal x0,x1,y0,y1,trial,st,comp_generated
x0=250
x1=290
if i_l==comp_generated:
ss=Label(root,text='YOU DID IT',bg='Gold',font=('Showcard Gothic',30)).place(x=300,y=300)
elif trial==10:
ss=Label(root,text='Game Over',bg='Gold',font=('Showcard Gothic',30)).place(x=300,y=300)
root.after(1000, lambda: root.destroy())
else:
ss=Label(root,text='Try Again',bg='Gold',font=('Showcard Gothic',30))
ss.place(x=300,y=300)
root.after(500,ss.destroy)
for i in range(0,4):
if i_l[i] in comp_generated:
if i_l[i]==comp_generated[i]:
can.create_oval(x0,y0,x1,y1,fill='grey1')
x0+=60
x1+=60
else:
can.create_oval(x0,y0,x1,y1,fill='snow')
x0+=60
x1+=60
x0=10
x1=50
st*=0
trial+=1
y1+=60
y0+=60
def standby(col):
nonlocal x0,x1,y0,y1,orde,st
st.append(col)
if orde==4:
root.Click=PhotoImage(file='click.png')
b=Button(root,image=root.Click,command=partial(Hint,st),bg='tomato2').place(x=680,y=500)
orde=0
else:
pass
def g1():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='royal blue')
x0+=60
x1+=60
return standby('b')
def g2():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='red3')
x0+=60
x1+=60
return standby('r')
def g3():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='magenta4')
x0+=60
x1+=60
return standby('p')
def g4():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='olive drab')
x0+=60
x1+=60
return standby('g')
def g5():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='gold2')
x0+=60
x1+=60
return standby('y')
def g6():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='orange red')
x0+=60
x1+=60
return standby('o')
def g7():
nonlocal orde
orde+=1
nonlocal x0,x1,y0,y1
can.create_oval(x0,y0,x1,y1,fill='saddle brown')
x0+=60
x1+=60
return standby('n')
#1
root.loadimage1=PhotoImage(file="1b.png")
root.roundedbutton1=Button(root,image=root.loadimage1,command=g1)
root.roundedbutton1["bg"]='black'
root.roundedbutton1.place(x=700,y=150)
#2
root.loadimage2=PhotoImage(file="2r.png")
root.roundedbutton2=Button(root,image=root.loadimage2,command=g2)
root.roundedbutton2["bg"]='black'
root.roundedbutton2.place(x=700,y=200)
#3
root.loadimage3=PhotoImage(file="3p.png")
root.roundedbutton3=Button(root,image=root.loadimage3,command=g3)
root.roundedbutton3["bg"]='black'
root.roundedbutton3.place(x=700,y=250)
#4
root.loadimage4=PhotoImage(file="4g.png")
root.roundedbutton4=Button(root,image=root.loadimage4,command=g4)
root.roundedbutton4["bg"]='black'
root.roundedbutton4.place(x=700,y=300)
#5
root.loadimage5=PhotoImage(file="5y.png")
root.roundedbutton5=Button(root,image=root.loadimage5,command=g5)
root.roundedbutton5["bg"]='black'
root.roundedbutton5.place(x=700,y=350)
#6
root.loadimage6=PhotoImage(file="6o.png")
root.roundedbutton6=Button(root,image=root.loadimage6,command=g6)
root.roundedbutton6["bg"]='black'
root.roundedbutton6.place(x=700,y=400)
#7
root.loadimage7=PhotoImage(file="7br.png")
root.roundedbutton7=Button(root,image=root.loadimage7,command=g7)
root.roundedbutton7["bg"]='black'
root.roundedbutton7.place(x=700,y=450)
#MASTERMIND
l=Label(root,text='MASTERMIND',font=('Bernard MT Condensed','80'),bg='tomato2',fg='Black').place(x=150,y=650)
root.mainloop()