/******************************/
/* High-Low Game */
/* This program will ask the */
/* user a to guess a random */
/* number and will tell them */
/* whether it is lower, higher*/
/* or is the number */
/******************************/
% The music that will play through the game
process music
loop
play ("4CDEFG5CDEFG6CCCDDDEEEFFFGGG2ACDE1CC2DEF1GGFDE8CCCDDDEEEFFF2ACED8GGGCCCDDDEEEFFF2ACED8GGGCCCDDDEEE")
end loop
end music
fork music
% Variables
var num, ans : int % the random number and the users answer
var font1 : int
var any : string (1) % for the getch command
var name : string % the users name
var count : int := 0 % to tally the users guesses
var aver : real
% Title Screen
% The intro screen to show that the game started
drawfillbox (0, 0, 700, 400, 2)
font1 := Font.New ("lithograph:30:italic")
assert font1 > 0
Font.Draw ("Highs and Lows", 130, 192, font1, red)
for y : 90 .. 120
drawarc (200, y, 120, 50, 0, 180, 7)
drawarc (440, y, 120, 50, 180, 0, 7)
delay (50)
end for
locate (23, 30)
colorback (2)
put "Press any key to continue"
locate (25, 43)
getch (any)
cls
% Instruction Screen
% Will inform the user of what to do and will get the users name
put "Lets start with your name. What is it?"
get name
put "Well ", name, " let me tell you the rules before we start."
getch (any)
put "This is a high low game, so you have to guess a random number between 1 and 100."
getch (any)
put "Please don't put any numbers over 100 or under 1."
delay (2500)
put "Ok, now that you have an idea of what to do, lets get started!"
put "Press Any Key"
getch (any)
cls
% High-Low Code
% will repeat if user wants to
loop
% To tally the amount of times it was played
var plays : real := 0
plays := plays + 1
% The random number that will be guessed
randomize
randint (num, 1, 100)
put "Guess a number between 1 and 100"
loop
get ans
% To see if the user gets the number right
% This will repeat if the user gets it wrong, will exit when the user guesses it right
if ans > 100
then
put "Please keep it below 100"
count := count + 1
elsif ans < 1
then
put "Please keep it above 1"
count := count + 1
elsif ans = num
then
put "You guessed right"
count := count + 1
elsif ans > num
then
put "Nope, your too high. Guess again"
count := count + 1
elsif ans < num
then
put "Nope, your too low. Guess again"
end if
exit when ans = num
end loop
delay (2000)
cls
% Info for the users to see their average and amount of tries
aver := count / plays
put "", name, " it took you ", count, " tries to guess the number."
put "Your average amount of guesses is:", aver
put "Would like to countinue?y/n"
getch (any)
cls
% If the user chooses to quit, the game will end
if any = "n"
then
cls
put "Thanks for playing!"
exit when any = "n"
end if
end loop |