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
798b39ca
Commit
798b39ca
authored
Aug 12, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update startGame
parent
df5ef839
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
socket.ts
src/socket.ts
+24
-11
No files found.
src/socket.ts
View file @
798b39ca
...
...
@@ -47,13 +47,14 @@ async function getHistory(socket: Socket) {
async
function
startGame
(
socket
:
Socket
,
data
:
any
)
{
const
user
=
getUserBySocket
(
socket
);
const
result
=
await
startGameApi
(
data
);
// const result =
tru
e;
// const result =
fals
e;
if
(
result
)
{
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_START_GAME
,
true
);
user
.
isEndGame
=
false
;
addBlock
(
socket
);
}
else
{
console
.
log
(
'start game fail'
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_START_GAME
,
{
code
:
9999
}
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_START_GAME
,
false
);
}
}
...
...
@@ -67,21 +68,26 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
let
score
=
0
const
distance
=
Math
.
abs
(
data
.
distance
-
user
.
distance2Tower
);
if
(
distance
<
DISTANCE_BLOCK
)
{
if
(
distance
<
DISTANCE_BLOCK
*
0.8
)
{
score
=
1
;
}
if
(
distance
<
DISTANCE_BLOCK
/
3
)
{
if
(
distance
<
=
DISTANCE_BLOCK
/
3
)
{
score
=
2
;
}
if
(
distance
>
DISTANCE_BLOCK
*
0.8
&&
distance
<=
DISTANCE_BLOCK
*
1.2
)
{
score
=
-
1
;
}
// if (user.towerNumber > 2) {
// score = 0;//test
// }
if
(
score
=
=
0
)
{
if
(
score
<
=
0
)
{
user
.
isEndGame
=
true
;
}
console
.
log
(
'score'
,
score
)
if
(
score
==
2
)
{
user
.
combo
=
Math
.
min
(
user
.
combo
+
1
,
2
);
score
*=
user
.
combo
;
...
...
@@ -89,15 +95,21 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
user
.
combo
=
0
;
}
let
pointJump
;
user
.
totalScore
+=
score
;
const
jumpDirection
=
(
data
.
distance
>
user
.
distance2Tower
?
1
:
-
1
)
*
user
.
direction
;
const
dataSend
=
{
totalScore
:
user
.
totalScore
,
tower
:
user
.
towerNumber
,
score
,
jumpScore
:
score
,
jumpDirection
,
pointJump
};
const
history
=
{
...
dataSend
,
score
:
Math
.
max
(
score
,
0
),
timeStart
:
user
.
timeStart
,
timePlayed
:
Date
.
now
()
-
user
.
timeStart
,
}
...
...
@@ -105,29 +117,30 @@ async function passTower(socket: Socket, data: { nextPos: v2, distance: number }
user
.
history
.
unshift
(
history
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_PASS_TOWER
,
dataSend
);
if
(
score
>
0
)
{
addBlock
(
socket
);
}
else
{
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_HISTORY
,
user
.
history
);
await
endGameApi
(
user
);
//
await endGameApi(user);
user
.
reset
();
console
.
log
(
'END'
)
console
.
log
(
'END'
)
;
}
}
async
function
addBlock
(
socket
:
Socket
)
{
const
user
=
getUserBySocket
(
socket
);
const
towerNumber
=
++
user
.
towerNumber
;
console
.
log
(
'towerNumber'
,
towerNumber
)
console
.
log
(
'towerNumber
////
'
,
towerNumber
)
const
xDistance
=
((
Math
.
min
(
towerNumber
,
100
)
/
100
+
1
)
+
Math
.
random
()
*
(
towerNumber
<=
10
?
0.5
:
1
))
*
150
;
const
yDistance
=
xDistance
*
Y_RATIO
;
user
.
curBlock
=
new
v2
(
user
.
nextBlock
.
x
,
user
.
nextBlock
.
y
);
if
(
towerNumber
>
1
)
{
if
(
towerNumber
>
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
.
y
=
user
.
curBlock
.
y
+
yDistance
;
user
.
distance2Tower
=
user
.
nextBlock
.
distanceTo
(
user
.
curBlock
);
...
...
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