mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 14:50:54 -08:00
Create stars.ms
This commit is contained in:
48
00_Alternate_Languages/82_Stars/MiniScript/stars.ms
Normal file
48
00_Alternate_Languages/82_Stars/MiniScript/stars.ms
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
kMaxNum = 100
|
||||||
|
kTries = 7
|
||||||
|
|
||||||
|
instructions = function
|
||||||
|
print "I am thinking of a whole number from 1 to " + kMaxNum
|
||||||
|
print "Try to guess my number. After you guess, I"
|
||||||
|
print "will output one or more stars (*). The more"
|
||||||
|
print "stars I type, the closer you are to my number."
|
||||||
|
print "One star (*) means far away, seven stars (*******)"
|
||||||
|
print "means really close! You get " + kTries + " guesses."
|
||||||
|
print
|
||||||
|
end function
|
||||||
|
|
||||||
|
print " " * 34 + "STARS"
|
||||||
|
print " " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||||
|
print; print; print
|
||||||
|
|
||||||
|
ans = input("Do you want instructions? ").lower
|
||||||
|
if ans[0] == "y" then
|
||||||
|
instructions
|
||||||
|
end if
|
||||||
|
|
||||||
|
while 1
|
||||||
|
print
|
||||||
|
print "OK, I am thinking of a number, start guessing."
|
||||||
|
starNum = floor(rnd * kMaxNum) + 1
|
||||||
|
try = 0
|
||||||
|
while try < kTries
|
||||||
|
print
|
||||||
|
guess = input("Your guess: ").val
|
||||||
|
|
||||||
|
if guess == starNum then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
d = abs(guess - starNum)
|
||||||
|
print "*" * (7 - floor(log(d,2)))
|
||||||
|
end if
|
||||||
|
try += 1
|
||||||
|
end while
|
||||||
|
|
||||||
|
if try < kTries then
|
||||||
|
print "*" * 59
|
||||||
|
print "You got it in " + (try + 1) + " guesses! Let's play again."
|
||||||
|
else
|
||||||
|
print "Sorry, that's " + try + " guesses. The number was " + starNum
|
||||||
|
end if
|
||||||
|
print
|
||||||
|
end while
|
||||||
Reference in New Issue
Block a user