forked from reedlaw/ruby-mmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.rb
executable file
·60 lines (49 loc) · 1.54 KB
/
engine.rb
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
#!/usr/bin/env ruby
require 'debugger'
#This creates the require_dir method that is used for requiring the engine, players, and monsters directories below
def require_dir(dir)
Dir["#{dir}/*.rb"].each do |file|
require File.join(File.dirname(__FILE__), file )
end
end
#This requires the engine directory
require_dir("engine")
modules = []
ObjectSpace.each_object(Module) {|m| modules << m.name } #Traverses all objects that are modules or subclasses of modules
#And adds them to the modules array
require_dir("players")
player_modules = []
ObjectSpace.each_object(Module) do |m|
player_modules << m.name unless modules.include?(m.name)
end
#IThis imports the monsters directory
require_dir("monsters")
#This creates a new Game object
game = Game.new
player_modules.each do |m|
constant = Object
player = Player.new
game.players << player #adds each player to the game's player array
p = PlayerProxy.new(player) #I'm not sure what the player proxy is
p.extend constant.const_get(m)
player.proxy = p
game.proxies << p
end
#This generates new monsters
20.times do
monster = Monster.new
game.players << monster
r = PlayerProxy.new(monster)
r.extend Rat
monster.proxy = r
game.proxies << r
end
#Rreceive the round count, and does something with a regex for any other command line arguments
if ARGV.size > 1 and ARGV[0] == "-r" and ARGV[1] =~ /^[1-9]\d*$/
ARGV.shift
round_count = ARGV.shift.to_i
else
round_count = 10
end
#This iterates the rounds
game.round(round_count)