-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lua
More file actions
59 lines (55 loc) · 1.58 KB
/
Copy pathgame.lua
File metadata and controls
59 lines (55 loc) · 1.58 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
47
48
49
50
51
52
53
54
55
56
57
58
59
require("data")
function describe_location()
local room = rooms[player.location]
print("\n" .. room.desc)
if room.enemy then
print("Enemy spotted: " .. room.enemy.name)
end
if room.item then
print("Item here: " .. room.item.name)
end
print("Exits: " .. table.concat(table.keys(room.exits), ", "))
end
function move(direction)
local room = rooms[player.location]
if room.exits[direction] then
player.location = room.exits[direction]
describe_location()
else
print("Can't go that way.")
end
end
function pickup()
local room = rooms[player.location]
if room.item then
table.insert(player.inventory, room.item)
print("Picked up: " .. room.item.name)
room.item = nil
else
print("Nothing to pick up here.")
end
end
function fight()
local room = rooms[player.location]
if room.enemy then
local enemy = room.enemy
print("Fighting " .. enemy.name .. "!")
while enemy.hp > 0 and player.hp > 0 do
enemy.hp = enemy.hp - 5 -- fixed player attack
print("Hit! " .. enemy.name .. " HP: " .. enemy.hp)
if enemy.hp <= 0 then
print(enemy.name .. " defeated!")
room.enemy = nil
break
end
player.hp = player.hp - enemy.attack
print("Ouch! Player HP: " .. player.hp)
if player.hp <= 0 then
print("You died! Game Over.")
os.exit()
end
end
else
print("No enemy here.")
end
end