WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , mx , my , mb , true , false
global whois , human , comp , cmem$ , hmem$ , comptel
winx = WindowWidth
winy = WindowHeight
true = not( false )
comp = 1
cmem$ = str$( int( rnd(0) * 4 ) )
comptel = 1
whois = comp
dim p$( 3 )
nomainwin
p$(0)=rect$(0,0,winx/2,winy/2,"pink")
p$(1)=rect$(0,winy/2,winx/2,winy,"blue")
p$(2)=rect$(winx/2,0,winx,winy/2,"red")
p$(3)=rect$(winx/2,winy/2,winx,winy,"green")
open "simon says" for graphics as #m
#m "trapclose [quit]"
#m "when leftButtonDown [leftDown]"
#m "when leftButtonUp [leftUp]"
#m "setfocus"
timer 500 , [tmr]
wait
[leftDown]
mx = MouseX
my = MouseY
mb = true
wait
[leftUp]
mb = false
wait
[tmr]
if whois = human then
if mb then
for i = 0 to 3
kl = hit( i , mx , my )
call draw i , kl
if kl then
hmem$ = hmem$ + str$( i )
end if
next i
else
for i = 0 to 3
call draw i , false
next i
end if
if len( cmem$ ) = len( hmem$ ) then
if cmem$ = hmem$ then
comptel = 1
whois = comp
else
timer 0
notice chr$( 13 )+ "Score : " ; len( hmem$ )
close #m
end
end if
end if
timer 500 , [tmr]
else
if comptel <= len( cmem$ ) then
kl = val( mid$( cmem$ , comptel , 1 ) )
else
kl = int( rnd(0) * 4 )
cmem$ = cmem$ + str$( kl )
comptel = 0
whois = human
end if
comptel = comptel + 1
for i = 0 to 3
if i = kl then
call draw i , true
else
call draw i , false
end if
next i
end if
wait
[quit]
close #m
end
function rect$( a , b , c , d , kl$ )
''constructor of rect objects
rect$ = str$( a ) + " " ; b ; " " ; c ; " " ; d _
; " " ; kl$
end function
function hit( i , x , y )
''look if x,y hit rect i
x1 = val( word$( p$( i ) , 1 ) )
y1 = val( word$( p$( i ) , 2 ) )
x2 = val( word$( p$( i ) , 3 ) )
y2 = val( word$( p$( i ) , 4 ) )
uit = true
if x < x1 or x > x2 then uit = false
if y < y1 or y > y2 then uit = false
hit = uit
end function
sub draw i , light
''draw rect i dark if not light
kl$ = word$( p$( i ) , 5 )
if not( light ) then
kl$ = "dark" + kl$
end if
x1 = val( word$( p$( i ) , 1 ) )
y1 = val( word$( p$( i ) , 2 ) )
x2 = val( word$( p$( i ) , 3 ) )
y2 = val( word$( p$( i ) , 4 ) )
#m "goto " ; x1 ; " " ; y1
#m "backcolor " ; kl$
#m "down"
#m "boxfilled " ; x2 ; " " ; y2
#m "up"
end sub