aboutsummaryrefslogtreecommitdiffstats
path: root/rogue-server.js
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2019-12-04 17:20:16 -0500
committerMatt Kohls <mattkohls13@gmail.com>2019-12-04 17:20:16 -0500
commit484d7613dbc7d8064e524e8c751d92f06e481616 (patch)
tree825ff0fb3f51545fddf4ec7315283a9f9fdf8bea /rogue-server.js
parent6f5579903f25e21419912ed851d0c2f6a7bdc151 (diff)
downloadrogue.js-484d7613dbc7d8064e524e8c751d92f06e481616.tar.gz
rogue.js-484d7613dbc7d8064e524e8c751d92f06e481616.tar.bz2
rogue.js-484d7613dbc7d8064e524e8c751d92f06e481616.zip
Adding some floors and move functionality
Diffstat (limited to 'rogue-server.js')
-rw-r--r--rogue-server.js61
1 files changed, 56 insertions, 5 deletions
diff --git a/rogue-server.js b/rogue-server.js
index af0b10d..59b6c21 100644
--- a/rogue-server.js
+++ b/rogue-server.js
@@ -30,9 +30,12 @@ class Location {
this.floor = floor;
}
- get x { return this.x; }
- get y { return this.y; }
- get floor { return this.floor; }
+ get x() { return this.x; }
+ set x(value) { this.x = value; }
+ get y() { return this.y; }
+ set y(value) { this.y = value; }
+ get floor() { return this.floor; }
+ set floor(value) { this.floor = value; }
}
class Item {
@@ -229,6 +232,7 @@ class Mob {
var mobs = [];
var dead = [];
+const floors = require('./floors.json');
/**
* Generates the turn order by placing the index of the mob into an array.
@@ -271,8 +275,55 @@ function attack(mobA, mobB, type) {
}
function move(mob, dir) {
-
-
+ var location = mobs[mob].location;
+ switch(dir) {
+ case 'w':
+ location.x = location.x - 1;
+ break;
+ case 'a':
+ location.y = location.y - 1;
+ break;
+ case 's':
+ location.y = location.y + 1;
+ break;
+ case 'd':
+ location.x = location.x + 1;
+ break;
+ case '.':
+ var symbol = floors[location.floor].charAt(location.y * 40 + location.x);
+ if(symbol == '>') {
+ location.floor = location.floor + 1;
+ if(location.floor > floors.length - 1) {
+ return "Already at bottom floor";
+ }
+ mobs[mob].location = location;
+ return "Go down the stairs";
+ } else if(symbol == '<') {
+ location.floor = location.floor - 1;
+ if(location.floor < 0) {
+ return "Already at top floor";
+ }
+ mobs[mob].location = location;
+ return "Go up the stairs";
+ }
+ break;
+ default:
+ break;
+ }
+ if(location.x < 0 || location.x > 99 || location.y < 0 || location.y > 39) {
+ return "Hit a wall";
+ }
+ if(floors[location.floor].charAt(location.y * 40 + location.x) == '*') {
+ return "Hit a wall";
+ }
+ for(var i = 0; i < mobs.length; i++) {
+ if(mobs[i].location.floor == location.floor) {
+ if(mobs[i].location.x == location.x && mobs[i].location.y == location.y) {
+ return attack(mob, i, "weapon");
+ }
+ }
+ }
+ mobs[mob].location = location;
}
function cast(mob, dir) {