From e6e8aac6168ec497b5bd7eb495914288f823db2a Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Mon, 16 May 2011 18:08:37 +0200 Subject: [PATCH] added draw --- games/tic-tac-toe-python/server.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/games/tic-tac-toe-python/server.js b/games/tic-tac-toe-python/server.js index fd208b1..32b609f 100644 --- a/games/tic-tac-toe-python/server.js +++ b/games/tic-tac-toe-python/server.js @@ -56,7 +56,9 @@ function move(player_id, args) { GGS.sendCommand(p1_id, "loser", "You lose!"); GGS.sendCommand(p2_id, "winner", "You win!"); } - } + } else if(allFieldsFull(gameBoard)) { + GGS.sendCommandToAll("draw", "It was a dwaw!"); + }allFieldsFull(gameBoard) if (nextPlayer == 1) { GGS.localStorage.setItem("next_player", 2); @@ -121,6 +123,17 @@ function checkIfWon(gameBoard) { return false; } +function allFieldsFull(gameBoard) { + for (var i=0; i < ROWS; i++) { + for(var j=0; j < ROWS; j++) { + if (gameBoard[i][j] == 0) { + return false; + } + } + } + return true; +} + function newGame() { // Initiate game with empty rows and columns var gameBoard = [];