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
abd8ecb2
Commit
abd8ecb2
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
83945f29
66a90b69
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
48 deletions
+137
-48
doc.rb
be/doc.rb
+12
-2
index.rb
be/index.rb
+79
-19
Map.ts
fe/src/Map.ts
+36
-14
MapGrid.ts
fe/src/MapGrid.ts
+6
-10
SceneManager.ts
fe/src/SceneManager.ts
+1
-1
Store.ts
fe/src/Store.ts
+2
-1
GameScene.ts
fe/src/scenes/GameScene.ts
+1
-1
No files found.
be/doc.rb
View file @
abd8ecb2
...
...
@@ -14,7 +14,7 @@
{
type:
'game_ready'
,
cid:
'abcdefg'
,
room_id:
'
asdfadfaf
'
,
room_id:
'
default_room
'
,
payload:
{
nick_name:
'asdfasdfa'
,
avatar_url:
'https://xxx.com'
,
...
...
@@ -26,7 +26,16 @@
{
type:
'game_end'
,
room_id:
'asdfadfaf'
,
room_id:
'default_room'
,
payload
:{
}
}
{
type:
'item_refresh'
,
room_id:
'default_room'
,
payload
:{
x
:
1
,
y
:
2
}
}
\ No newline at end of file
be/index.rb
View file @
abd8ecb2
...
...
@@ -21,8 +21,16 @@ module CrazyFlirt
end
class
RandomPicker
def
self
.
item_generate
rd
=
Random
.
new
x
=
@rd
.
rand
(
0
..
@x_max
)
y
=
@rd
.
rand
(
0
..
@y_max
)
[
x
,
y
]
end
def
initialize
(
clients
)
@client
=
clients
@x_max
=
14
...
...
@@ -45,12 +53,13 @@ module CrazyFlirt
class
Client
attr_reader
:key
attr_accessor
:role
,
:room
attr_accessor
:role
,
:room
,
:user_info
def
initialize
(
ws
)
@ws
=
ws
@key
=
generate_key
@role
=
nil
@room
=
nil
end
def
msg
(
msg
)
...
...
@@ -111,11 +120,15 @@ module CrazyFlirt
ws
.
on
:message
do
|
event
|
message
=
JSON
.
parse
(
event
.
data
)
seq
=
message
[
'type'
]
puts
'seq is nil'
if
seq
.
nil?
next
if
seq
.
nil?
command
(
seq
,
message
,
client
)
end
ws
.
on
:close
do
|
event
|
puts
"leave key
#{
client
.
key
}
"
@socket_pool
.
delete
(
client
.
key
)
p
client
.
room
client
.
room
.
leave_client
(
client
.
key
)
client
=
nil
puts
'closed'
...
...
@@ -135,28 +148,73 @@ module CrazyFlirt
picker
=
RandomPicker
.
new
(
room
.
clients
)
idx
=
picker
.
pick_ghost_index
ghost
=
room
.
clients
[
idx
]
game_ready_notice
(
room
,
ghost
,
picker
)
timer
(
room
)
end
room
.
clients
.
each
do
|
client
|
msg
=
{
type:
'game_ready'
,
cid:
client
.
id
,
def
timer
(
room
)
@thread
=
Thread
.
new
do
puts
'start'
sleep
(
30
)
puts
'notice'
notice_all
(
room
,
{
type:
'game_end'
,
room_id:
room
.
name
,
payload:
{
open_id:
client
.
open_id
,
picture:
client
.
picture
,
payload
:{
}
})
end
@item_thread
=
Thread
.
new
do
5
.
times
do
x
,
y
=
RandomPicker
.
item_generate
notice_all
(
room
,{
type:
'item_refresh'
,
room_id:
'default_room'
,
payload
:{
x
:x
,
y
:y
}
})
sleep
(
5
)
end
end
end
def
game_ready_notice
(
room
,
ghost
,
picker
)
room
.
clients
.
each
do
|
client
|
msg
=
ready_message
(
room
,
client
)
if
ghost
.
key
==
client
.
key
msg
[
:payload
][
:role
]
=
'ghost'
client
.
msg
(
msg
)
else
x
,
y
=
picker
.
pick_born_point
x
,
y
=
picker
.
pick_born_point
msg
[
:payload
][
:x
]
=
x
msg
[
:payload
][
:y
]
=
y
msg
[
:payload
][
:role
]
=
'runner'
end
notice_all
(
room
,
msg
)
end
end
def
notice_all
(
room
,
msg
)
room
.
clients
.
each
do
|
client
|
client
.
msg
(
msg
)
end
end
def
ready_message
(
room
,
client
)
{
type:
'game_ready'
,
cid:
client
.
id
,
room_id:
room
.
name
,
payload:
{
open_id:
client
.
open_id
,
picture:
client
.
picture
,
}
}
end
def
clicking
(
msg
,
cl
)
...
...
@@ -177,22 +235,24 @@ module CrazyFlirt
room
=
@room_pool
[
msg
[
'rid'
]]
seat_index
=
room
.
set_client
(
client
)
client
.
room
=
room
client
.
user_info
=
{
nick_name:
msg
[
'payload'
][
'nick_name'
],
avatar_url:
msg
[
'payload'
][
'avatar_url'
]}
msg
[
'cid'
]
=
client
.
key
msg
[
'payload'
][
'seat'
]
=
seat_index
msg
[
'payload'
][
'members'
]
=
room
.
clients
.
map
do
|
cl
|
cl
.
user_info
end
room
.
clients
.
each
do
|
client
|
client
.
msg
(
msg
)
end
end
def
create_room
(
msg
)
client_id
=
msg
[
'cid'
]
key
=
"room_
#{
::
CrazyFlirt
::
RandomKeyGenerator
.
key
}
"
room
=
GameRoom
.
new
(
key
)
@room_pool
[
key
]
=
room
client
=
@socket_pool
[
client_id
]
room
.
set_client
(
client
)
client
.
msg
(
room_id:
key
)
end
#
def create_room(msg)
#
client_id = msg['cid']
#
key = "room_#{::CrazyFlirt::RandomKeyGenerator.key}"
#
room = GameRoom.new(key)
#
@room_pool[key] = room
#
client = @socket_pool[client_id]
#
room.set_client(client)
#
client.msg(room_id: key)
#
end
end
end
...
...
fe/src/Map.ts
View file @
abd8ecb2
...
...
@@ -4,6 +4,7 @@ const gridsInX = 14
const
gridsInY
=
10
class
Map
extends
egret
.
Sprite
{
private
grids
:
any
=
[]
private
touchArea
:
egret
.
Bitmap
public
constructor
()
{
super
();
this
.
init
()
...
...
@@ -11,7 +12,6 @@ class Map extends egret.Sprite {
// 初始化(给开始按钮绑定点击事件)
private
init
()
{
console
.
log
(
'Map.init'
)
for
(
let
i
=
0
;
i
<
gridsInY
;
i
++
)
{
this
.
grids
.
push
([])
for
(
let
j
=
0
;
j
<
gridsInX
;
j
++
)
{
...
...
@@ -22,21 +22,44 @@ class Map extends egret.Sprite {
this
.
addChild
(
grid
)
}
}
if
(
Store
.
isCatcher
())
{
const
mask
=
new
egret
.
Shape
()
mask
.
x
=
100
mask
.
y
=
100
mask
.
graphics
.
lineStyle
(
10
,
0x00ff00
);
mask
.
graphics
.
beginFill
(
0xff0000
,
1
);
mask
.
graphics
.
drawCircle
(
0
,
0
,
50
);
mask
.
graphics
.
endFill
();
mask
.
touchEnabled
=
false
this
.
mask
=
mask
this
.
touchArea
=
new
egret
.
Bitmap
()
this
.
touchArea
.
texture
=
RES
.
getRes
(
'mask_jpg'
)
this
.
touchArea
.
alpha
=
0
this
.
addChild
(
this
.
touchArea
)
}
public
getSurroundedGrids
(
x
,
y
)
{
const
left
=
Math
.
max
(
x
/
gridWidth
-
2
)
const
top
=
Math
.
max
(
y
/
gridHeight
-
2
)
const
grids
=
[]
for
(
let
i
=
left
;
i
<
5
+
left
;
i
++
)
{
for
(
let
j
=
top
;
j
<
5
+
top
;
j
++
)
{
if
(
i
>=
0
&&
j
>=
0
&&
i
<
gridsInX
&&
j
<
gridsInY
)
{
grids
.
push
(
this
.
grids
[
j
][
i
])
}
}
// put display object to this scene
}
return
grids
}
public
showSurroundedGrids
(
x
,
y
)
{
const
surroundedGrids
=
this
.
getSurroundedGrids
(
x
,
y
)
surroundedGrids
.
forEach
(
grid
=>
{
grid
.
alpha
=
1
})
this
.
touchArea
.
alpha
=
1
this
.
touchArea
.
x
=
x
-
2
*
gridWidth
this
.
touchArea
.
y
=
y
-
2
*
gridHeight
setTimeout
(()
=>
{
surroundedGrids
.
forEach
(
grid
=>
{
grid
.
alpha
=
0
})
this
.
touchArea
.
alpha
=
0
},
1000
);
}
public
release
()
{
// 移除事件
}
}
\ No newline at end of file
fe/src/MapGrid.ts
View file @
abd8ecb2
...
...
@@ -6,25 +6,22 @@ class MapGrid extends egret.Sprite {
this
.
init
()
}
// 初始化(给开始按钮绑定点击事件)
private
init
()
{
console
.
log
(
'Map.init'
)
this
.
bg
.
texture
=
RES
.
getRes
(
'grid_jpg'
)
this
.
addChild
(
this
.
bg
)
this
.
bg
.
touchEnabled
=
true
this
.
bg
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_BEGIN
,
this
.
onTouchTap
,
this
)
this
.
touchEnabled
=
true
if
(
Store
.
isCatcher
())
{
this
.
alpha
=
0
this
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_BEGIN
,
this
.
onTouchTap
,
this
)
}
}
private
onTouchTap
()
{
console
.
log
(
this
,
this
.
parent
)
if
(
Store
.
isCatcher
())
{
console
.
log
(
this
,
this
.
parent
)
// const map = SceneManager.getInstance().gameScene.map
this
.
parent
.
showSurroundedGrids
(
this
.
x
,
this
.
y
)
}
}
public
release
()
{
// 移除事件
}
}
\ No newline at end of file
fe/src/SceneManager.ts
View file @
abd8ecb2
...
...
@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this
.
roomScene
=
new
RoomScene
();
this
.
gameScene
=
new
GameScene
();
// 默认添加开始场景
this
.
addChild
(
this
.
room
Scene
);
this
.
addChild
(
this
.
game
Scene
);
}
// 实例化单例获取方法
public
static
getInstance
():
SceneManager
{
...
...
fe/src/Store.ts
View file @
abd8ecb2
...
...
@@ -31,6 +31,6 @@ class Store {
static
isCatcher
()
{
return
true
return
_state
.
role
===
'ghost'
//
return _state.role === 'ghost'
}
}
\ No newline at end of file
fe/src/scenes/GameScene.ts
View file @
abd8ecb2
...
...
@@ -28,7 +28,7 @@ class GameScene extends egret.Sprite {
this
.
me
.
y
=
15
this
.
me
.
x
=
10
this
.
addChild
(
this
.
map
)
this
.
addChild
(
this
.
me
)
this
.
map
.
addChild
(
this
.
me
)
}
private
onPositionChange
(
delta
){
...
...
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