-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopyCat.kbs
112 lines (102 loc) · 2.54 KB
/
CopyCat.kbs
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
#CopyCat - A follow along memory game
# 2013-01-07 j.m.reneau
# requires BASIC256 0.9.9.25 or later3
# Revised by SPiNX Dec 22 2021 23:00. Native was misused as a variable round->rounds
pies = 5
dim lightcolors(1)
lightcolors = {red, blue, green, yellow, purple, cyan, orange}
dim darkcolors(1)
darkcolors = {darkred, darkblue, darkgreen, darkyellow, darkpurple, darkcyan, darkorange}
global pies, lightcolors, darkcolors, rounds
fastgraphics
dim game(100)
print "CopyCat"
print "See how long of a pattern you can remember. Click on the correct pie wedge when it is your turn."
do
input "How many pie slices (3-7)?", pies
until pies >=3 and pies <= 7
# generate the game
for t = 0 to game[?]-1
game[t] = int(rand*pies)
next t
rounds = 1
gameon = true
while gameon
# show the pattern
rounds++
print "Round " + rounds
for t = 0 to rounds -1
call showslice(100,300,game[t])
next t
#
# get the user to give it back
print " Play it back."
for t = 0 to rounds -1
g = getclick(3000,game[t])
if g = -1 then
# made a mistake - die
gameon = false
t = rounds
end if
next t
end while
print "You completed " + rounds + " rounds."
end
subroutine showslice(waittime, soundtime, slice)
pause waittime/1000
call drawgame(slice)
call playsound(slice, soundtime)
call drawgame(-1)
end subroutine
function getclick(timeout, slicetoclick)
# get the click before the timeout
start = msec
while msec<start+timeout and mouseb = 0
pause .01
end while
if msec>=start+timeout then
call drawgame(slicetoclick)
call playdie()
return -1
else
slice = -1
for t = 0 to pies-1
if pixel(mousex, mousey) = darkcolors[t] then slice = t
next t
if slice <> slicetoclick then
call drawgame(slicetoclick)
call playdie()
return -1
else
call drawgame(slice)
call playsound(slice, 250)
while mouseb <> 0
pause .01
end while
call drawgame(-1)
return slice
end if
end if
end function
subroutine playdie()
sound 100,500
say "you loose."
end subroutine
subroutine playsound(s, d)
sound 200+s*50,d
end subroutine
subroutine drawgame(sliceon)
# set slice number by passing its number (-1) nothing is on
clg
penwidth 1
w = 2*pi/pies
for t = 0 to pies-1
if t = sliceon then
color black,lightcolors[t]
else
color black,darkcolors[t]
end if
pie 0,0,300,300,t*w,w
next t
refresh
end subroutine