Commit 1cf4776c by Nick An

fix doc

parent 3563970a
......@@ -3,8 +3,8 @@
cid: 'abcdefg',
room_id: 'asdfadfaf',
payload: {
open_id: 'asdfasdfa',
picture: 'https://xxx.com',
nick_name: 'asdfasdfa',
avatar_url: 'https://xxx.com',
x: 1,
y: 4
}
......@@ -16,8 +16,8 @@
cid: 'abcdefg',
room_id: 'asdfadfaf',
payload: {
open_id: 'asdfasdfa',
picture: 'https://xxx.com',
nick_name: 'asdfasdfa',
avatar_url: 'https://xxx.com',
role: 'ghost', # runner
x: 1,
y: 3
......
......@@ -16,7 +16,7 @@ module CrazyFlirt
5.times do
random_key += words[random.rand(0..size)]
end
Time.now.to_s.to_i + random_key
Time.now.to_s.to_i.to_s + random_key
end
end
......@@ -66,7 +66,7 @@ module CrazyFlirt
class GameRoom
attr_reader :clients
attr_reader :clients, :name
def initialize(name)
@clients = []
......@@ -75,8 +75,9 @@ module CrazyFlirt
end
def set_client(client)
return unless @status == :waiting
@clients << client
client.size - 1
@clients.size - 1
end
def start!
......@@ -105,12 +106,11 @@ module CrazyFlirt
def call(env)
return unless @faye.websocket?(env)
ws = @faye.new(env)
client = ::CrazyFlirt::Client.new(ws)
@socket_pool[client.key] = client
ws.on :message do |event|
message = JSON.parse(event.data)
seq = message[:type]
seq = message['type']
command(seq, message, client)
end
......@@ -125,33 +125,56 @@ module CrazyFlirt
private
def commend(command, *args)
def command(command, *args)
send(command, *args)
end
def start(msg)
room = @room_pool[msg['room_id']]
def start(msg,cl)
room = @room_pool[msg['rid']]
room.start!
picker = RandomPicker.new(room.clients)
idx = picker.pick_ghost_index
ghost = room.clients[idx]
room.clients.each do |client|
msg = {
type: 'game_ready',
cid: client.id,
room_id: room.name,
payload: {
open_id: client.open_id,
picture: client.picture,
}
}
if ghost.key == client.key
msg[:payload][:role] = 'ghost'
client.msg(msg)
else
x,y = picker.pick_born_point
msg[:payload][:x] = x
msg[:payload][:y] = y
msg[:payload][:role] = 'runner'
client.msg(msg)
end
end
end
def clicking(msg)
room = @room_pool[msg['room_id']]
def clicking(msg,cl)
room = @room_pool[msg['rid']]
room.clients.each do |client|
client.msg(msg)
end
end
def moving(msg)
room = @room_pool[msg['room_id']]
def moving(msg,cl)
room = @room_pool[msg['rid']]
room.clients.each do |client|
client.msg(msg)
end
end
def entry(msg, client)
room = @room_pool[msg['room_id']]
room = @room_pool[msg['rid']]
seat_index = room.set_client(client)
client.room = room
msg['cid'] = client.key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment