News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Number Flash

Started by geecee, May 07, 2009, 04:11:45 AM

Previous topic - Next topic

geecee

Hi there!

Here's another short programme that I have adapted for Play Basic from a 1985 computer magazine ...... The conversion wasn't difficult but I've spruced it up a little.

I have posted the code here but it and the necessary media are in the attached Number Flash.zip file.

PlayBASIC Code: [Select]
remstart
=======================================================
Number Flash
*************************************************
Author: geecee
Adapted for Play Basic - May 2009
from a 1985 computer magazine
*************************************************
=======================================================
remend


rem ==========================================================================
rem Initialise programme
rem ==========================================================================

rem Tell PB to include the input support library
#include "Input"

rem Pre-load required fonts
font1 =loadnewfont("arial bold",22,0)
font2=loadNewfont("arial bold",40,0)

rem Pre-Load required media
NFBackdropimage=Loadnewimage("NumberFlashbackdrop.png")

rem This command will hide the mouse pointer
mouse off

rem Set text style and size
setfont font1

rem Determine text height
height=gettextheight("arial bold")

rem Set ink colour
ink rgb(255,217,128)

rem ==========================================================================
rem Programme Introduction
rem ==========================================================================

rem Display an image
drawimage NFBackdropimage,0,0,false

rem Write text to screen
centertext 400,270,"A number will flash on the screen. Remember it, and key it in"
centertext 400,300,"You score one point for each time you get it correct"

rem Display screen
sync

rem This do .. loop calls all the procedures in turn to play the game.
do
gosub play_game
gosub play_again
loop

rem End programme
end

rem ================================================================
rem Play game subroutine
rem ================================================================
play_game:

rem Draw a box to hide previous text at location
boxc 2,330,798,598,1,rgb(255,0,0)

rem Display screen
sync

rem A short wait before proceeding
wait 500

rem Write text to screen
centertext 400,330,"Click mouse to get number"

rem display screen
sync

rem Wait for mouse click
Waitmouse false, (1+2)
mb=mousebutton()

rem Wait until the mouse button is released
WaitNoInput

rem Determine random number
number=rnd(9998)+1

rem Write text to screen
centertext 400,360,number

rem Display screen
sync

rem A short wait before proceeding
wait 300

rem Draw a box to hide previous text at location
boxc 2,360,798,598,1,rgb(255,0,0)

rem Set cursor position and key in answer
setcursor 400-gettextwidth("Key in the number > "+"9999")/2,390
answer=val(staticinput("Key in the number > "))

rem If answer equals random number then increment score counter
if answer=number then score=score+1

rem Increment guesses counter
inc guesses

rem Write text to screen
centertext 400,500,"You have scored "+str$(score)+" out of "+str$(guesses)

return

rem ================================================================
rem Play again subroutine
rem ================================================================
play_again:

rem Write text to screen
centertext 400,540,"Left click mouse to continue ... Right click mouse to end"

rem Display screen
sync

rem Until mouse is clicked
repeat
mb=mousebutton()
until mb>0

rem If right mouse button is clicked
if mb=2

rem Set text style and size
setfont font2

StartTime=Timer()
repeat
boxc 0,0,798,598,1,rgb(255,0,0)
CurrentTime=Timer()
Timepast=ClipRange(Timer()-StartTime,1,1000)
Ink rgbfade(rgb(255,217,128),(1000-TimePast)/10.0)

Xpos= GetScreenWidth()/2
Ypos= GetScreenHeight()*0.40
Login required to view complete source code


:)
Enjoy
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

Koganwel

No « media », Geecee.

geecee

Sorry Koganwel ...... My error.

Now fixed.

:)
Cheers
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)