%Set screen up
import GUI
%Declaration Section
var mainWin := Window.Open ("graphic: 640;200")
var key : string (1)
var number, randomNum : int
var try : int := 3
var mainMenuBtn, playBtn, quitBtn : int := 0
%Title
proc title
locate (1, 34)
put "Guessing Game"
end title
%Introduction
proc introduction
GUI.Refresh
title
locate (3, 1)
put "This program will allow you to guess a number between 10 and 65."
GUI.Show (mainMenuBtn)
GUI.Hide (playBtn)
GUI.Hide (quitBtn)
end introduction
%Main Menu
proc mainMenu
cls
GUI.Hide (mainMenuBtn)
GUI.Show (playBtn)
GUI.Show (quitBtn)
title
locate (3, 1)
put "Select a button to proceed to the destination you desire."
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 a number between 10 and 65."
locate (5, 1)
put "To proceed, please press any key" ..
loop
exit when hasch
end loop
Window.Close (windID1)
end errorMessage
%User Input
proc userInput
cls
introduction
GUI.Hide (mainMenuBtn)
randNum
try := 3
loop
locate (7, 1)
put ""
put ""
put ""
locate (7, 1)
put "Enter a number between 10 and 65: " ..
get number
if number < 10 or number > 65 then
errorMessage
userInput
end if
try := try - 1
locate (8, 1)
put "Tries remaining ", try
if try = 0 then
cls
locate (12, 28)
put "Sorry but you used all your tries"
delay (3000)
cls
GUI.Show (mainMenuBtn)
exit
end if
locate (9, 1)
if number = randomNum then
put "Good Job!"
delay (1000)
elsif number < randomNum then
put "Your guess is too low!"
delay (1000)
else
put "Your guess is too high!"
exit
end if
end loop
end userInput
%Good Bye
proc goodBye
var windID2 := Window.Open ("graphics:640;400")
Window.Close (mainWin)
locate (12, 25)
put "This program was brought to you by:"
locate (13, 35)
put "******** *******"
locate (14, 39)
put "Goodbye!"
delay (2500)
Window.Close (windID2)
end goodBye
%Buttons
mainMenuBtn := GUI.CreateButtonFull (260, 160, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (282, 220, 0, "Play Game", userInput, 0, '^P', false)
quitBtn := GUI.CreateButton (300, 130, 0, "Exit", GUI.Quit)
%Main Program
introduction
loop
exit when GUI.ProcessEvent
end loop
goodBye
%End of program |