class MonkeyMusic::UI::Browser
Public Class Methods
new(level, players, delay, clear)
click to toggle source
# File lib/monkey_music/ui/browser.rb, line 6 def initialize(level, players, delay, clear) @delay = delay @players = players @level = level puts "Initializing websockets..." Thread.new { EM.run { EM::WebSocket.run(:host => "0.0.0.0", :port => 3000) do |ws| @ws = ws ws.onopen { update } end } } print "Using browser UI. Press the enter key to start game." gets puts "Starting game..." puts "Game started!" end
Public Instance Methods
update(turn = 0, turn_time = 0)
click to toggle source
# File lib/monkey_music/ui/browser.rb, line 25 def update(turn = 0, turn_time = 0) @ws.send({ :width => @level.width, :height => @level.height, :units => @level.units, :players => @level.players.map {|p| { :boost_cooldown => p.boost_cooldown, :remaining_time => p.remaining_time, :score => p.monkey.score, :capacity => p.monkey.capacity, :id => p.monkey.id, :name => p.monkey.name, }}, :turn_limit => @level.turn_limit, :time_limit => @level.time_limit, :turn => turn, }.to_json) if @ws sleep 0.50 end