Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
srvpro
Commits
29ca510e
Commit
29ca510e
authored
Oct 01, 2015
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
99ae4a90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
24 deletions
+42
-24
room.coffee
room.coffee
+19
-10
room.js
room.js
+23
-14
No files found.
room.coffee
View file @
29ca510e
...
...
@@ -44,22 +44,18 @@ class Room
return
new
Room
(
name
)
@
find_or_create_random
:
(
type
,
player_name
)
->
if
type
==
''
result
=
_
.
find
@
all
,
(
room
)
->
room
.
random_type
and
room
.
players
.
length
==
1
and
room
.
players
[
0
].
name
!=
Room
.
players_oppentlist
[
player_name
]
else
result
=
_
.
find
@
all
,
(
room
)
->
room
.
random_type
==
type
and
room
.
players
.
length
==
1
and
room
.
players
[
0
].
name
!=
Room
.
players_oppentlist
[
player_name
]
result
=
_
.
find
@
all
,
(
room
)
->
(
type
==
''
or
room
.
random_type
==
type
)
and
room
.
get_playing_player
().
length
==
1
and
room
.
get_playing_player
()[
0
].
name
!=
Room
.
players_oppentlist
[
player_name
]
if
result
result
.
welcome
=
'对手已经在等你了,开始决斗吧!'
log
.
info
'found room'
,
player_name
#
log.info 'found room', player_name
else
type
=
if
type
then
type
else
'S'
name
=
type
+
',RANDOM#'
+
Math
.
floor
(
Math
.
random
()
*
100000
)
result
=
new
Room
(
name
)
result
.
random_type
=
type
result
.
welcome
=
'已建立随机对战房间,正在等待对手!'
log
.
info
'create room'
,
player_name
,
name
#
log.info 'create room', player_name, name
return
result
@
find_by_name
:
(
name
)
->
...
...
@@ -271,12 +267,25 @@ class Room
#Room.all[index] = null unless index == -1
Room
.
all
.
splice
(
index
,
1
)
unless
index
==
-
1
return
get_playing_player
:
->
playing_player
=
[]
_
.
each
@
players
,
(
player
)
=>
if
player
.
pos
<
4
then
playing_player
.
push
player
return
return
playing_player
connect
:
(
client
)
->
@
players
.
push
client
if
@
random_type
Room
.
players_oppentlist
[
@
players
[
0
].
name
]
=
if
@
players
[
1
]
then
@
players
[
1
].
name
else
null
if
@
players
[
1
]
then
Room
.
players_oppentlist
[
@
players
[
1
].
name
]
=
@
players
[
0
].
name
playing_players
=
@
get_playing_player
()
if
playing_players
.
length
#进来时已经有人在等待了,互相记录为匹配过
Room
.
players_oppentlist
[
playing_players
[
0
].
name
]
=
client
.
name
Room
.
players_oppentlist
[
client
.
name
]
=
playing_players
[
0
].
name
else
#第一个玩家刚进来,还没就位
Room
.
players_oppentlist
[
client
.
name
]
=
null
if
@
established
client
.
server
.
connect
@
port
,
'127.0.0.1'
,
->
...
...
room.js
View file @
29ca510e
...
...
@@ -57,25 +57,17 @@
Room
.
find_or_create_random
=
function
(
type
,
player_name
)
{
var
name
,
result
;
if
(
type
===
''
)
{
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
return
room
.
random_type
&&
room
.
players
.
length
===
1
&&
room
.
players
[
0
].
name
!==
Room
.
players_oppentlist
[
player_name
];
});
}
else
{
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
return
room
.
random_type
===
type
&&
room
.
players
.
length
===
1
&&
room
.
players
[
0
].
name
!==
Room
.
players_oppentlist
[
player_name
];
});
}
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
return
(
type
===
''
||
room
.
random_type
===
type
)
&&
room
.
get_playing_player
().
length
===
1
&&
room
.
get_playing_player
()[
0
].
name
!==
Room
.
players_oppentlist
[
player_name
];
});
if
(
result
)
{
result
.
welcome
=
'
对手已经在等你了,开始决斗吧!
'
;
log
.
info
(
'
found room
'
,
player_name
);
}
else
{
type
=
type
?
type
:
'
S
'
;
name
=
type
+
'
,RANDOM#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
result
=
new
Room
(
name
);
result
.
random_type
=
type
;
result
.
welcome
=
'
已建立随机对战房间,正在等待对手!
'
;
log
.
info
(
'
create room
'
,
player_name
,
name
);
}
return
result
;
};
...
...
@@ -343,12 +335,29 @@
}
};
Room
.
prototype
.
get_playing_player
=
function
()
{
var
playing_player
;
playing_player
=
[];
_
.
each
(
this
.
players
,
(
function
(
_this
)
{
return
function
(
player
)
{
if
(
player
.
pos
<
4
)
{
playing_player
.
push
(
player
);
}
};
})(
this
));
return
playing_player
;
};
Room
.
prototype
.
connect
=
function
(
client
)
{
var
playing_players
;
this
.
players
.
push
(
client
);
if
(
this
.
random_type
)
{
Room
.
players_oppentlist
[
this
.
players
[
0
].
name
]
=
this
.
players
[
1
]
?
this
.
players
[
1
].
name
:
null
;
if
(
this
.
players
[
1
])
{
Room
.
players_oppentlist
[
this
.
players
[
1
].
name
]
=
this
.
players
[
0
].
name
;
playing_players
=
this
.
get_playing_player
();
if
(
playing_players
.
length
)
{
Room
.
players_oppentlist
[
playing_players
[
0
].
name
]
=
client
.
name
;
Room
.
players_oppentlist
[
client
.
name
]
=
playing_players
[
0
].
name
;
}
else
{
Room
.
players_oppentlist
[
client
.
name
]
=
null
;
}
}
if
(
this
.
established
)
{
...
...
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