1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| ' WK4PROG8.BAS
' Here is an interactive HI-LO
' Program
'don't use a main window
nomainwin
[start]
guessMe = int(rnd(1)*100) + 1
' Clear the screen and print the title and instructions
notice "HI-LO" + chr$(13) + _
"I have decided on a number between one " + _
"and a hundred, and I want you to guess " + _
"what it is. I will tell you to guess " + _
"higher or lower, and we'll count up " + _
"the number of guesses you use."
'initialise le score
score = 10
[ask]
' Ask the user to guess the number and tally the guess
prompt "OK. What is your guess ?"; guess$
guess = val(guess$)
' Now add one to the count variable to count the guesses
let count = count + 1
' check to see if the guess is right
if guess = guessMe then goto [win]
' check to see if the guess is too low
if guess < guessMe then notice "Guess higher. The score is "+str$(score)
' check to see if the guess is too high
if guess > guessMe then notice "Guess lower. The score is "+str$(score)
'diminue le score
let score = score - 1
' si score nul, c'est fini
if score=0 then goto [fini]
' go back and ask again
goto [ask]
[win]
' beep once and tell how many guesses it took to win
beep
notice "You win! It took" + str$(count) + "guesses."
' reset the count variable to zero for the next game
let count = 0
' ask to play again
confirm "Play again (Y/N)?"; play$
if instr("YESyes", play$) > 0 then goto [start]
[fini]
end |
Partager