Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crazyflirt
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shawn Wang
crazyflirt
Commits
153545ae
Commit
153545ae
authored
May 05, 2018
by
Shawn Wang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of cd.i.strikingly.com:shawn.wang/crazyflirt into develop
parents
10ba22f7
1eebe1f6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
17 deletions
+40
-17
doc.rb
be/doc.rb
+4
-4
index.rb
be/index.rb
+36
-13
No files found.
be/doc.rb
View file @
153545ae
...
...
@@ -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
...
...
be/index.rb
View file @
153545ae
...
...
@@ -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
comm
e
nd
(
command
,
*
args
)
def
comm
a
nd
(
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
[
'r
oom_
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
[
'r
oom_
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
[
'r
oom_
id'
]]
room
=
@room_pool
[
msg
[
'rid'
]]
seat_index
=
room
.
set_client
(
client
)
client
.
room
=
room
msg
[
'cid'
]
=
client
.
key
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment