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

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reqwey committed Nov 14, 2022
1 parent 27a3496 commit 7fba859
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
10 changes: 8 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ global.port = 9016
global.serverRunning = false
global.gameStarted = false
global.map = undefined
global.gameLoop = undefined
global.gameConfig = {
maxPlayers: 8,
gameSpeed: 3,
Expand Down Expand Up @@ -56,6 +57,11 @@ async function handleInput(command) {
async function handleDisconnectInGame(player, io) {
io.local.emit('room_message', player.trans(), 'quit.')
global.players = global.players.filter(p => p != player)
if (global.players.length <= 1) {
global.gameStarted = false
clearInterval(global.gameLoop)
io.local.emit('game_ended', global.players[0].id)
}
}

async function handleDisconnectInRoom(player, io) {
Expand Down Expand Up @@ -141,7 +147,7 @@ async function handleGame(io) {
}

let updTime = 500 / speedArr[global.gameConfig.gameSpeed]
let gameLoop = setInterval(async () => {
global.gameLoop = setInterval(async () => {
try {

global.players.forEach(async (player) => {
Expand Down Expand Up @@ -170,7 +176,7 @@ async function handleGame(io) {
io.local.emit('game_ended', alivePlayer.id)
global.gameStarted = false
global.forceStartNum = 0
clearInterval(gameLoop)
clearInterval(global.gameLoop)
}

let leaderBoard = global.players.map(player => {
Expand Down
42 changes: 30 additions & 12 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ let Queue = (function () {
return item;
}

pop_back() {
let item = items.pop()
$(`#td${item.to.x}-${item.to.y}`).removeClass('queued')
return item;
}

front() {
return items[0];
}
Expand Down Expand Up @@ -148,19 +154,17 @@ function gameJoin(username) {
});

socket.on('reject_join', (title, message) => {
$.toast({
position: 'left top',
class: 'error',
Swal.fire({
title: title,
displayTime: 0,
message: message,
actions: [{
text: 'OK',
class: 'white',
click: function () {
window.location.href = 'index.html';
}
}]
text: message,
icon: error,
showDenyButton: false,
showCancelButton: false,
allowOutsideClick: false,
confirmButtonText: 'OK'
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
reJoinGame()
})
})

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

socket.on('disconnect', () => {
Swal.fire({
title: 'Disconnected from the server',
html: 'Please reflush the App.',
icon: 'error',
showDenyButton: false,
showCancelButton: false,
allowOutsideClick: false,
confirmButtonText: 'Quit'
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
reJoinGame()
})
console.log('Disconnected from server.');
});

Expand Down Expand Up @@ -482,6 +498,8 @@ function gameJoin(username) {
$(document).bind('keydown', (event) => {
if (!window.selectedTd) return
if (event.which === 69) {
window.queue.pop_back()
} else if (event.which === 81) {
window.queue.clear()
} else if (event.which === 65 || event.which === 37) { // Left
let newPoint = { x: window.selectedTd.x, y: window.selectedTd.y - 1 }
Expand Down
30 changes: 0 additions & 30 deletions src/server/game.js

This file was deleted.

0 comments on commit 7fba859

Please sign in to comment.