-
Notifications
You must be signed in to change notification settings - Fork 5
/
numguess.uvb
81 lines (62 loc) · 1.53 KB
/
numguess.uvb
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
73
74
75
76
77
78
79
80
81
SUBROUTINE NUMGUESS
RANDOMIZE
PROMPT ""
CRT "Welcome to NumGuess UniVerse Basic version!"
CRT
CRT "Enter your name: ":
INPUT NAME
IF NAME = "" THEN NAME = "Player"
CRT
CRT "Welcome ":NAME:", enter upper limit: ":
INPUT LIMIT
IF NOT(NUM(LIMIT)) OR LIMIT < 10 THEN LIMIT = 10
MAX.TRIES = INT(LN(LIMIT) / LN(2)) + 1
LOOP
NUM = RND(LIMIT) + 1
TRIES = 0
CRT
CRT "Guess my number between 1 and ":LIMIT:"!"
CRT
LOOP
CRT "Guess: ":
INPUT GUESS
TRIES += 1
BEGIN CASE
CASE NOT(NUM(GUESS))
CRT "That's just plain wrong."
TRIES -= 1
CASE GUESS < 1 OR GUESS > LIMIT
CRT "Out of range."
TRIES -= 1
CASE GUESS < NUM
CRT "Too low!"
CASE GUESS > NUM
CRT "Too high!"
END CASE
UNTIL GUESS = NUM
REPEAT
TRIES.WORD = "tries"
IF TRIES = 1 THEN TRIES.WORD = "try"
CRT
CRT "Well done ":NAME:", you guessed my number from ":TRIES:" ":TRIES.WORD:"!"
BEGIN CASE
CASE TRIES = 1
CRT "You're one lucky bastard!"
CASE TRIES < MAX.TRIES
CRT "You are the master of this game!"
CASE TRIES = MAX.TRIES
CRT "You are a machine!"
CASE TRIES <= MAX.TRIES * 1.1
CRT "Very good result!"
CASE TRIES <= LIMIT
CRT "Try harder, you can do better!"
CASE 1
CRT "I find your lack of skill disturbing!"
END CASE
CRT "Play again [y/N]? ":
INPUT AGAIN, 1
UNTIL UPCASE(AGAIN) # "Y"
REPEAT
CRT
CRT "Okay, bye."
END