-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock_paper_scissors.lua
executable file
·46 lines (42 loc) · 1.1 KB
/
rock_paper_scissors.lua
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
#!/usr/bin/lua
--[[
--
--author: derrick wakhu shibero
--]]
--
function game()
gen = math.fmod(math.random(1, 100), 3)
values = {"rock", "paper", "scissors"}
choice = ""
while choice == "" do
print("enter between rock, paper and scissors")
choice = io.read()
choice = string.lower(choice)
if choice ~= "rock" and choice ~= "paper" and choice ~= "scissors"then
choice = ""
end
end
if choice == values[gen + 1] then
print("it is a tie")
elseif values[gen+1] == "rock" and choice == "paper" then
print("you won")
elseif values[gen+1] == "paper" and choice == "scissors" then
print("you won")
elseif values[gen+1] == "scissors" and choice == "rock" then
print("you won")
else
print("you lost")
end
end
while true do
print("do you want to play reply with yes or no")
reply = io.read()
if string.lower(reply) == "no" or string.lower(reply) == "n" then
print("thank you for playing the game")
break
elseif string.lower(reply) == "yes" or string.lower(reply) == "y" then
game()
else
print("invalid input! please try again")
end
end