-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.lua
113 lines (103 loc) · 3.67 KB
/
game.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
local direction
function clearConsole()
if not os.execute("clear") then
os.execute("cls")
elseif not os.execute("cls") then
for i = 1,25 do
print("\n\n")
end
end
end
function detectKey(key, message)
repeat
io.write('Press "' .. key .. '" to continue ')
io.flush()
continueVar = io.read()
until continueVar ~= nil
end
function pickRandomCharacters()
local characters = {{name = "salesman", type = "friendly"}, {name = "wiseman", type = "friendly"}, {name = "weaponsmith", type = "friendly"}, {name = "stranger", type = "neutral"}, {name = "shifty salesman", type = "neutral"}, {name = "walker", type = "hostile"}, {name = "knight in dark armour", type = "hostile"}, {name = "archer", type = "hostile"}}
local characterPicked = characters[math.random(1, #characters)]
if characterPicked.type == "friendly" then
print("A " .. characterPicked.name .. " approachs you, he looks friendly")
elseif characterPicked.type == "neutral" then
print("You see a " .. characterPicked.name .. ", do you want to approach him?")
elseif characterPicked.type == "hostile" then
print("A " .. characterPicked.name .. " runs toward you!")
repeat
io.write('Do you want to fight "f", hide "h", or run "r"?')
io.flush()
enemyReaction = io.read()
until enemyReaction == "f" or "h" or "r"
if enemyReaction == "f" then
print("You decide to fight the " .. characterPicked.name)
end
end
function startRoom(direction)
print("You walk into the " .. direction .. " hallway...")
local stopWhen = math.random(1, 3)
pickRandomCharacters()
repeat
io.write('Press "Enter" to continue ')
io.flush()
continueVar = io.read()
until continueVar ~= nil
end
local answer
local yourName
print("You awaken in a strange hallway...")
print("You look in your pockets...")
print("You find a fuzzy picture, a trowel, and a worn book.")
local continueVar
repeat
io.write('Press "Enter" to continue ')
io.flush()
continueVar = io.read()
until continueVar ~= nil
clearConsole()
print("Holding the items, you decide to look at the photo, it seems familiar...")
print("You realize why, It's you!")
repeat
io.write("You can't seem to remember your name, so you decide to call yourself (type your name) ")
io.flush()
yourName = io.read()
until yourName ~= nil
print(yourName .. ", you like it, it seems perfect...")
print("\n")
print("After saying " .. yourName .. " several times, you remember the other items you are holding.")
print("You decide to read the book...")
print("\n")
print("My name is " .. yourName)
print("I don't know what happened to me, I was running down an ally, next thing I knew, I was clutching my head in pain.")
print("After I took in my suroundings (all I could see was what seemed to be mossy walls, and the light from a dim torch), I realized there was someone beside me.")
print('When "they" saw I was awake, they told me to "Find the keeper", then they left...')
io.write('You decide to dig, choose "d", then press "enter" to dig ')
io.flush()
local choice = io.read()
repeat
print("You find a sword, it appears to be quite old")
until choice == "d"
local pressedEnter = nil
repeat
io.write('Press "Enter" to continue')
io.flush()
pressedEnter = io.read()
until pressedEnter ~= nil
clearConsole()
repeat
local choice = nil
io.write('You decide to walk down the (left/right) hallway? ')
io.flush()
choice = io.read()
until choice == "left" or "right"
startRoom(choice)
score = nil
while score > 100 do
repeat
local choice = nil
io.write('You decide to walk down the (left/right) hallway? ')
io.flush()
choice = io.read()
until choice == "left" or "right"
startRoom(choice)
end