a few oopsies

This commit is contained in:
Evert Prants 2017-04-05 23:23:37 +03:00
parent 8160fed639
commit 5bd7b5ab0d
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 7 additions and 8 deletions

View File

@ -132,6 +132,7 @@
let column = GameDrawer.gridX - 1 let column = GameDrawer.gridX - 1
if (GameDrawer.possible(column)) { if (GameDrawer.possible(column)) {
io.emit('place_at', {column: column, gameId: Connect4.Game.gameId}) io.emit('place_at', {column: column, gameId: Connect4.Game.gameId})
Connect4.Game.myTurn = false
} }
} }
}, },

View File

@ -1,13 +1,13 @@
{ {
"name": "battleship.js", "name": "connect_four.js",
"version": "0.0.0", "version": "0.0.0",
"description": "Battleship game in the browser", "description": "Connect Four game in the browser",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [ "keywords": [
"battleship", "connectfour",
"game", "game",
"html5" "html5"
], ],

View File

@ -236,7 +236,6 @@ function detectWin (color, game) {
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
let pAt = getPiece(game, parseInt(c) + i, piece.y) let pAt = getPiece(game, parseInt(c) + i, piece.y)
if (pAt && pAt.color === color) { if (pAt && pAt.color === color) {
console.log(pAt)
matches += 1 matches += 1
} else { } else {
matches = 0 matches = 0
@ -423,7 +422,9 @@ io.on('connection', (socket) => {
clients[opponent].socket.emit('place', {column: data.column, color: playerInGame}) clients[opponent].socket.emit('place', {column: data.column, color: playerInGame})
game.places[data.column].push({color: playerInGame, y: 8 - game.places[data.column].length}) game.places[data.column].push({color: playerInGame, y: 8 - game.places[data.column].length})
console.log(game.places[data.column])
clients[me].socket.emit('turn', false)
clients[opponent].socket.emit('turn', true)
if (detectWin(playerInGame, game)) { if (detectWin(playerInGame, game)) {
endGame(data.gameId, me, opponent, 1) endGame(data.gameId, me, opponent, 1)
@ -434,9 +435,6 @@ io.on('connection', (socket) => {
endGame(data.gameId, me, opponent, 2) endGame(data.gameId, me, opponent, 2)
return return
} }
clients[me].socket.emit('turn', false)
clients[opponent].socket.emit('turn', true)
}) })
socket.on('disconnect', () => { socket.on('disconnect', () => {