TGC Codebase Backup



Simple Guess the Number game by ZoneMaster

6th Oct 2003 11:52
Summary

Has 10 skill levels. Guess a number from 1 to xxx.



Description

This is a simple Guess the Number game. Took me all of about 10 minutes to code. I am new to DarkBASIC but NOT BASIC in general. It has 10 skill levels and a very simple concept. A random number is generated, then you try and guess the number generated. Program will tell you if you are either to HIGH or LOW based on your input.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem simple guess the number game
rem 06/30/2003 by ZoneMaster; revised 10/06/2003
print "ZoneMaster's Guess the Number game."
print "-=-=-=10/06/2003 by ZoneMaster=-=-=-"
wait 4000

rem enter your skill level
begin:
cls:input "Enter your skill level (1-10): ";skill
if skill<1 or skill>10 then goto begin

rem setup the game variables
maxnum=10*skill:num=rnd(maxnum)+1:numguess=maxnum/2:x=0

rem start guessing the number
print "I am thinking of a number from 1 to ";maxnum;"."
for count = numguess to 1 step -1
	inc x
tryagain:
	input "You have ";count;" guesses remaining. Please enter your guess: ";guess
   if guess>maxnum or guess<1
      cls:goto tryagain
   endif
   if guess=num
		print:print "You're right, the number was ";num;"!"
		goto exit
   endif
   if guess>num then print "Your guess was too HIGH."
   if guess<num then print "Your guess was too LOW."

rem clears screen after 12 guesses and resets counter
if x=12
	wait 2000:cls:x=0
endif
next count

rem you ran out of guesses
print:print "I'm sorry, the number was ";num;"."

rem exit routine, play again or exit
exit:
input "Would you like to play again? (y/n) ";$yesno
if $yesno="y"
	cls:goto begin
endif
if $yesno="n"
	print:print "Thank you for playing!"
	end
endif
goto exit