%Set screen up
import GUI
setscreen ("graphics")
%Declaration Section
var mainWin := Window.Open ("graphic: 640;200")
var key : string (1)
var number, randomNum : int
var try : int := 3
var mainMenuBtn, playBtn, nextBtn, quitBtn : int := 0
%Title
proc title
locate (1, 36)
put "Math Game"
end title
%Introduction
proc introduction
GUI.Refresh
title
locate (3, 1)
put "This program will be testing your math skills."
GUI.Show (mainMenuBtn)
GUI.Hide (nextBtn)
GUI.Hide (playBtn)
GUI.Hide (quitBtn)
end introduction
%Main Menu
proc mainMenu
cls
GUI.Hide (mainMenuBtn)
GUI.Hide (nextBtn)
GUI.Show (playBtn)
GUI.Show (quitBtn)
title
locate (3, 1)
put "To proceed, please press any of the below buttons."
GUI.Refresh
end mainMenu
%Random Number
proc randNum
randint (randomNum, 10, 65)
end randNum
%User input's error message
proc errorMessage
var windID1 := Window.Open ("position:300;300,graphics: 330;100")
locate (1, 1)
put "Please enter 1, 2, 3 or 4."
locate (5, 1)
put "To proceed, please press any key" ..
loop
exit when hasch
end loop
Window.Close (windID1)
end errorMessage
%Display
proc display
GUI.Show (mainMenuBtn)
title
try := -1
randNum
if number = randomNum then
locate (3, 1)
put "Good Job!"
put "Tries remaining: ", try
elsif number < randomNum then
put "Too low!"
put "Tries remaining:", try
else
put "Your guess is too high!"
put "Tries remaining:", try
end if
if try = 0 then
locate (6, 1)
put "The random number chosen was: ", randomNum
end if
end display
%User Input
proc userInput
cls
title
locate (3, 1)
put "How do you calculate the volume of a prism? " ..
locate (5, 1)
put "1.V = Area of base x height"
put "2.V = 1/3 x area of base x height"
put "3.V = Base x 1/3 x base x height"
put "4.V = Base x Height"
put "Answer: " ..
get number
GUI.Show (nextBtn)
GUI.Hide (mainMenuBtn)
if number < 1 or number > 5 then
errorMessage
userInput
else
end if
display
end userInput
%Good Bye
proc goodBye
var windID2 := Window.Open ("graphics:640;400")
Window.Close (mainWin)
locate (12, 29)
put "This program was written by:"
locate (13, 35)
put "******** *******"
locate (14, 39)
put "Goodbye!"
delay (2500)
Window.Close (windID2)
end goodBye
%Buttons
mainMenuBtn := GUI.CreateButtonFull (270, 160, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (282, 220, 0, "Start Game", userInput, 0, '^P', false)
nextBtn := GUI.CreateButtonFull (400, 100, 0, "Next", userInput, 0, '^N', false)
quitBtn := GUI.CreateButton (300, 100, 0, "Exit", GUI.Quit)
%Main Program
introduction
loop
exit when GUI.ProcessEvent
end loop
goodBye
%End of program
|