Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 7fba859

Browse files
committed
Update
1 parent 27a3496 commit 7fba859

File tree

3 files changed

+38
-44
lines changed

3 files changed

+38
-44
lines changed

main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ global.port = 9016
2525
global.serverRunning = false
2626
global.gameStarted = false
2727
global.map = undefined
28+
global.gameLoop = undefined
2829
global.gameConfig = {
2930
maxPlayers: 8,
3031
gameSpeed: 3,
@@ -56,6 +57,11 @@ async function handleInput(command) {
5657
async function handleDisconnectInGame(player, io) {
5758
io.local.emit('room_message', player.trans(), 'quit.')
5859
global.players = global.players.filter(p => p != player)
60+
if (global.players.length <= 1) {
61+
global.gameStarted = false
62+
clearInterval(global.gameLoop)
63+
io.local.emit('game_ended', global.players[0].id)
64+
}
5965
}
6066

6167
async function handleDisconnectInRoom(player, io) {
@@ -141,7 +147,7 @@ async function handleGame(io) {
141147
}
142148

143149
let updTime = 500 / speedArr[global.gameConfig.gameSpeed]
144-
let gameLoop = setInterval(async () => {
150+
global.gameLoop = setInterval(async () => {
145151
try {
146152

147153
global.players.forEach(async (player) => {
@@ -170,7 +176,7 @@ async function handleGame(io) {
170176
io.local.emit('game_ended', alivePlayer.id)
171177
global.gameStarted = false
172178
global.forceStartNum = 0
173-
clearInterval(gameLoop)
179+
clearInterval(global.gameLoop)
174180
}
175181

176182
let leaderBoard = global.players.map(player => {

renderer.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ let Queue = (function () {
2525
return item;
2626
}
2727

28+
pop_back() {
29+
let item = items.pop()
30+
$(`#td${item.to.x}-${item.to.y}`).removeClass('queued')
31+
return item;
32+
}
33+
2834
front() {
2935
return items[0];
3036
}
@@ -148,19 +154,17 @@ function gameJoin(username) {
148154
});
149155

150156
socket.on('reject_join', (title, message) => {
151-
$.toast({
152-
position: 'left top',
153-
class: 'error',
157+
Swal.fire({
154158
title: title,
155-
displayTime: 0,
156-
message: message,
157-
actions: [{
158-
text: 'OK',
159-
class: 'white',
160-
click: function () {
161-
window.location.href = 'index.html';
162-
}
163-
}]
159+
text: message,
160+
icon: error,
161+
showDenyButton: false,
162+
showCancelButton: false,
163+
allowOutsideClick: false,
164+
confirmButtonText: 'OK'
165+
}).then((result) => {
166+
/* Read more about isConfirmed, isDenied below */
167+
reJoinGame()
164168
})
165169
})
166170

@@ -173,6 +177,18 @@ function gameJoin(username) {
173177
});
174178

175179
socket.on('disconnect', () => {
180+
Swal.fire({
181+
title: 'Disconnected from the server',
182+
html: 'Please reflush the App.',
183+
icon: 'error',
184+
showDenyButton: false,
185+
showCancelButton: false,
186+
allowOutsideClick: false,
187+
confirmButtonText: 'Quit'
188+
}).then((result) => {
189+
/* Read more about isConfirmed, isDenied below */
190+
reJoinGame()
191+
})
176192
console.log('Disconnected from server.');
177193
});
178194

@@ -482,6 +498,8 @@ function gameJoin(username) {
482498
$(document).bind('keydown', (event) => {
483499
if (!window.selectedTd) return
484500
if (event.which === 69) {
501+
window.queue.pop_back()
502+
} else if (event.which === 81) {
485503
window.queue.clear()
486504
} else if (event.which === 65 || event.which === 37) { // Left
487505
let newPoint = { x: window.selectedTd.x, y: window.selectedTd.y - 1 }

src/server/game.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)