Commit 57796b58 by Shawn Wang

Merge branch 'develop' of cd.i.strikingly.com:shawn.wang/crazyflirt into develop

parents ed387b38 25b1febe
<?xml version="1.0" encoding="UTF-8"?>
<module type="RUBY_MODULE" version="4">
<component name="ModuleRunConfigurationManager">
<shared />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.16.0, rbenv: 2.2.2) [gem]" level="application" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.2.2" project-jdk-type="RUBY_SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/crazyflirt.iml" filepath="$PROJECT_DIR$/.idea/crazyflirt.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.3.0'
gemspec
gem 'faye-websocket'
gem 'sinatra'
gem 'rack'
gem 'thin'
GEM
remote: https://rubygems.org/
specs:
PLATFORMS
ruby
DEPENDENCIES
BUNDLED WITH
1.16.0
......@@ -22,4 +22,11 @@
x: 1,
y: 3
}
}
{
type: 'game_end',
room_id: 'asdfadfaf',
payload:{
}
}
\ No newline at end of file
......@@ -21,25 +21,31 @@ module CrazyFlirt
end
class RandomRole
class RandomPicker
def initialize
@roles = %i(ghost runner runner runner)
def initialize(clients)
@client = clients
@x_max = 14
@y_max = 10
@rd = Random.new
end
def pick_ghost_index
size = @client.size - 1
@rd.rand(0..size)
end
def pick_role
size = @roles.size - 1
index = Random.new.rand(0..size)
role = @roles[index]
@roles.delete_at(index)
role
def pick_born_point
x = @rd.rand(0..@x_max)
y = @rd.rand(0..@y_max)
[x, y]
end
end
class Client
attr_reader :key
attr_accessor :role
attr_accessor :role, :room
def initialize(ws)
@ws = ws
......@@ -47,7 +53,6 @@ module CrazyFlirt
@role = nil
end
def msg(msg)
@ws.send(msg.to_json)
end
......@@ -64,13 +69,14 @@ module CrazyFlirt
attr_reader :clients
def initialize(name)
@clients = {}
@clients = []
@name = name
@status = :waiting
end
def set_client(client)
@clients[client.key] = client
@clients << client
client.size - 1
end
def start!
......@@ -78,7 +84,8 @@ module CrazyFlirt
end
def leave_client(key)
@clients.delete(key)
idx = @clients.find_index { |c| c.key == key}
@clients.delete_at(idx)
end
end
......@@ -87,31 +94,32 @@ module CrazyFlirt
def initialize
Faye::WebSocket.load_adapter('thin')
@default_room = "default_room"
@faye = Faye::WebSocket
@socket_pool = {}
@room_pool = {}
@room_pool[@default_room] = GameRoom.new(@default_room)
end
def call(env)
return unless @faye.websocket?(env)
default_room = "default_room"
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[:seq]
command(seq, message)
seq = message[:type]
command(seq, message, client)
end
ws.on :close do |event|
@socket_pool.delete(client.key)
client.room.leave_client(client.key)
client = nil
puts 'closed'
end
ws.rack_response
end
......@@ -121,10 +129,16 @@ module CrazyFlirt
send(command, *args)
end
def clicking
def start(msg)
room = @room_pool[msg['room_id']]
picker = RandomPicker.new(room.clients)
idx = picker.pick_ghost_index
ghost = room.clients[idx]
end
def clicking(msg)
room = @room_pool[msg['room_id']]
room.clients.each do |client|
next if client.key == msg
client.msg(msg)
end
end
......@@ -132,7 +146,17 @@ module CrazyFlirt
def moving(msg)
room = @room_pool[msg['room_id']]
room.clients.each do |client|
next if client.key == msg
client.msg(msg)
end
end
def entry(msg, client)
room = @room_pool[msg['room_id']]
seat_index = room.set_client(client)
client.room = room
msg['cid'] = client.key
msg['payload']['seat'] = seat_index
room.clients.each do |client|
client.msg(msg)
end
end
......
......@@ -101,6 +101,7 @@ class Main extends egret.DisplayObjectContainer {
platform.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data)
const state = Store.onMessage(res.data)
})
platform.onSocketError((e) => {
console.error("onSocketError")
......
const _state = {}
class Store {
static getState() {
return _state
}
static onMessage(message) {
switch (message.type) {
case 'start':
_state = {
}
break;
default:
break;
}
return _state
}
}
\ No newline at end of file
{
type: 'moving', # 'start' , 'entry', 'clicking'
cid: 'abcdefg',
room_id: 'asdfadfaf',
payload: {
open_id: 'asdfasdfa',
picture: 'https://xxx.com',
x: 1,
y: 4
}
}
{
type: 'game_ready',
cid: 'abcdefg',
room_id: 'asdfadfaf',
payload: {
open_id: 'asdfasdfa',
picture: 'https://xxx.com',
role: 'ghost', # runner
}
}
GameScene
RunnerList
if isRunner
Controller
Map
if isCatcher
Map.mask = touchArea
\ No newline at end of file
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