-
Notifications
You must be signed in to change notification settings - Fork 5
/
numguess.prg
72 lines (67 loc) · 1.38 KB
/
numguess.prg
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
set talk off
set scoreboard off
set status off
? "Welcome to NumGuess dBase IV version!"
?
accept "Enter your name: " to name
if name = ""
name = "Player"
endif
?
accept "Welcome " + name + ", enter upper limit: " to limit
limit = val(limit)
if limit < 10
limit = 10
endif
maxtries = int(log(limit) / log(2)) + 1
do while .t.
num = int(rand(-1) * limit) + 1
tries = 0
?
? "Guess my number between 1 and " + ltrim(str(limit)) + "!"
?
do while .t.
accept "Guess: " to guess
if type(guess) = "N"
guess = val(guess)
if guess < 1 .or. guess > limit
? "Out of range."
else
tries = tries + 1
do case
case guess < num
? "Too low!"
case guess > num
? "Too high!"
otherwise
exit
endcase
endif
else
? "That's just plain wrong."
endif
enddo
triesword = iif(tries = 1, "try", "tries")
?
? "Well done " + name + ", you guessed my number from " + ltrim(str(tries)) + " " + triesword + "!"
do case
case tries = 1
? "You're one lucky bastard!"
case tries < maxtries
? "You are the master of this game!"
case tries = maxtries
? "You are a machine!"
case tries <= maxtries * 1.1
? "Very good result!"
case tries <= limit
? "Try harder, you can do better!"
otherwise
? "I find your lack of skill disturbing!"
endcase
accept "Play again [y/N]? " to again
if upper(again) <> "Y"
exit
endif
enddo
?
? "Okay, bye."