-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMy_number.lua
More file actions
46 lines (40 loc) · 1.44 KB
/
Copy pathMy_number.lua
File metadata and controls
46 lines (40 loc) · 1.44 KB
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
-- Vérifie si l'entrée est valide et compare avec le nombre caché
function check(input, game_info)
if (input == nil or not (input < 100 and input > 0)) then
print("Write Number 1 to 100")
elseif (game_info.inconnu > input) then
print("Plus haut que ".. input)
game_info.count = game_info.count + 1
elseif (game_info.inconnu < input) then
print("Plus bas que ".. input)
game_info.count = game_info.count + 1
else
print("Bravos tu a gagnier")
game_info.status = "END"
end
end
-- Lance une partie complète du jeu
function game()
local game_info = {inconnu,status="RUN",count=0, nbr_game=0, restart="Y"}
print("Le jeu a commencer")
while (game_info.restart == "Y") do
-- Choisit un nombre aléatoire à deviner
math.randomseed(os.time())
math.random(); math.random(); math.random()
game_info.inconnu=math.random(100)
game_info.restart ="N"
game_info.status ="RUN"
game_info.count =0
game_info.nbr_game =game_info.nbr_game + 1
print("Game "..game_info.nbr_game)
while (game_info.status ~= "END") do
print("Nrombre d'essais " .. game_info.count)
-- Lit la proposition du joueur
local input = tonumber(io.read())
check(input, game_info)
end
print("Tu veux rejouer [Y/N]")
game_info.restart = io.read()
end
end
game()