Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-server-flip-jump
Project
Project
Details
Activity
Releases
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
Vũ Gia Vương
game-server-flip-jump
Commits
df5ef839
Commit
df5ef839
authored
Aug 11, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update config
parent
e5a1641f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
20 deletions
+27
-20
config.ts
src/Config/config.ts
+4
-4
networkCtrl.ts
src/Controller/networkCtrl.ts
+1
-1
User.ts
src/Model/User.ts
+3
-2
socket.ts
src/socket.ts
+19
-13
No files found.
src/Config/config.ts
View file @
df5ef839
...
@@ -34,10 +34,10 @@ const CONFIG = {
...
@@ -34,10 +34,10 @@ const CONFIG = {
RECONNECT
:
'500'
,
RECONNECT
:
'500'
,
REQU
SE
T_START_GAME
:
'600'
,
REQU
ES
T_START_GAME
:
'600'
,
REQU
SE
T_PASS_TOWER
:
'601'
,
REQU
ES
T_PASS_TOWER
:
'601'
,
REQU
SE
T_SPAWN_TOWER
:
'602'
,
REQU
ES
T_SPAWN_TOWER
:
'602'
,
REQU
SE
T_HISTORY
:
'603'
,
REQU
ES
T_HISTORY
:
'603'
,
},
},
HTTP_RESPONSE
:
{
HTTP_RESPONSE
:
{
SUCCESS
:
{
SUCCESS
:
{
...
...
src/Controller/networkCtrl.ts
View file @
df5ef839
...
@@ -46,7 +46,7 @@ export async function endGameApi(user: User) {
...
@@ -46,7 +46,7 @@ export async function endGameApi(user: User) {
details
details
}
}
//
const res = await callApi(URL_END_GAME, 'POST', params);
const
res
=
await
callApi
(
URL_END_GAME
,
'POST'
,
params
);
}
}
async
function
callApi
(
url
:
string
,
method
:
string
,
data
:
any
)
{
async
function
callApi
(
url
:
string
,
method
:
string
,
data
:
any
)
{
...
...
src/Model/User.ts
View file @
df5ef839
...
@@ -3,7 +3,7 @@ import v2 from "./v2";
...
@@ -3,7 +3,7 @@ import v2 from "./v2";
class
User
{
class
User
{
public
token
:
string
=
''
;
public
token
:
string
=
''
;
public
towerNumber
:
number
=
0
;
public
towerNumber
:
number
=
0
;
public
direction
:
number
=
0
;
public
direction
:
number
=
1
;
public
distance2Tower
:
number
=
0
;
public
distance2Tower
:
number
=
0
;
public
score
:
number
=
0
;
public
score
:
number
=
0
;
...
@@ -20,6 +20,7 @@ class User {
...
@@ -20,6 +20,7 @@ class User {
constructor
(
token
:
string
)
{
constructor
(
token
:
string
)
{
this
.
token
=
token
;
this
.
token
=
token
;
this
.
reset
();
}
}
public
reset
()
{
public
reset
()
{
...
@@ -30,7 +31,7 @@ class User {
...
@@ -30,7 +31,7 @@ class User {
this
.
history
=
[];
this
.
history
=
[];
this
.
timeStart
=
0
;
this
.
timeStart
=
0
;
this
.
towerNumber
=
0
;
this
.
towerNumber
=
0
;
this
.
direction
=
0
;
this
.
direction
=
1
;
this
.
distance2Tower
=
0
;
this
.
distance2Tower
=
0
;
this
.
curBlock
.
x
=
0
;
this
.
curBlock
.
x
=
0
;
this
.
curBlock
.
y
=
0
;
this
.
curBlock
.
y
=
0
;
...
...
src/socket.ts
View file @
df5ef839
...
@@ -30,33 +30,35 @@ export function setupSocket(io: Server) {
...
@@ -30,33 +30,35 @@ export function setupSocket(io: Server) {
}
}
function
onDisconnect
(
socket
:
Socket
):
void
{
function
onDisconnect
(
socket
:
Socket
):
void
{
console
.
log
(
`🔴 Client disconnected:
${
socket
.
id
}
`
)
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
if
(
user
?.
isEndGame
)
{
if
(
user
?.
isEndGame
)
{
return
;
return
;
}
}
endGameApi
(
user
);
endGameApi
(
user
);
user
.
totalScore
=
0
;
user
.
reset
();
return
console
.
log
(
`🔴 Client disconnected:
${
socket
.
id
}
`
);
}
}
async
function
getHistory
(
socket
:
Socket
)
{
async
function
getHistory
(
socket
:
Socket
)
{
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
SE
T_HISTORY
,
user
.
history
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
ES
T_HISTORY
,
user
.
history
);
}
}
async
function
startGame
(
socket
:
Socket
,
data
:
any
)
{
async
function
startGame
(
socket
:
Socket
,
data
:
any
)
{
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
const
result
=
await
startGameApi
(
data
);
const
result
=
await
startGameApi
(
data
);
// const result = true;
if
(
result
)
{
if
(
result
)
{
user
.
isEndGame
=
false
;
user
.
isEndGame
=
false
;
addBlock
(
socket
);
addBlock
(
socket
);
}
else
{
}
else
{
console
.
log
(
'start game fail'
);
console
.
log
(
'start game fail'
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
SE
T_START_GAME
,
{
code
:
9999
});
socket
.
emit
(
CONFIG
.
EVT
.
REQU
ES
T_START_GAME
,
{
code
:
9999
});
}
}
}
}
async
function
passTower
(
socket
:
Socket
,
data
:
{
nextPos
:
v2
,
distance
:
number
})
{
async
function
passTower
(
socket
:
Socket
,
data
:
{
nextPos
:
v2
,
distance
:
number
})
{
console
.
log
(
'distance'
,
data
.
distance
)
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
// const lastDis = user.curBlock.distanceTo(data.nextPos);
// const lastDis = user.curBlock.distanceTo(data.nextPos);
...
@@ -71,14 +73,15 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
...
@@ -71,14 +73,15 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
if
(
distance
<
DISTANCE_BLOCK
/
3
)
{
if
(
distance
<
DISTANCE_BLOCK
/
3
)
{
score
=
2
;
score
=
2
;
}
}
if
(
user
.
towerNumber
>
2
)
{
//
if (user.towerNumber > 2) {
score
=
0
;
//test
//
score = 0;//test
}
//
}
if
(
score
==
0
)
{
if
(
score
==
0
)
{
user
.
isEndGame
=
true
;
user
.
isEndGame
=
true
;
}
}
console
.
log
(
'score'
,
score
)
if
(
score
==
2
)
{
if
(
score
==
2
)
{
user
.
combo
=
Math
.
min
(
user
.
combo
+
1
,
2
);
user
.
combo
=
Math
.
min
(
user
.
combo
+
1
,
2
);
score
*=
user
.
combo
;
score
*=
user
.
combo
;
...
@@ -101,14 +104,13 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
...
@@ -101,14 +104,13 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
user
.
history
.
unshift
(
history
);
user
.
history
.
unshift
(
history
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
SE
T_PASS_TOWER
,
dataSend
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
ES
T_PASS_TOWER
,
dataSend
);
if
(
score
!=
0
)
{
if
(
score
>
0
)
{
addBlock
(
socket
);
addBlock
(
socket
);
}
else
{
}
else
{
socket
.
emit
(
CONFIG
.
EVT
.
REQU
SE
T_HISTORY
,
user
.
history
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
ES
T_HISTORY
,
user
.
history
);
await
endGameApi
(
user
);
await
endGameApi
(
user
);
user
.
reset
();
user
.
reset
();
socket
.
emit
(
CONFIG
.
EVT
.
REQUSET_PASS_TOWER
,
'END'
);
console
.
log
(
'END'
)
console
.
log
(
'END'
)
}
}
}
}
...
@@ -116,12 +118,16 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
...
@@ -116,12 +118,16 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
async
function
addBlock
(
socket
:
Socket
)
{
async
function
addBlock
(
socket
:
Socket
)
{
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
const
towerNumber
=
++
user
.
towerNumber
;
const
towerNumber
=
++
user
.
towerNumber
;
console
.
log
(
'towerNumber'
,
towerNumber
)
const
xDistance
=
((
Math
.
min
(
towerNumber
,
100
)
/
100
+
1
)
+
Math
.
random
()
*
(
towerNumber
<=
10
?
0.5
:
1
))
*
150
;
const
xDistance
=
((
Math
.
min
(
towerNumber
,
100
)
/
100
+
1
)
+
Math
.
random
()
*
(
towerNumber
<=
10
?
0.5
:
1
))
*
150
;
const
yDistance
=
xDistance
*
Y_RATIO
;
const
yDistance
=
xDistance
*
Y_RATIO
;
user
.
curBlock
=
new
v2
(
user
.
nextBlock
.
x
,
user
.
nextBlock
.
y
);
user
.
curBlock
=
new
v2
(
user
.
nextBlock
.
x
,
user
.
nextBlock
.
y
);
if
(
towerNumber
>
1
){
user
.
direction
=
(
Math
.
random
()
<
0.5
)
?
-
1
:
1
;
user
.
direction
=
(
Math
.
random
()
<
0.5
)
?
-
1
:
1
;
}
console
.
log
(
'user.direction'
,
user
.
direction
)
user
.
nextBlock
.
x
=
user
.
curBlock
.
x
+
(
xDistance
*
user
.
direction
);
user
.
nextBlock
.
x
=
user
.
curBlock
.
x
+
(
xDistance
*
user
.
direction
);
user
.
nextBlock
.
y
=
user
.
curBlock
.
y
+
yDistance
;
user
.
nextBlock
.
y
=
user
.
curBlock
.
y
+
yDistance
;
user
.
distance2Tower
=
user
.
nextBlock
.
distanceTo
(
user
.
curBlock
);
user
.
distance2Tower
=
user
.
nextBlock
.
distanceTo
(
user
.
curBlock
);
...
@@ -135,7 +141,7 @@ async function addBlock(socket: Socket) {
...
@@ -135,7 +141,7 @@ async function addBlock(socket: Socket) {
towerNumber
:
user
.
towerNumber
-
1
,
towerNumber
:
user
.
towerNumber
-
1
,
};
};
user
.
timeStart
=
Date
.
now
();
user
.
timeStart
=
Date
.
now
();
socket
.
emit
(
CONFIG
.
EVT
.
REQU
SE
T_SPAWN_TOWER
,
data
);
socket
.
emit
(
CONFIG
.
EVT
.
REQU
ES
T_SPAWN_TOWER
,
data
);
}
}
function
getUserBySocket
(
socket
:
Socket
)
{
function
getUserBySocket
(
socket
:
Socket
)
{
...
...
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