rem Countdown .... Rev 3.2 rem A J Tooth//February 2005 rem Setup screen and numbers proc_init repeat rem Setup screen and numbers proc_setup nc%=0 : cnt%=0 : br%=0 : ltim%=0 : rem Various flags and counters repeat rem Permit selection of numbers or a "(" area%=0 : sel%=0 proc_numselect area%=0 : sel%=0 rem Permit selection of arithmetic operation or a ")" proc_opselect until cnt%=6 or area%=9 or etim%>3000 rem Make sure any remaining open bracket is closed off rem and finish with a "equals" sign. if cnt%=6 then if br%=2 then Calc$=Calc$+")" : colour 4:print tab(5+nc%,15);")" : nc%+=2 colour 2:print tab(5+nc%,15);"=" endif rem Check result and keep score proc_rescore a$=get$ until a$<>" " end rem End of Program ========================================================= rem ======================================================================== rem Setup screen and numbers def proc_init rem Check the display size sys "GetSystemMetrics", 0 to xscreen% sys "GetSystemMetrics", 1 to yscreen% mode 22 sys "ShowWindow", @hwnd%, 3 : rem. SW_MAXIMIZE *REFRESH rem Prevent the window from being resized sys "GetWindowLong", @hwnd%, -16 to ws% sys "SetWindowLong", @hwnd%, -16, ws% and not &50000 dim nums%(6), seld%(6) Score%=0 : Game%=0 : per%=0 endproc rem ======================================================================== rem Message-with-background facility def proc_back(Xo%,Yo%,Msg$,Col%,Xs%,Ys%,Ws%,Hs%,Rr%,Gg%,Bb%) local h&,Rf&,Gf&,Bf& for h&=0 to 30 Rf&=int(Rr%*h&/30) : Gf&=int(Gg%*h&/30) : Bf&=int(Bb%*h&/30) colour 9,Rf&,Gf&,Bf& : gcol 9 rectangle fill Xs%+h&,Ys%+h&,Ws%-2*h&,Hs%-2*h& next h& vdu 5 move (Xs%+Xo%),(Ys%+Yo%) : gcol Col%: print;Msg$; *REFRESH vdu 4 endproc rem ======================================================================== rem Setup screen and numbers def proc_setup local i&,k& Calc$="" rem Pick the 6 utility numbers nums%(1)=25*rnd(4) for i&=2 to 6 nums%(i&)=rnd(10) next i& Ans%=100+rnd(900) : rem Pick target number seld%()=0 : rem Initialise selection array colour 128:cls: colour 3 msg$="TARGET IS: " *FONT Desdemona,20 proc_back(75,120,msg$,3,100,1100,450,200,100,100,100) *FONT Desdemona,30 msg$=str$(Ans%) proc_back(70,140,msg$,2,600,1100,300,200,100,120,100) rem Display arithmetic signs *FONT Desdemona,60 msg$="=" proc_back(50,180,msg$,5,1000,1100,190,200,120,120,100) *FONT Desdemona,60 msg$="+" proc_back(50,180,msg$,5,1200,1100,190,200,120,120,100) msg$="_" proc_back(50,260,msg$,5,1400,1100,190,200,120,120,100) *FONT Desdemona,60 msg$="*" proc_back(70,150,msg$,5,1600,1100,190,200,120,120,100) *FONT Desdemona,40 msg$="/" proc_back(70,160,msg$,5,1800,1100,190,200,120,120,100) *FONT Desdemona,40 msg$="(" proc_back(70,170,msg$,6,1000,1300,190,200,100,120,120) msg$=")" proc_back(70,170,msg$,6,1200,1300,190,200,100,120,120) *FONT Desdemona,25 msg$="Numbers are:" proc_back(75,120,msg$,3,100,800,600,200,110,100,100) for k&=1 to 6 msg$=str$(nums%(k&)) proc_back(65,120,msg$,1,800+50*(k&=1)+200*(k&-1),800,190-30*(k&=1),200,100,100,120) next k& rem Display Score msg$="Score" proc_back(65,120,msg$,11,100,1300,400,200,50,50,50) *FONT Desdemona,24 msg$=str$(Score%)+"/"+str$(10*Game%)+" "+str$(per%)+"%" proc_back(55,120,msg$,13,500,1300,500,200,50,50,50) rem Display my icon in compiled version proc_AJTicon(50,3*yscreen%/4) rem Initialise time counter tims%=time endproc rem ======================================================================== rem Select numbers or a "(" def proc_numselect if br%<>3 and br%<>2 and cnt%<6 then repeat if area%=0 then mouse on 136 mouse x%,y%,b% if y%>800 and y%<1000 then area%=0 if seld%(1)=0 and x%>800 and x%<990 then mouse on 0 : area%=1 if seld%(2)=0 and x%>1000 and x%<1190 then mouse on 0 : area%=2 if seld%(3)=0 and x%>1200 and x%<1390 then mouse on 0 : area%=3 if seld%(4)=0 and x%>1400 and x%<1590 then mouse on 0 : area%=4 if seld%(5)=0 and x%>1600 and x%<1790 then mouse on 0 : area%=5 if seld%(6)=0 and x%>1800 and x%<1990 then mouse on 0 : area%=6 else area%=0 if y%>1300 and y%<1500 then if br%=0 and x%>1000 and x%<1190 then mouse on 0 : area%=7 endif endif if area%>0 and b%=4 then sel%=area% if sel%=7 then br%=1 if sel%>0 and sel%<7 and br%=1 then br%=2 tim%=time : etim%=tim%-tims% if etim%-ltim%>50 then msg$=str$(int(etim%/100)) proc_back(55,150,msg$,13,1800,1300,190,200,int(etim%/20),0,0) ltim%=etim% endif until sel%>0 or etim%>3000 endif rem Make the selected number disappear if sel%>0 and sel%<7 then seld%(sel%)=1 : msg$="" : cnt%+=1 proc_back(65,120,msg$,0,800+50*(sel%=1)+200*(sel%-1),800,190-30*(sel%=1),200,0,0,0) nsel$=str$(nums%(sel%)) colour 3:print tab(5+nc%,15);nsel$ endif if sel%=7 then nsel$="(" colour 4:print tab(5+nc%,15);nsel$ endif if sel%>0 then Calc$=Calc$+nsel$ nc%+=1+len(nsel$) endif endproc rem ======================================================================== rem Permit selection of arithmetic operation or a ")" def proc_opselect if cnt%<6 and br%<>1 then repeat if area%=0 then mouse on 136 mouse x%,y%,b% if y%>1100 and y%<1300 then area%=0 if x%>1200 and x%<1390 then mouse on 0 : area%=1 if x%>1400 and x%<1590 then mouse on 0 : area%=2 if x%>1600 and x%<1790 then mouse on 0 : area%=3 if x%>1800 and x%<1990 then mouse on 0 : area%=4 if cnt%>1 and x%>1000 and x%<1190 then mouse on 0 : area%=9 else area%=0 if y%>1300 and y%<1500 then if br%=2 and x%>1200 and x%<1390 then mouse on 0 : area%=8 endif endif if area%>0 and b%=4 then sel%=area% if sel%>0 and sel%<>8 and br%=3 then br%=0 if sel%>0 and sel%<>8 and br%=2 then br%=1 if sel%=8 then br%=3 tim%=time : etim%=tim%-tims% if etim%-ltim%>50 then msg$=str$(int(etim%/100)) proc_back(55,150,msg$,13,1800,1300,190,200,int(etim%/20),0,0) ltim%=etim% endif until sel%>0 or etim%>3000 colour 2 case sel% of when 1: print tab(5+nc%,15);"+" : Calc$=Calc$+"+" when 2: print tab(5+nc%,15);"-" : Calc$=Calc$+"-" when 3: print tab(5+nc%,15);"*" : Calc$=Calc$+"*" when 4: print tab(5+nc%,15);"/" : Calc$=Calc$+"/" when 8: colour 4:print tab(5+nc%,15);")" : Calc$=Calc$+")" when 9: print tab(5+nc%,15);"=" endcase nc%+=2 endif endproc rem ======================================================================== rem Check result and keep score def proc_rescore if etim%<3001 then nc%+=2 : Res%=int(eval(Calc$)) if Res%=Ans% then colour 4: print tab(5+nc%,15);Res%;" ... is correct!" Score%+=10 else if abs(Res%-Ans%)<5 then colour 5: print tab(5+nc%,15);Res%;" ... is almost correct!" Score%+=5 else colour 1: print tab(5+nc%,15);Res%;" ... is incorrect!" endif endif else msg$=str$(30) proc_back(70,150,msg$,13,1800,1300,190,200,200,0,0) colour 1: print tab(5+nc%+2,15);" TIME OUT!" endif colour 2: print tab(15,17);"Press space-bar to continue." Game%+=1 per%=int(10*Score%/Game%) msg$=str$(Score%)+"/"+str$(10*Game%)+" "+str$(per%)+"%" proc_back(55,120,msg$,13,500,1300,500,200,50,50,50) endproc rem ======================================================================== rem Displays my Icon in .exe version def proc_AJTicon(i%,j%) sys "GetModuleHandle", 0 to hm% sys "LoadImage", hm%, "BBCWrun", 1, 32, 32, 0 to hicon% w% = 32 h% = 32 sys "DrawIconEx", @memhdc%, i%, j%, hicon%, w%, h%, 0, 0, 3 sys "InvalidateRect", @hwnd%, 0, 0 endproc rem ========================================================================