Last active
May 20, 2016 08:29
-
-
Save ruudud/56dd140856f841d558aface24e1c787c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const blessed = require('blessed'); | |
const STATUS = { | |
pending: "PENDING" | |
}; | |
class Character { | |
tick() { | |
if (Math.random*2 > 1) { | |
this.fight(); | |
} else { | |
this.move(); | |
} | |
} | |
} | |
class Gummi extends Character { | |
constructor(x, y) { | |
this.type = 'gummi'; | |
this.x = x; | |
this.y = y; | |
} | |
fight() { | |
} | |
} | |
class Ogre extends Character { | |
constructor(x, y) { | |
this.type = 'ogre'; | |
this.x = x; | |
this.y = y; | |
} | |
} | |
class Battle { | |
constructor() { | |
this.status = STATUS.pending; | |
} | |
draw() { | |
var screen = blessed.screen({ | |
smartCSR: true | |
}); | |
screen.title = 'Gummi Bear vs Ogres'; | |
var map = blessed.box({ | |
top: 'center', | |
left: 'center', | |
width: '99%', | |
height: '99%', | |
content: 'The battle begins...', | |
border: { | |
type: 'line' | |
}, | |
style: { | |
fg: 'white', | |
bg: 'blue', | |
border: { | |
fg: 'white' | |
} | |
} | |
}); | |
screen.append(map); | |
screen.render(); | |
} | |
createMap(rows, cols) { | |
let map = []; | |
for (var i = 0; i < rows; i++) { | |
map.push(new Array(cols)); | |
} | |
this.map = map; | |
return map; | |
} | |
fillMap() { | |
this.map[0] = this.map[0].map(col => new Ogre()); | |
let lastrow = this.map.length - 1; | |
this.map[lastrow] = this.map[lastrow].map(col => new Gummi()); | |
return this.map; | |
} | |
earthQuake() { | |
// shake things up, move characters randomly around | |
} | |
tick() { | |
if (Math.random()*15 < 1) { | |
this.earthQuake(); | |
} | |
// Move characters around | |
// Since we don't have concurrency, switch between which army moves first | |
this.map.forEach(); | |
} | |
} | |
module.exports = Battle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "gummibattle", | |
"version": "0.0.1", | |
"description": "", | |
"main": "src/index.js", | |
"scripts": { | |
"test": "tape {src,test}/*.js | tap-dot || true", | |
"watch": "nodemon --watch src/ --watch test/ --exec 'npm run test'" | |
}, | |
"author": "Pål Ruud", | |
"license": "MIT", | |
"devDependencies": { | |
"nodemon": "^1.9.2", | |
"tap-dot": "^1.0.5", | |
"tape": "^4.5.1" | |
}, | |
"dependencies": { | |
"blessed": "^0.1.81" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = require('tape'); | |
test('battle', (t) => { | |
var Battle = require('../src/'); | |
var battle = new Battle(); | |
t.equal(battle.status, 'PENDING', 'Battle starts in pending status'); | |
var battleGround = battle.createMap(2,2); | |
t.equals(battleGround.length, 2, 'Can init map'); | |
t.equals(battleGround[0].length, 2, 'Can init map'); | |
battle.fillMap(); | |
t.equals(battle.map[0][0].type, 'ogre', 'fill first row with ogre'); | |
t.end(); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment