UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: geecee on March 07, 2009, 11:20:04 PM

Title: Domino Magic
Post by: geecee on March 07, 2009, 11:20:04 PM
Another short programme ...... Domino Magic

Here you will need a Double-Six set of 28 dominoes.

[pbcode]
remstart
 =======================================================

                       DOMINO MAGIC
                 ***********************

                      Author: geecee
           Written for Play Basic - March 2009

                 ***********************

 =======================================================
remend

` Start of programme
start:

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

` This command will hide the mouse pointer
mouse off

` Declare array/s
;dim message$(4)

` Set down coordinate
down=30

` Set new ink colour
ink rgb(255,217,128)

` Define title
title$="DOMINO MAGIC"

` Set text style and size
loadfont "arial bold",1,30,0

`Write title to screen
centertext 400,down,title$

` A short wait before proceeding
sync
wait 3000

` Set text style and size
loadfont "arial bold",1,20,0

` Determine height of text
height=gettextheight("arial bold")

` Define message/s
message$="From a Double-Six set of 28 dominoes, choose any one ...... Press any key when ready."

` Write message/s to screen
centertext 400,down+height*4,message$

` Wait for a keypress
sync
waitkey
waitnokey

` Define message/s
message$="Multiply one of the numbers on the domino by 5 ...... Press any key when ready."

` Write message/s to screen
centertext 400,down+height*6,message$

sync
waitkey
waitnokey

` Define message/s
message$="Add 7 to the result ...... Press any key when ready."

` Write message/s to screen
centertext 400,down+height*8,message$

sync
waitkey
waitnokey

` Define message/s
message$="Multiply the sum by 2 ...... Press any key when ready."

` Write message/s to screen
centertext 400,down+height*10,message$

sync
waitkey
waitnokey

` Define message/s
message$="Add the other number on the domino ...... Press any key when ready."

` Write message/s to screen
centertext 400,down+height*12,message$

sync
waitkey
waitnokey

` Set cursor position and enter answer
setcursor 400-gettextwidth("Key in your answer >    ")/2,down+height*18
answer$=staticinput("Key in your answer > ")

sync
waitkey
waitnokey

` Determine chosen domino
chosen_domino$=str$(val(answer$)-14)
if val(chosen_domino$)<10 then chosen_domino$=chosen_domino$+"0"
first$=mid$(chosen_domino$,1,1):second$=mid$(chosen_domino$,2,1)

` Define message/s
message$="You chose the ...... "+first$+":"+second$+" domino"

` Write message/s to screen
centertext 400,down+height*20,message$
   
` A short wait before proceeding
sync
wait 3000

` Define message/s
message$="Correct? ...... Thank you"

` Determine width of message
tw=gettextwidth(message$)

` Where to write message to screen
text 400-tw/2,down+height*22,message$

sync
wait 1000

` Padding message of blank characters
x$="                                                             "

 ` Until the desired result is achieved
 repeat

   ` Set ink colour and draw a box to hide previous text at location
   ink rgb(0,0,0)
   box 10,479,790,500,1

   ` Set new ink colour
   ink rgb(255,217,128)

   ` Set cursor position   
   setcursor 0,500

   ` Decide if to try another
   answer$=staticinput(x$+"Try another [Y] or [N] > ")

 until answer$="Y" or answer$="y" or answer$="N" or answer$="n"  

` A short wait before proceeding
sync
wait 100

 if answer$="Y" or answer$="y"

   ` Set ink colour and draw a box to hide previous text at location
   ink rgb(0,0,0)
   box 10,60,790,590,1

   ` Set new ink colour
   ink rgb(255,217,128)

   ` A short wait before proceeding
   sync
   wait 3000

   ` Restart programme
   gosub start

 else

   ` Set ink colour and draw a box to hide previous text at location
   ink rgb(0,0,0)
   box 10,60,790,590,1

   ` Set new ink colour
   ink rgb(255,217,128)
 
   ` Set text style and size
   loadfont "arial bold",1,40,0
   
   ` Write message to screen
   centertext 400,300,"BYE!   THANKS FOR PLAYING"   
 
   ` Set text style and size
   loadfont "arial bold",1,20,0
   
   ` A short wait before proceeding
   sync
   wait 3000
   
   ` End programme
   end
 endif
[/pbcode]

As always, any comments constructive or otherwise appreciated.

:)
Enjoy.
geecee