-
Notifications
You must be signed in to change notification settings - Fork 4
/
game.rb
executable file
·61 lines (51 loc) · 1.12 KB
/
game.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
61
#!/usr/bin/env ruby
require 'rubygems'
require 'rubygame'
require 'httparty'
require 'optparse'
require './lib/engine'
require './lib/map'
require './lib/setup'
require './lib/ingame'
include Engine
include Rubygame::Events
$id = ""
def safe_get url
begin
HTTParty.get("http://#{$ip}/" + url)
rescue Errno::EADDRINUSE
puts "Address already in use"
retry
rescue Errno::ECONNREFUSED
puts "Connection refused"
rescue Exception => e
puts "Fail, unknown or unexpected error:"
p e
end
end
game = Game.new
game.event(QuitRequested) do
safe_get("disconnect?id=#{$id}")
Rubygame.quit
exit
end
Text.send(:class_variable_set, :@@default_font, "media/FreeSans.ttf")
options = {}
optparse = OptionParser.new do |opts|
options[:skip] = false
opts.on('--skip', 'Skip character design screen') do
options[:skip] = true
end
options[:ip] = "localhost:4567"
opts.on('--ip ADDRESS', "Set the ip address of the server we're using") do |address|
options[:ip] = address
end
end
optparse.parse!
if options[:skip]
game.switch_state InGame.new "Tyler", [255,255,255]
else
game.switch_state Setup.new
end
$ip = options[:ip]
game.run