Sunday, November 24, 2013

Matching Cards

# Another game for the interactive whiteboard

Dim a$(4,3)
Dim value(4,3)
Dim pair(2)
Dim pair$(2)
font "arial",40,40
Graphsize 750,450
time = second+minute*60+hour*3600
QA = 0
# Atributing questions and answers########
do
n1=int(rand*9+1)
n2=int(rand*9+1)
question$=n1+"x"+n2
answer$ = string (n1*n2)
#################################
repetition = false
#checking for repetitions
for n=0 to 2
for m=0 to 3
if a$[m,n]=answer$ then repetition = true
next m
next n

if repetition = false then
#selecting 1 card for question
Q =0
do
v=int(rand*3)
h=int(rand*4)

if a$[h,v]="" then
a$[h,v]= question$
value[h,v]= int(answer$)
Q = 1
end if
until Q =1
#selecting 1 card for answer
A =0
do
v=int(rand*3)
h=int(rand*4)
if a$[h,v]="" then
a$[h,v]= answer$
value[h,v]= int(answer$)
A = 1
end if
until A =1
QA =QA +2
end if
until QA = 12


# Clicking the cards
cards=12
do
gosub drawcards
p=0
do
clickclear
t=0
do
if second+minute*60+hour*3600>t then
color white
rect 600,0,450,150
color black
text 600,40,second+minute*60+hour*3600 - time+" sec"
t=second+minute*60+hour*3600
end if
until clicky>0
x=int(clickx/150)
y=int(clicky/150)
pair[p]=value[x,y]
pair$[p]=a$[x,y]
p=p+1
color red
circle 150*x+20,150*y+20,10
until p=2
pause .5

if pair[0]=pair[1]and pair$[0]<>pair$[1] then
for n=0 to 3
for m=0 to 2
if value[n,m]=pair[1]then a$[n,m]="Yes"
next m
next n
cards=cards-2
end if
until cards=0

drawcards:
for n=0 to 3
for m=0 to 2
color black
if a$[n,m]="Yes" then color green
Rect 150*n,150*m,140,140
color white
text 150*n+20,150*m+40,a$[n,m]
next m
next n
return

end 

Friday, November 1, 2013

Estimate the angle

# This is a game designed to be played on an interactive whiteboard by two players

clg
fastgraphics
p1=0:p2=0
Bestof = 5
#Main ####################################
do

angle1=int(rand*360)
angle2=int(rand*360)
gosub drawscale
gosub drawpie
color white

text 170,280,"A turn"
refresh
gosub cliked
text 170,330,"Guess: "+guess+"º"
refresh
error1=abs(guess-angle1)
pause 1

text 470,280,"B turn"
refresh
gosub cliked
text 470,330,"Guess: "+guess+"º"
refresh
error2=abs(guess-angle2)
pause 1

gosub drawscale
gosub drawpie

color red
if error1<error2 then
win=200
p1=p1+1
color green
end if
text 170,330,"Real: "+angle1+"º"
text 170,380,"Error: "+error1+"º"
color red
if error1>error2 then
win=470
p2=p2+1
color green
end if
text 470,330,"Real: "+angle2+"º"
text 470,380,"Error: "+error2+"º"
color green
text win,150,"Winner"
refresh
pause 2
clg
until p1=Bestof or p2=Bestof
#End code####################################
color black
if p1=5 then text 270,320,"Player A won :)"
if p2=5 then text 270,320,"Player B won :)"
refresh
end
#Subroutines###################################
cliked:
clickclear
do
guess=mousey-7
until clicky>0
return

drawpie:
font "arial",30,100
text 170,10, "Palyer A: "+p1
text 470,10, "Player B: "+p2
color orange
pie ( 150,70,200,200,0,pi*angle1/180 )
color blue
pie ( 450,70,200,200,0,pi*angle2/180 )
return

drawscale:
font "arial",10,100
color black
graphsize 800,600
rect 0,0,800,600
color white
for y = 0 to 360 step 20
text 10,y,y
line 30,y+7,100,y+7
text 775,y,y
line 700,y+7,770,y+7
next y
refresh
return