-
Notifications
You must be signed in to change notification settings - Fork 4
/
numguess.aca
62 lines (55 loc) · 1.46 KB
/
numguess.aca
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
#*
A number guessing game written in Acacia
CBerJun 2022.12.16
*#
# import the builtin modules
import print
import math
import schedule
const MAX_ANSWER = 999 # the last digit should be 9
answer: int
guess: int
player := Engroup[Entity]()
interface input:
#**
* Input 1 digit.
* Set the value of "input" on scoreboard "numguess" to the
* number user pressed.
*#
if guess <= MAX_ANSWER / 10:
# Make sure the input value is not larger than MAX_ANSWER
guess *= 10
guess += scb("input", "numguess")
interface delete:
#* Delete 1 digit. *#
guess /= 10
interface commit:
#* Submit user's guess *#
if guess == answer:
print.title("You win!", player)
print.title(
print.format("The answer is %0", answer),
player, print.SUBTITLE
)
player.clear()
elif guess > answer:
print.title("Too large", player)
else:
print.title("Too small", player)
interface start:
#* Start the game. *#
answer = math.randint(1, MAX_ANSWER)
guess = 0
player.select(Enfilter().all_players())
print.title("Guess the Number", player)
print.title(
print.format("Guess a number between 1~%0", MAX_ANSWER),
player, print.SUBTITLE
)
def show_guess():
#* Show users the number they input. *#
print.title(
print.format("Your guess: %0", guess),
player, print.ACTIONBAR
)
schedule.register_loop(show_guess)