Skip to content

Commit

Permalink
hit/miss
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebla committed Aug 28, 2011
1 parent f899553 commit 38996f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
14 changes: 8 additions & 6 deletions arduino_client.js
Expand Up @@ -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);
})
// http.get(options, function(res) {
// console.log("Got response: " + res.statusCode);
// }).on('error', function(e) {
// console.log("Got error: " + e.message);
// })
15 changes: 5 additions & 10 deletions game_server.js
Expand Up @@ -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
Expand Down
16 changes: 3 additions & 13 deletions lib/player.js
Expand Up @@ -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;

0 comments on commit 38996f8

Please sign in to comment.