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
1cf4776c
Commit
1cf4776c
authored
May 05, 2018
by
Nick An
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix doc
parent
3563970a
Hide 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 @
1cf4776c
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
cid:
'abcdefg'
,
cid:
'abcdefg'
,
room_id:
'asdfadfaf'
,
room_id:
'asdfadfaf'
,
payload:
{
payload:
{
open_id
:
'asdfasdfa'
,
nick_name
:
'asdfasdfa'
,
picture
:
'https://xxx.com'
,
avatar_url
:
'https://xxx.com'
,
x:
1
,
x:
1
,
y:
4
y:
4
}
}
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
cid:
'abcdefg'
,
cid:
'abcdefg'
,
room_id:
'asdfadfaf'
,
room_id:
'asdfadfaf'
,
payload:
{
payload:
{
open_id
:
'asdfasdfa'
,
nick_name
:
'asdfasdfa'
,
picture
:
'https://xxx.com'
,
avatar_url
:
'https://xxx.com'
,
role:
'ghost'
,
# runner
role:
'ghost'
,
# runner
x:
1
,
x:
1
,
y:
3
y:
3
...
...
be/index.rb
View file @
1cf4776c
...
@@ -16,7 +16,7 @@ module CrazyFlirt
...
@@ -16,7 +16,7 @@ module CrazyFlirt
5
.
times
do
5
.
times
do
random_key
+=
words
[
random
.
rand
(
0
..
size
)]
random_key
+=
words
[
random
.
rand
(
0
..
size
)]
end
end
Time
.
now
.
to_s
.
to_i
+
random_key
Time
.
now
.
to_s
.
to_i
.
to_s
+
random_key
end
end
end
end
...
@@ -66,7 +66,7 @@ module CrazyFlirt
...
@@ -66,7 +66,7 @@ module CrazyFlirt
class
GameRoom
class
GameRoom
attr_reader
:clients
attr_reader
:clients
,
:name
def
initialize
(
name
)
def
initialize
(
name
)
@clients
=
[]
@clients
=
[]
...
@@ -75,8 +75,9 @@ module CrazyFlirt
...
@@ -75,8 +75,9 @@ module CrazyFlirt
end
end
def
set_client
(
client
)
def
set_client
(
client
)
return
unless
@status
==
:waiting
@clients
<<
client
@clients
<<
client
client
.
size
-
1
@clients
.
size
-
1
end
end
def
start!
def
start!
...
@@ -105,12 +106,11 @@ module CrazyFlirt
...
@@ -105,12 +106,11 @@ module CrazyFlirt
def
call
(
env
)
def
call
(
env
)
return
unless
@faye
.
websocket?
(
env
)
return
unless
@faye
.
websocket?
(
env
)
ws
=
@faye
.
new
(
env
)
ws
=
@faye
.
new
(
env
)
client
=
::
CrazyFlirt
::
Client
.
new
(
ws
)
client
=
::
CrazyFlirt
::
Client
.
new
(
ws
)
@socket_pool
[
client
.
key
]
=
client
@socket_pool
[
client
.
key
]
=
client
ws
.
on
:message
do
|
event
|
ws
.
on
:message
do
|
event
|
message
=
JSON
.
parse
(
event
.
data
)
message
=
JSON
.
parse
(
event
.
data
)
seq
=
message
[
:type
]
seq
=
message
[
'type'
]
command
(
seq
,
message
,
client
)
command
(
seq
,
message
,
client
)
end
end
...
@@ -125,33 +125,56 @@ module CrazyFlirt
...
@@ -125,33 +125,56 @@ module CrazyFlirt
private
private
def
comm
e
nd
(
command
,
*
args
)
def
comm
a
nd
(
command
,
*
args
)
send
(
command
,
*
args
)
send
(
command
,
*
args
)
end
end
def
start
(
msg
)
def
start
(
msg
,
cl
)
room
=
@room_pool
[
msg
[
'room_id'
]]
room
=
@room_pool
[
msg
[
'rid'
]]
room
.
start!
picker
=
RandomPicker
.
new
(
room
.
clients
)
picker
=
RandomPicker
.
new
(
room
.
clients
)
idx
=
picker
.
pick_ghost_index
idx
=
picker
.
pick_ghost_index
ghost
=
room
.
clients
[
idx
]
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
end
def
clicking
(
msg
)
def
clicking
(
msg
,
cl
)
room
=
@room_pool
[
msg
[
'r
oom_
id'
]]
room
=
@room_pool
[
msg
[
'rid'
]]
room
.
clients
.
each
do
|
client
|
room
.
clients
.
each
do
|
client
|
client
.
msg
(
msg
)
client
.
msg
(
msg
)
end
end
end
end
def
moving
(
msg
)
def
moving
(
msg
,
cl
)
room
=
@room_pool
[
msg
[
'r
oom_
id'
]]
room
=
@room_pool
[
msg
[
'rid'
]]
room
.
clients
.
each
do
|
client
|
room
.
clients
.
each
do
|
client
|
client
.
msg
(
msg
)
client
.
msg
(
msg
)
end
end
end
end
def
entry
(
msg
,
client
)
def
entry
(
msg
,
client
)
room
=
@room_pool
[
msg
[
'r
oom_
id'
]]
room
=
@room_pool
[
msg
[
'rid'
]]
seat_index
=
room
.
set_client
(
client
)
seat_index
=
room
.
set_client
(
client
)
client
.
room
=
room
client
.
room
=
room
msg
[
'cid'
]
=
client
.
key
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