RANDOM NUMBER GAME
Author |
Message |
Dylan-182
![](http://i6.photobucket.com/albums/y207/Dylan-182/ying1.gif)
|
Posted: Sat May 21, 2005 12:11 am Post subject: RANDOM NUMBER GAME |
|
|
thi sis my random number game, im going to update it later and add a music selection screen aswell as music but until then here is my random number game
code: |
% AUTHOR : DYLAN CAUME
var randomNumber : int
var guess1 : int
var guess2 : int
var guess3 : int
var guess4 : int
var choice : int
colourback (black)
colour (brightred)
cls
locate (11, 32)
put "NUMBER GUESS"
delay (3000)
cls
locate (11, 25)
put "PLEASE CHOOSE A NUMBER RANGE"
put "1) 1 - 25"
put "2) 1 - 50"
put "3) 1 - 75"
put "4) 1 - 100"
% FIRST CHOICE
locate (13, 25)
get choice
if choice = 1 then
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 25"
randomNumber := Rand.Int (1, 25)
loop
locate (13, 25)
get guess1
if guess1 > randomNumber then
locate (14, 25)
put "TOO HIGH GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 25"
elsif guess1 < randomNumber then
locate (14, 25)
put "TOO LOW GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 25"
elsif guess1 = randomNumber then
locate (14, 25)
put "YOU GOT IT!!"
exit
end if
end loop
end if
%SECOND CHOICE
locate (13, 25)
if choice = 2 then
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 50"
randomNumber := Rand.Int (1, 50)
loop
locate (13, 25)
get guess2
if guess2 > randomNumber then
locate (14, 25)
put "TOO HIGH GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 50"
elsif guess2 < randomNumber then
locate (14, 25)
put "TOO LOW GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 50"
elsif guess2 = randomNumber then
locate (14, 25)
put "YOU GOT IT!!"
exit
end if
end loop
end if
%THIRD CHOICE
locate (13, 25)
if choice = 3 then
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 75"
randomNumber := Rand.Int (1, 75)
loop
locate (13, 25)
get guess3
if guess3 > randomNumber then
locate (14, 25)
put "TOO HIGH GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 75"
elsif guess3 < randomNumber then
locate (14, 25)
put "TOO LOW GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 75"
elsif guess3 = randomNumber then
locate (14, 25)
put "YOU GOT IT!!"
exit
end if
end loop
end if
% FOURTH CHOICE
locate (13, 25)
if choice = 4 then
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 100"
randomNumber := Rand.Int (1, 100)
loop
locate (13, 25)
get guess4
if guess4 > randomNumber then
locate (14, 25)
put "TOO HIGH GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 100"
elsif guess4 < randomNumber then
locate (14, 25)
put "TOO LOW GUESS AGAIN"
delay (2000)
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & 100"
elsif guess4 = randomNumber then
locate (14, 25)
put "YOU GOT IT!!"
exit
end if
end loop
end if
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dylan-182
![](http://i6.photobucket.com/albums/y207/Dylan-182/ying1.gif)
|
Posted: Sat May 21, 2005 12:13 am Post subject: (No subject) |
|
|
so there it is tell me what u think of it and any improvements you can think of for it ty and have fun ![Razz Razz](images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat May 21, 2005 8:18 am Post subject: (No subject) |
|
|
I thought you said you knew how to use loops and for loops and heck, even arrays. If so, why are you making this program? And why is it so many lines. And why is it not error-proofed?
Here's my version of your program, with the exact same output (except I reduced some of the long delays) only it's error proofed and comes in a bit more than 1/4 of the lines.
Turing: |
colourback (black)
colour (brightred)
cls
var theNum, guess, input_int, numberRange : int
var input_string : string
proc inputInteger (low, high : int)
loop
locate (13, 25)
get input_string
if strintok (input_string ) then
input_int := strint (input_string )
exit when input_int >= low and input_int <= high
end if
locate (13, 25)
put " "
end loop
end inputInteger
locate (11, 32)
put "NUMBER GUESS"
delay (1500)
cls
locate (11, 25)
put "PLEASE CHOOSE A NUMBER RANGE"
put "1) 1 - 25"
put "2) 1 - 50"
put "3) 1 - 75"
put "4) 1 - 100"
inputInteger (1, 4)
delay (500)
cls
numberRange := input_int * 25
theNum := Rand.Int (1, numberRange )
for i : 1 .. 4
cls
locate (11, 25)
put "PLEASE GUESS A NUMBER BETWEEN 1 & ", numberRange
inputInteger (1, numberRange )
locate (14, 25)
if input_int = theNum then
put "YOU GOT IT!"
exit
elsif i = 4 then
put "SORRY, YOU LOSE!"
elsif input_int < theNum then
put "TOO LOW GUESS AGAIN"
else
put "TOO HIGH GUESS AGAIN"
end if
delay (1500)
end for
|
You say you've learned loops & for loops & arrays, but I think, based on this program, that you should read the tutorials and make some programs using them. Check out the Turing Walkthrough for some program suggestions. |
|
|
|
|
![](images/spacer.gif) |
Dylan-182
![](http://i6.photobucket.com/albums/y207/Dylan-182/ying1.gif)
|
Posted: Sat May 21, 2005 4:09 pm Post subject: (No subject) |
|
|
lol yea i thought i knew em but i guess i have 2 review it some more i learned it years ago in my compsci classes ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|