zarta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/zarta +3 -0
- data/lib/zarta/dungeon.rb +134 -0
- data/lib/zarta/enemy.rb +125 -0
- data/lib/zarta/enemy.yml +289 -0
- data/lib/zarta/main.rb +214 -0
- data/lib/zarta/player.rb +188 -0
- data/lib/zarta/rooms.yml +368 -0
- data/lib/zarta/weapon.rb +67 -0
- data/lib/zarta/weapons.yml +300 -0
- data/lib/zarta.rb +8 -0
- data/tests/test_zarta.rb +93 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ca56c38e74daf18c8ca66174fdc0edbd2cab7a2
|
4
|
+
data.tar.gz: 4b69ae07c7a64cf98143f145e4f363bb8ac7ea87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04ec21909bb132f207238401b54e9ba7afb07a38040c8c584811513aebe6242aaf8d3f36e5f303095233516c280d120cfcf1fd3f8e6e5beb0064fffddc263bc3
|
7
|
+
data.tar.gz: f2b2811e023f6392d0f44c871c9285d1aa4c2e035f59e2f269d428792d96b4cf674b2cf6c638c8b6f9a40b9f020152ae8f364bd52bffc352fc45d00e189dbaca
|
data/bin/zarta
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
# The catch-all module for Zarta
|
4
|
+
module Zarta
|
5
|
+
# Keeps track of the dungeon. Mostly, this guy is used for passing all the
|
6
|
+
# other objects to each other and keeping track of a few things because I'm
|
7
|
+
# not allowed to use class variables for some reason...
|
8
|
+
class Dungeon
|
9
|
+
# The name of the dungeon
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
# The description of the dungeon
|
13
|
+
attr_accessor :description
|
14
|
+
|
15
|
+
# The deepest level of the dungeon
|
16
|
+
attr_accessor :max_level
|
17
|
+
|
18
|
+
# The level the player is currently on
|
19
|
+
attr_accessor :level
|
20
|
+
|
21
|
+
# An array of all possible room adjectives
|
22
|
+
attr_accessor :room_list
|
23
|
+
|
24
|
+
# A list of all possible weapon drops
|
25
|
+
attr_accessor :weapon_list
|
26
|
+
|
27
|
+
# A list of all possible enemy spawns
|
28
|
+
attr_accessor :enemy_list
|
29
|
+
|
30
|
+
# The number of rooms passed through since the last set of stairs.
|
31
|
+
attr_accessor :stairs_time
|
32
|
+
|
33
|
+
# The player
|
34
|
+
attr_accessor :player
|
35
|
+
|
36
|
+
# The current room
|
37
|
+
attr_accessor :room
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
load_yaml_files
|
41
|
+
|
42
|
+
@name = 'The Legendary Dungeon of ZARTA'
|
43
|
+
@description = 'The testiest test dungeon that ever tested!'
|
44
|
+
@max_level = 10
|
45
|
+
@level = 1
|
46
|
+
@stairs_time = 0
|
47
|
+
@player = Zarta::Player.new(self)
|
48
|
+
@room = Zarta::Room.new(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Moved him out for clarity and ease of editing. I know enemy isn't plural.
|
52
|
+
# It bugs me as well. It's on my list.
|
53
|
+
def load_yaml_files
|
54
|
+
@room_list = YAML.load_file(__dir__ + '/rooms.yml')
|
55
|
+
@weapon_list = YAML.load_file(__dir__ + '/weapons.yml')
|
56
|
+
@enemy_list = YAML.load_file(__dir__ + '/enemy.yml')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Where all the magic happens. Not really. Magic hasn't been implemented.
|
61
|
+
class Room
|
62
|
+
# The dungeon. The main guy. The big cheese.
|
63
|
+
attr_accessor :dungeon
|
64
|
+
|
65
|
+
# The description of the room
|
66
|
+
attr_accessor :description
|
67
|
+
|
68
|
+
# A list of rooms that are 'connected' to this one
|
69
|
+
attr_accessor :next_rooms
|
70
|
+
|
71
|
+
# If an enemy spawned in this room, he'll be in here
|
72
|
+
attr_accessor :enemy
|
73
|
+
|
74
|
+
# See above. Except this one is for weapons. If that wasn't clear.
|
75
|
+
attr_accessor :weapon
|
76
|
+
|
77
|
+
# Stairs, yes or no?
|
78
|
+
attr_accessor :stairs
|
79
|
+
|
80
|
+
def initialize(dungeon)
|
81
|
+
@dungeon = dungeon
|
82
|
+
@description = new_description
|
83
|
+
@next_rooms = [] # A list of room objects. Well, it will be.
|
84
|
+
@dungeon.stairs_time += 1
|
85
|
+
@stairs = false
|
86
|
+
|
87
|
+
@enemy = []
|
88
|
+
populate_room
|
89
|
+
end
|
90
|
+
|
91
|
+
# Buys itself something pretty. As long as its a random word from a yaml
|
92
|
+
# file.
|
93
|
+
def new_description
|
94
|
+
@dungeon.room_list[rand(0...@dungeon.room_list.length)]
|
95
|
+
end
|
96
|
+
|
97
|
+
# If anything exciting is going to happen in this room, it starts in here.
|
98
|
+
def populate_room
|
99
|
+
@enemy = Zarta::Enemy.new(@dungeon) if enemy_spawned
|
100
|
+
@weapon = Zarta::Weapon.new(@dungeon) if weapon_spawned
|
101
|
+
@stairs = stairs_spawned
|
102
|
+
end
|
103
|
+
|
104
|
+
# I can't call this in the initialization or else it will endlessly spawn
|
105
|
+
# rooms and break everything.
|
106
|
+
def new_rooms
|
107
|
+
min_rooms = MIN_NEXT_ROOMS
|
108
|
+
max_rooms = MAX_NEXT_ROOMS
|
109
|
+
rand(min_rooms..max_rooms).times do
|
110
|
+
@next_rooms << Zarta::Room.new(@dungeon)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# These next three functions handle the amazingly complex algorithm that
|
115
|
+
# determines if objects spawn in this room.
|
116
|
+
def enemy_spawned
|
117
|
+
enemy_chance = ENEMY_CHANCE_BASE + (@dungeon.level + ENEMY_CHANCE_MOD)
|
118
|
+
enemy_chance > rand(100)
|
119
|
+
end
|
120
|
+
|
121
|
+
def weapon_spawned
|
122
|
+
weapon_chance = WEAPON_CHANCE_BASE + (@dungeon.level + WEAPON_CHANCE_MOD)
|
123
|
+
weapon_chance > rand(100)
|
124
|
+
end
|
125
|
+
|
126
|
+
def stairs_spawned
|
127
|
+
return false if @dungeon.level == @dungeon.max_level
|
128
|
+
@dungeon.stairs_time += 1
|
129
|
+
return false unless STAIRS_CHANCE + @dungeon.stairs_time > rand(100)
|
130
|
+
@dungeon.stairs_time = 0
|
131
|
+
true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/zarta/enemy.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# The catch-all module for Zarta
|
2
|
+
module Zarta
|
3
|
+
# The enemy class
|
4
|
+
class Enemy
|
5
|
+
# The enemy's name
|
6
|
+
attr_accessor :name
|
7
|
+
|
8
|
+
# The enemy's current experience level
|
9
|
+
attr_accessor :level
|
10
|
+
|
11
|
+
# The enemy's current weapon
|
12
|
+
attr_accessor :weapon
|
13
|
+
|
14
|
+
# Did you kill him? Or did you run away? You probably ran away...
|
15
|
+
attr_accessor :dealt_with
|
16
|
+
|
17
|
+
def initialize(dungeon)
|
18
|
+
@dungeon = dungeon
|
19
|
+
@dealt_with = false
|
20
|
+
@player = @dungeon.player
|
21
|
+
|
22
|
+
pick_enemy
|
23
|
+
set_level
|
24
|
+
@health = set_health
|
25
|
+
@weapon = Zarta::Weapon.new(@dungeon)
|
26
|
+
@pastel = Pastel.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def pick_enemy
|
30
|
+
return if boss_spawn
|
31
|
+
spawn_list = []
|
32
|
+
chance = spawn_chance
|
33
|
+
@dungeon.enemy_list.each do |enemy|
|
34
|
+
spawn_list << enemy if enemy[:rarity] <= chance
|
35
|
+
end
|
36
|
+
|
37
|
+
spawn = spawn_list[rand(0...spawn_list.length)]
|
38
|
+
|
39
|
+
@name = spawn[:name]
|
40
|
+
@description = spawn[:description]
|
41
|
+
@rarity = spawn[:rarity]
|
42
|
+
end
|
43
|
+
|
44
|
+
def spawn_chance
|
45
|
+
rand(1..((@player.level + @dungeon.level) * SPAWN_CHANCE_MOD))
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_level
|
49
|
+
plevel = @dungeon.player.level
|
50
|
+
@level = rand((plevel - ENEMY_LEVEL_MIN_MOD)..
|
51
|
+
(plevel + ENEMY_LEVEL_MAX_MOD))
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_health
|
55
|
+
base = @rarity + @level + @dungeon.level + @dungeon.player.level
|
56
|
+
current_health = rand(base..base * ENEMY_MAX_HEALTH_MOD)
|
57
|
+
max_health = current_health
|
58
|
+
[current_health, max_health]
|
59
|
+
end
|
60
|
+
|
61
|
+
def take_damage(damage)
|
62
|
+
@health[0] -= damage
|
63
|
+
return unless @health[0] <= 0
|
64
|
+
# The enemy drops its weapon when killed. This will overwrite any weapon
|
65
|
+
# that may have spawned in the room.
|
66
|
+
@dungeon.room.weapon = @weapon
|
67
|
+
@dealt_with = true
|
68
|
+
end
|
69
|
+
|
70
|
+
def boss_spawn
|
71
|
+
return false if @dungeon.level < @dungeon.max_level
|
72
|
+
return false if rand(100) > @dungeon.stairs_time
|
73
|
+
|
74
|
+
@name = 'BOSS!'
|
75
|
+
@description = 'The BOSS!'
|
76
|
+
@rarity = @dungeon.level + BOSS_RARITY
|
77
|
+
|
78
|
+
set_level
|
79
|
+
set_health
|
80
|
+
@weapon = Zarta::Weapon.new(@dungeon)
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def enemy_turn
|
85
|
+
enemy_hit = enemy_damage
|
86
|
+
@player.take_damage(enemy_hit)
|
87
|
+
puts "The #{@pastel.magenta.bold(@name)} hits you!"
|
88
|
+
puts "You take #{@pastel.red.bold(enemy_hit)} damage."
|
89
|
+
gets
|
90
|
+
end
|
91
|
+
|
92
|
+
# This function and the player one should be moved into a single function.
|
93
|
+
# Just pass in the player or enemy.
|
94
|
+
def enemy_damage
|
95
|
+
base_damage = @weapon.damage + rand(@weapon.damage)
|
96
|
+
hit = base_damage + rand(@level) + @level
|
97
|
+
hit.round
|
98
|
+
end
|
99
|
+
|
100
|
+
def inspect
|
101
|
+
Zarta::HUD.new(@dungeon)
|
102
|
+
@pastel = Pastel.new
|
103
|
+
table_title
|
104
|
+
table
|
105
|
+
gets
|
106
|
+
end
|
107
|
+
|
108
|
+
def table_title
|
109
|
+
table_title = Terminal::Table.new
|
110
|
+
table_title.title = @pastel.magenta.bold(@name)
|
111
|
+
table_title.style = { width: 40, padding_left: 1 }
|
112
|
+
table_title.align_column(0, :center)
|
113
|
+
table_title.add_row [@description]
|
114
|
+
puts table_title
|
115
|
+
end
|
116
|
+
|
117
|
+
def table
|
118
|
+
table = Terminal::Table.new
|
119
|
+
table.style = { width: 40, padding_left: 1 }
|
120
|
+
table.add_row ['Weapon:', @weapon.name]
|
121
|
+
table.add_row ['Health:', "#{@health[0]}/#{@health[1]}"]
|
122
|
+
puts table
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/zarta/enemy.yml
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
---
|
2
|
+
-
|
3
|
+
:name: Ass Centaur
|
4
|
+
:description: 'No description yet'
|
5
|
+
:rarity: 6
|
6
|
+
-
|
7
|
+
:name: Balrog
|
8
|
+
:description: 'No description yet'
|
9
|
+
:rarity: 9
|
10
|
+
-
|
11
|
+
:name: Barrow-Wight
|
12
|
+
:description: 'No description yet'
|
13
|
+
:rarity: 6
|
14
|
+
-
|
15
|
+
:name: Basilisk
|
16
|
+
:description: 'No description yet'
|
17
|
+
:rarity: 3
|
18
|
+
-
|
19
|
+
:name: Cave-troll
|
20
|
+
:description: 'No description yet'
|
21
|
+
:rarity: 2
|
22
|
+
-
|
23
|
+
:name: Catoblepas
|
24
|
+
:description: 'No description yet'
|
25
|
+
:rarity: 6
|
26
|
+
-
|
27
|
+
:name: Centaur
|
28
|
+
:description: 'No description yet'
|
29
|
+
:rarity: 3
|
30
|
+
-
|
31
|
+
:name: Chimera
|
32
|
+
:description: 'No description yet'
|
33
|
+
:rarity: 6
|
34
|
+
-
|
35
|
+
:name: Cold-drake
|
36
|
+
:description: 'No description yet'
|
37
|
+
:rarity: 7
|
38
|
+
-
|
39
|
+
:name: Cyclops
|
40
|
+
:description: 'No description yet'
|
41
|
+
:rarity: 4
|
42
|
+
-
|
43
|
+
:name: Demon
|
44
|
+
:description: 'No description yet'
|
45
|
+
:rarity: 8
|
46
|
+
-
|
47
|
+
:name: Djinni
|
48
|
+
:description: 'No description yet'
|
49
|
+
:rarity: 6
|
50
|
+
-
|
51
|
+
:name: Dragon
|
52
|
+
:description: 'Huge and ferocious'
|
53
|
+
:rarity: 9
|
54
|
+
-
|
55
|
+
:name: Dryad
|
56
|
+
:description: 'No description yet'
|
57
|
+
:rarity: 4
|
58
|
+
-
|
59
|
+
:name: Dwarf
|
60
|
+
:description: 'No description yet'
|
61
|
+
:rarity: 2
|
62
|
+
-
|
63
|
+
:name: Elf
|
64
|
+
:description: 'No description yet'
|
65
|
+
:rarity: 2
|
66
|
+
-
|
67
|
+
:name: Ettin
|
68
|
+
:description: 'No description yet'
|
69
|
+
:rarity: 7
|
70
|
+
-
|
71
|
+
:name: Fox-maiden
|
72
|
+
:description: 'No description yet'
|
73
|
+
:rarity: 3
|
74
|
+
-
|
75
|
+
:name: Fire-drake
|
76
|
+
:description: 'No description yet'
|
77
|
+
:rarity: 8
|
78
|
+
-
|
79
|
+
:name: Frost-giant
|
80
|
+
:description: 'ICE COLD!'
|
81
|
+
:rarity: 7
|
82
|
+
-
|
83
|
+
:name: Gargoyle
|
84
|
+
:description: 'No description yet'
|
85
|
+
:rarity: 6
|
86
|
+
-
|
87
|
+
:name: Ghoul
|
88
|
+
:description: 'No description yet'
|
89
|
+
:rarity: 4
|
90
|
+
-
|
91
|
+
:name: Gnome
|
92
|
+
:description: 'No description yet'
|
93
|
+
:rarity: 3
|
94
|
+
-
|
95
|
+
:name: Goblin
|
96
|
+
:description: 'No description yet'
|
97
|
+
:rarity: 1
|
98
|
+
-
|
99
|
+
:name: Griffin
|
100
|
+
:description: 'No description yet'
|
101
|
+
:rarity: 6
|
102
|
+
-
|
103
|
+
:name: Hag
|
104
|
+
:description: 'No description yet'
|
105
|
+
:rarity: 4
|
106
|
+
-
|
107
|
+
:name: Half-orc
|
108
|
+
:description: 'No description yet'
|
109
|
+
:rarity: 1
|
110
|
+
-
|
111
|
+
:name: Half-troll
|
112
|
+
:description: 'No description yet'
|
113
|
+
:rarity: 2
|
114
|
+
-
|
115
|
+
:name: Harpy
|
116
|
+
:description: 'No description yet'
|
117
|
+
:rarity: 2
|
118
|
+
-
|
119
|
+
:name: Hill-man
|
120
|
+
:description: 'No description yet'
|
121
|
+
:rarity: 5
|
122
|
+
-
|
123
|
+
:name: Hill-troll
|
124
|
+
:description: 'No description yet'
|
125
|
+
:rarity: 4
|
126
|
+
-
|
127
|
+
:name: Hippogriff
|
128
|
+
:description: 'No description yet'
|
129
|
+
:rarity: 4
|
130
|
+
-
|
131
|
+
:name: Hobgoblin
|
132
|
+
:description: 'No description yet'
|
133
|
+
:rarity: 1
|
134
|
+
-
|
135
|
+
:name: Kobold
|
136
|
+
:description: 'No description yet'
|
137
|
+
:rarity: 1
|
138
|
+
-
|
139
|
+
:name: Kraken
|
140
|
+
:description: 'No description yet'
|
141
|
+
:rarity: 5
|
142
|
+
-
|
143
|
+
:name: Leprechaun
|
144
|
+
:description: 'No description yet'
|
145
|
+
:rarity: 10
|
146
|
+
-
|
147
|
+
:name: Leviathan
|
148
|
+
:description: 'No description yet'
|
149
|
+
:rarity: 7
|
150
|
+
-
|
151
|
+
:name: Long-worm
|
152
|
+
:description: 'No description yet'
|
153
|
+
:rarity: 2
|
154
|
+
-
|
155
|
+
:name: Manticore
|
156
|
+
:description: 'No description yet'
|
157
|
+
:rarity: 5
|
158
|
+
-
|
159
|
+
:name: Medusa
|
160
|
+
:description: 'No description yet'
|
161
|
+
:rarity: 6
|
162
|
+
-
|
163
|
+
:name: Mermaid
|
164
|
+
:description: 'No description yet'
|
165
|
+
:rarity: 8
|
166
|
+
-
|
167
|
+
:name: Minotaur
|
168
|
+
:description: 'No description yet'
|
169
|
+
:rarity: 4
|
170
|
+
-
|
171
|
+
:name: Mountain-troll
|
172
|
+
:description: 'No description yet'
|
173
|
+
:rarity: 3
|
174
|
+
-
|
175
|
+
:name: Naga
|
176
|
+
:description: 'No description yet'
|
177
|
+
:rarity: 3
|
178
|
+
-
|
179
|
+
:name: Nasir
|
180
|
+
:description: 'No description yet'
|
181
|
+
:rarity: 7
|
182
|
+
-
|
183
|
+
:name: Necromancer
|
184
|
+
:description: 'No description yet'
|
185
|
+
:rarity: 5
|
186
|
+
-
|
187
|
+
:name: Ogre
|
188
|
+
:description: 'No description yet'
|
189
|
+
:rarity: 2
|
190
|
+
-
|
191
|
+
:name: Orc
|
192
|
+
:description: 'Warlike green beast!'
|
193
|
+
:rarity: 1
|
194
|
+
-
|
195
|
+
:name: Pegasus
|
196
|
+
:description: 'No description yet'
|
197
|
+
:rarity: 8
|
198
|
+
-
|
199
|
+
:name: Salamander
|
200
|
+
:description: 'No description yet'
|
201
|
+
:rarity: 2
|
202
|
+
-
|
203
|
+
:name: Scorpion-man
|
204
|
+
:description: 'No description yet'
|
205
|
+
:rarity: 5
|
206
|
+
-
|
207
|
+
:name: Shadow Host
|
208
|
+
:description: 'No description yet'
|
209
|
+
:rarity: 8
|
210
|
+
-
|
211
|
+
:name: Silent Watcher
|
212
|
+
:description: 'No description yet'
|
213
|
+
:rarity: 5
|
214
|
+
-
|
215
|
+
:name: Snow-troll
|
216
|
+
:description: 'No description yet'
|
217
|
+
:rarity: 4
|
218
|
+
-
|
219
|
+
:name: Sphinx
|
220
|
+
:description: 'No description yet'
|
221
|
+
:rarity: 7
|
222
|
+
-
|
223
|
+
:name: Spider
|
224
|
+
:description: 'No description yet'
|
225
|
+
:rarity: 1
|
226
|
+
-
|
227
|
+
:name: Stone-giant
|
228
|
+
:description: 'No description yet'
|
229
|
+
:rarity: 5
|
230
|
+
-
|
231
|
+
:name: Stone-troll
|
232
|
+
:description: 'No description yet'
|
233
|
+
:rarity: 3
|
234
|
+
-
|
235
|
+
:name: Succubus
|
236
|
+
:description: 'No description yet'
|
237
|
+
:rarity: 4
|
238
|
+
-
|
239
|
+
:name: Sun-lizard
|
240
|
+
:description: 'No description yet'
|
241
|
+
:rarity: 2
|
242
|
+
-
|
243
|
+
:name: Tengu
|
244
|
+
:description: 'No description yet'
|
245
|
+
:rarity: 4
|
246
|
+
-
|
247
|
+
:name: Troll
|
248
|
+
:description: 'No description yet'
|
249
|
+
:rarity: 2
|
250
|
+
-
|
251
|
+
:name: Two-headed troll
|
252
|
+
:description: 'No description yet'
|
253
|
+
:rarity: 3
|
254
|
+
-
|
255
|
+
:name: Unicorn
|
256
|
+
:description: 'Mystic rare creature'
|
257
|
+
:rarity: 10
|
258
|
+
-
|
259
|
+
:name: Vampire
|
260
|
+
:description: 'No description yet'
|
261
|
+
:rarity: 4
|
262
|
+
-
|
263
|
+
:name: Vampire Bat
|
264
|
+
:description: 'No description yet'
|
265
|
+
:rarity: 2
|
266
|
+
-
|
267
|
+
:name: Were-worm
|
268
|
+
:description: 'No description yet'
|
269
|
+
:rarity: 5
|
270
|
+
-
|
271
|
+
:name: Werewolf
|
272
|
+
:description: 'No description yet'
|
273
|
+
:rarity: 4
|
274
|
+
-
|
275
|
+
:name: Winged Beast
|
276
|
+
:description: 'No description yet'
|
277
|
+
:rarity: 2
|
278
|
+
-
|
279
|
+
:name: Wolf
|
280
|
+
:description: 'No description yet'
|
281
|
+
:rarity: 1
|
282
|
+
-
|
283
|
+
:name: Worm
|
284
|
+
:description: 'No description yet'
|
285
|
+
:rarity: 1
|
286
|
+
-
|
287
|
+
:name: Wyvern
|
288
|
+
:description: 'No description yet'
|
289
|
+
:rarity: 3
|