You are on page 1of 5

from graphics import*

import random
import time
import sys

pattern = []
#o is the amount of times the game will run - 1
o= 100000

#choose if you want to play easy or hard mode


gamemode = input("Please enter if you want easy or hard mode (hard mode is 75 percent faster): ")

#easy mode
if (gamemode[0] == 'e'):
#Graphic window
win = GraphWin(title = "Simon Says", width = 300, height = 300)

gbutton = Rectangle(Point(50,50),Point(150,150))
rbutton = Rectangle(Point(150,50),Point(250,150))
ybutton = Rectangle(Point(50,150),Point(150,250))
bbutton = Rectangle(Point(150,150),Point(250,250))
gb = Rectangle(Point(60,60),Point(140,140))
rb = Rectangle(Point(160,60),Point(240,140))
yb = Rectangle(Point(60,160),Point(140,240))
bb = Rectangle(Point(160,160),Point(240,240))
gb.setFill(color_rgb(204,255,204))
rb.setFill(color_rgb(255,204,204))
yb.setFill(color_rgb(255,255,204))
bb.setFill(color_rgb(204,204,255))
gbutton.setFill("green")
rbutton.setFill("red")
ybutton.setFill("yellow")
bbutton.setFill("blue")
gbutton.draw(win)
rbutton.draw(win)
ybutton.draw(win)
bbutton.draw(win)

ready = Text(Point(50,25),"Ready...")
ready.setTextColor("red")
ready.draw(win)
time.sleep(2)
ready.undraw()

sett = Text(Point(150,25),"Set...")
sett.setTextColor("yellow")
sett.draw(win)
time.sleep(2)
sett.undraw()

go = Text(Point(250,25),"Go!")
go.setTextColor("green")
go.draw(win)
time.sleep(2)
go.undraw()

yes = Text(Point(150,275), (" "))


yes.draw(win)

time.sleep(1)
#loop to start the game

for y in range(o):
# Append 1 color to pattern
score = 0

z = random.randint(1,4)
if z == 1:
pattern.append('green')
elif z == 2:
pattern.append('red')
elif z == 3:
pattern.append('yellow')
else:
pattern.append('blue')

# Show computer pattern


for clr in pattern:
if clr == 'green':
gb.draw(win)
time.sleep(1)
gb.undraw()
time.sleep(0.1)

elif clr == 'red':


rb.draw(win)
time.sleep(1)
rb.undraw()
time.sleep(0.1)

elif clr == 'yellow':


yb.draw(win)
time.sleep(1)
yb.undraw()
time.sleep(0.1)

else:
bb.draw(win)
time.sleep(1)
bb.undraw()
time.sleep(0.1)

# Wait for human pattern


i=0
while i < len(pattern):

click = win.getMouse()
p = click.getX()
h = click.getY()

if (50<p<150 and 50<h<150 and pattern[i] == 'green'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.2)
correct.undraw()

elif(150<p<250 and 50<h<150 and pattern[i] == 'red'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.2)
correct.undraw()

elif(50<p<150 and 150<h<250 and pattern[i] == 'yellow'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.2)
correct.undraw()
elif(150<p<250 and 150<h<250 and pattern[i] == 'blue'):
correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.2)
correct.undraw()

else:
lose = Text(Point(150,20), "You lost! Press E to exit the game.")
lose.setSize(10)
lose.draw(win)
exit = win.getKey()
if(exit == 'e'):
sys.exit()
else:
continue

break
i += 1
score+=1
yes.setText(score)

# Pause for a moment before receiving the next pattern


time.sleep(3)

#hard mode(75% faster)


elif (gamemode[0] == 'h'):
win = GraphWin(title = "Simon Says", width = 300, height = 300)

gbutton = Rectangle(Point(50,50),Point(150,150))
rbutton = Rectangle(Point(150,50),Point(250,150))
ybutton = Rectangle(Point(50,150),Point(150,250))
bbutton = Rectangle(Point(150,150),Point(250,250))
gb = Rectangle(Point(60,60),Point(140,140))
rb = Rectangle(Point(160,60),Point(240,140))
yb = Rectangle(Point(60,160),Point(140,240))
bb = Rectangle(Point(160,160),Point(240,240))
gb.setFill(color_rgb(204,255,204))
rb.setFill(color_rgb(255,204,204))
yb.setFill(color_rgb(255,255,204))
bb.setFill(color_rgb(204,204,255))
gbutton.setFill("green")
rbutton.setFill("red")
ybutton.setFill("yellow")
bbutton.setFill("blue")
gbutton.draw(win)
rbutton.draw(win)
ybutton.draw(win)
bbutton.draw(win)

ready = Text(Point(50,25),"Ready...")
ready.setTextColor("red")
ready.draw(win)
time.sleep(2)
ready.undraw()

sett = Text(Point(150,25),"Set...")
sett.setTextColor("yellow")
sett.draw(win)
time.sleep(2)
sett.undraw()

go = Text(Point(250,25),"Go!")
go.setTextColor("green")
go.draw(win)
time.sleep(2)
go.undraw()

yes = Text(Point(150,275), (" "))


yes.draw(win)

time.sleep(1)
for y in range(o):
# Append 1 color to pattern
score = 0

z = random.randint(1,4)
if z == 1:
pattern.append('green')
elif z == 2:
pattern.append('red')
elif z == 3:
pattern.append('yellow')
else:
pattern.append('blue')

# Show computer pattern


for clr in pattern:
if clr == 'green':
gb.draw(win)
time.sleep(.25)
gb.undraw()
time.sleep(0.1)

elif clr == 'red':


rb.draw(win)
time.sleep(.25)
rb.undraw()
time.sleep(0.1)

elif clr == 'yellow':


yb.draw(win)
time.sleep(.25)
yb.undraw()
time.sleep(0.1)

else:
bb.draw(win)
time.sleep(.25)
bb.undraw()
time.sleep(0.1)

# Wait for human pattern


i=0
while i < len(pattern):

click = win.getMouse()
p = click.getX()
h = click.getY()

if (50<p<150 and 50<h<150 and pattern[i] == 'green'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.1)
correct.undraw()

elif(150<p<250 and 50<h<150 and pattern[i] == 'red'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.1)
correct.undraw()

elif(50<p<150 and 150<h<250 and pattern[i] == 'yellow'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.1)
correct.undraw()

elif(150<p<250 and 150<h<250 and pattern[i] == 'blue'):


correct = Text(Point(150,25), "Correct!")
correct.setSize(18)
correct.draw(win)
time.sleep(.1)
correct.undraw()

else:
lose = Text(Point(150,20), "You lost! Press E to exit the game.")
lose.setSize(10)
lose.draw(win)
exit = win.getKey()
if(exit == 'e'):
sys.exit()
else:
continue

break
i += 1
score+=1
yes.setText(score)

# Pause for a moment before receiving the next pattern


time.sleep(1.5)
else:
print(" ")

You might also like