From 38996f89a1688e8a45e500efd83d4f99cacacd1a Mon Sep 17 00:00:00 2001 From: Andre Aureliano Date: Sun, 28 Aug 2011 13:52:28 -0300 Subject: [PATCH] hit/miss --- arduino_client.js | 14 ++++++++------ game_server.js | 15 +++++---------- lib/player.js | 16 +++------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/arduino_client.js b/arduino_client.js index 04e786a..05a430c 100644 --- a/arduino_client.js +++ b/arduino_client.js @@ -9,16 +9,18 @@ var SerialPort = require("serialport").SerialPort; var serialPort = new SerialPort(SERIAL_PORT); -var coordinate = '000'; + + +var coordinate = '000'; var options = { host: HOST_NAME, port: HOST_PORT, path: '/fire/'+PLAYER_NAME+'/'+coordinate }; -http.get(options, function(res) { - console.log("Got response: " + res.statusCode); -}).on('error', function(e) { - console.log("Got error: " + e.message); -}) \ No newline at end of file +// http.get(options, function(res) { +// console.log("Got response: " + res.statusCode); +// }).on('error', function(e) { +// console.log("Got error: " + e.message); +// }) \ No newline at end of file diff --git a/game_server.js b/game_server.js index 352d7d0..7261f7f 100644 --- a/game_server.js +++ b/game_server.js @@ -81,30 +81,25 @@ app.get('/fire/:playerName/:xyz', function(req, res){ pos_y = req.params.xyz.substr(1,1); pos_z = req.params.xyz.substr(2,1); - // shots[][][]==1, hit! - // shots[][][]==2, miss! - - if (req.params.playerName == 'player1') { + if (req.params.playerName == 'player1') { if ((player2.cube[pos_x][pos_y][pos_z] == "1") && (player1.shots[pos_x][pos_y][pos_z] == '0')) { - player1.shots[pos_x][pos_y][pos_z] == '1'; + player1.setShot(pos_x, pos_y, pos_z, 'hit'); player1.upScore(); } if ((player2.cube[pos_x][pos_y][pos_z] == "0") && (player1.shots[pos_x][pos_y][pos_z] == '0')) { player1.shots[pos_x][pos_y][pos_z] == '2'; - } - + } } if (req.params.playerName == 'player2') { if ((player1.cube[pos_x][pos_y][pos_z] == "1") && (player2.shots[pos_x][pos_y][pos_z] == '0')) { - player2.shots[pos_x][pos_y][pos_z] == '1'; + player2.setShot(pos_x, pos_y, pos_z, 'hit'); player2.upScore(); } if ((player1.cube[pos_x][pos_y][pos_z] == "0") && (player2.shots[pos_x][pos_y][pos_z] == '0')) { - player2.shots[pos_x][pos_y][pos_z] == '2'; + player1.setShot(pos_x, pos_y, pos_z, 'miss'); } - } // just for http 200 check diff --git a/lib/player.js b/lib/player.js index b007d89..1f11586 100644 --- a/lib/player.js +++ b/lib/player.js @@ -42,18 +42,8 @@ Player.prototype.getShots = function() { return this.shots; } -// Player.prototype.shoot = function(pos_x, pos_y, pos_z) { -// -// if ((this.cube[pos_x][pos_y][pos_z] == "1") && (this.shots[pos_x][pos_y][pos_z] == '0')) { -// return true; -// } -// if ((this.cube[pos_x][pos_y][pos_z] == "0") && (this.shots[pos_x][pos_y][pos_z] == '0')) { -// this.shots[pos_x][pos_y][pos_z] = '1'; -// return false; -// } -// -// this.shots[pos_x][pos_y][pos_z] = '1'; -// } - +Player.prototype.setShot = function(pos_x, pos_y, pos_z, shot) { + this.shots[pos_x][pos_y][pos_z] = shot; +} exports.Player = Player; \ No newline at end of file