rebase to coding cookies style

This commit is contained in:
jwinterm
2017-11-25 13:20:36 -08:00
parent 1b27ad1f60
commit 2d142f70ef
15 changed files with 5676 additions and 50 deletions
+1
View File
@@ -1,2 +1,3 @@
## log files
npm-debug.log
/nbproject/private/
View File
View File
+3 -3
View File
@@ -3,9 +3,9 @@
<head>
<title>Socket.io Test</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="/socket.io/socket.io.js"></script>
<script src="js/game.js"></script>
<script src="https://ondras.github.io/rot.js/rot.js"></script>
<script src="node_modules/socket.io/socket.io.js"></script>
<script src="clientjs/game.js"></script>
<script src="clientjs/rot.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<meta charset="utf-8">
-31
View File
@@ -1,31 +0,0 @@
// map.js
// =========
var ROT = require('rot-js');
var w = 10;
var h = 10;
var maparray = [];
for(i = 0; i < w; i++) {
maparray.push([]);
}
function createArena(w, h) {
return new ROT.Map.Arena(w, h);
}
function printCallback(x, y, value) {
console.log(x, y, value);
}
function arrayCallback(x, y, value) {
maparray[x][y] = value;
console.log(x, y, value);
}
module.exports = {
maparray,
createArena,
printCallback,
arrayCallback,
};
+3
View File
@@ -0,0 +1,3 @@
files.encoding=UTF-8
site.root.folder=
source.folder=
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.clientproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/clientside-project/1">
<name>rotsock</name>
</data>
</configuration>
</project>
+5 -5
View File
@@ -4,8 +4,9 @@ var http = require('http').Server(app);
var io = require('socket.io')(http);
var ROT = require('rot-js');
var Map = require('./js/map.js')
var Player = require('./js/player.js')
var Map = require('./serverjs/map.js');
var Player = require('./serverjs/player.js');
var Glyph = require('./serverjs/glyph.js');
app.use(express.static(__dirname)); // Current directory is root
@@ -21,8 +22,7 @@ var Game = {
};
var map = Map.createArena(10, 10);
map.create(Map.arrayCallback);
console.log(Map.maparray);
map.consoleDisplay();
function findWithAttr(array, attr, value) {
for(var i = 0; i < array.length; i += 1) {
@@ -52,7 +52,7 @@ io.on('connection', function(socket){
function pushMap() {
for (player in Game.Players) {
io.to(player.id).emit("display", JSON.stringify(Map.maparray));
io.to(player.id).emit("display", JSON.stringify(map));
}
}
// setTimeout(pushMap, 1000);
+27
View File
@@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
Glyph = function(chr, foreground, background) {
// Instantiate properties to default if they weren't passed
this._char = chr || ' ';
this._foreground = foreground || 'white';
this._background = background || 'black';
};
// Create standard getters for glyphs
Glyph.prototype.getChar = function(){
return this._char;
}
Glyph.prototype.getBackground = function(){
return this._background;
}
Glyph.prototype.getForeground = function(){
return this._foreground;
}
module.exports = {
Glyph,
};
+72
View File
@@ -0,0 +1,72 @@
// map.js
// =========
var ROT = require('rot-js');
var Glyph = require('./glyph.js');
var Tile = require('./tile.js');
var w = 80;
var h = 40;
function Map(tiles) {
this._tiles = tiles;
// cache the width and height based
// on the length of the dimensions of
// the tiles array
this._width = tiles.length;
this._height = tiles[0].length;
};
// Standard getters
Map.prototype.getWidth = function() {
return this._width;
};
Map.prototype.getHeight = function() {
return this._height;
};
// Gets the tile for a given coordinate set
Map.prototype.getTile = function(x, y) {
// Make sure we are inside the bounds. If we aren't, return
// null tile.
if (x < 0 || x >= this._width || y < 0 || y >= this._height) {
return Tile.nullTile;
} else {
return this._tiles[x][y] || Tile.nullTile;
}
};
Map.prototype.consoleDisplay = function() {
for (var x = 0; x < this.getWidth(); x++) {
for (var y = 0; y < this.getHeight(); y++) {
console.log(this.getTile(x, y));
}
console.log('\n');
}
}
function createArena(w, h) {
var tilearray = []
for (var x = 0; x < w; x++) {
tilearray.push([]);
for (var y = 0; y < h; y++) {
tilearray[x].push(Tile.Tile.nullTile);
}
}
console.log(tilearray);
var generator = new ROT.Map.Arena(w, h);
generator.create(function(x, y, v) {
if (v === 1) {
tilearray[x][y] = Tile.Tile.floorTile;
} else {
tilearray[x][y] = Tile.Tile.wallTile;
}
});
return new Map(tilearray);
}
module.exports = {
Map,
createArena,
};
+14 -11
View File
@@ -2,19 +2,23 @@
// ============
function createPlayer(nick, addy, id, ip) {
function Player(nick, addy, id, ip) {
// Setup the bookkeeping stuff
this.nick = nick || "Anon";
this.addy = addy || "MLaMWLvFJMai3czhrK6peenVT2S2hFgmUi";
this.id = id;
this.ip = ip;
this.jointime = Date.now();
this.x = 0;
this.y = 0;
this._nick = nick || "Anon";
this._addy = addy || "MLaMWLvFJMai3czhrK6peenVT2S2hFgmUi";
this._id = id;
this._ip = ip;
this._jointime = Date.now();
this._x = 0;
this._y = 0;
return this;
};
function processInput(key) {
Player.prototype.getNick = function() {
return this._nick;
}
Player.prototype.processInput = function(key) {
if (key == "VK_K" || key == "VK_NUMPAD8" || key == "VK_UP") {
dir = ROT.DIRS["8"][0];
}
@@ -46,8 +50,7 @@ function processInput(key) {
}
module.exports = {
createPlayer,
processInput,
Player,
};
+5519
View File
File diff suppressed because it is too large Load Diff
+23
View File
@@ -0,0 +1,23 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var Glyph = require('./glyph.js');
Tile = function(glyph) {
this._glyph = glyph;
};
Tile.prototype.getGlyph = function() {
return this._glyph;
};
Tile.nullTile = new Tile(new Glyph.Glyph());
Tile.floorTile = new Tile(new Glyph.Glyph('.'));
Tile.wallTile = new Tile(new Glyph.Glyph('#', 'goldenrod'));
module.exports = {
Tile,
};