Compare commits
No commits in common. "master" and "clear-on-exit" have entirely different histories.
master
...
clear-on-e
2
.replit
2
.replit
@ -1,2 +0,0 @@
|
|||||||
language = "nodejs"
|
|
||||||
run = "npm i; npm i babel-polyfill; npm i ansi; echo Which game do you want; echo spacecraft; echo snake; echo tanks; read game; echo what language; echo es or en; read lang; node index.js $game"
|
|
13
README.md
13
README.md
@ -2,24 +2,13 @@ node-games
|
|||||||
==========
|
==========
|
||||||
|
|
||||||
Some fun console games written using Node.
|
Some fun console games written using Node.
|
||||||
[![Run on Repl.it](https://repl.it/badge/github/mdibaiee/node-games)](https://repl.it/github/mdibaiee/node-games)
|
|
||||||
```
|
```
|
||||||
npm i -g node-games
|
npm i -g node-games
|
||||||
|
|
||||||
node-games
|
node-games
|
||||||
```
|
```
|
||||||
|
|
||||||
language
|
|
||||||
--------
|
|
||||||
|
|
||||||
In order to select another language you can specify it from the command line:
|
|
||||||
|
|
||||||
```
|
|
||||||
node-games <game_name> <language>
|
|
||||||
```
|
|
||||||
|
|
||||||
Available languages: es, en.
|
|
||||||
|
|
||||||
spacecraft
|
spacecraft
|
||||||
----------
|
----------
|
||||||
![spacecraft](https://raw.githubusercontent.com/mdibaiee/node-games/master/spacecraft.gif)
|
![spacecraft](https://raw.githubusercontent.com/mdibaiee/node-games/master/spacecraft.gif)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
||||||
|
|
||||||
var _ansi = require('ansi');
|
var _ansi = require('ansi');
|
||||||
|
|
||||||
var _ansi2 = _interopRequireDefault(_ansi);
|
var _ansi2 = _interopRequireDefault(_ansi);
|
||||||
@ -14,29 +14,28 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var _process = process,
|
var _process = process;
|
||||||
stdout = _process.stdout,
|
var stdout = _process.stdout;
|
||||||
stdin = _process.stdin;
|
var stdin = _process.stdin;
|
||||||
|
|
||||||
|
|
||||||
var listeners = [];
|
var listeners = [];
|
||||||
|
|
||||||
var prefix = '\x1B';
|
var prefix = '\u001b';
|
||||||
var keys = {
|
var keys = {
|
||||||
right: prefix + '[C',
|
right: prefix + '[C',
|
||||||
up: prefix + '[A',
|
up: prefix + '[A',
|
||||||
left: prefix + '[D',
|
left: prefix + '[D',
|
||||||
down: prefix + '[B',
|
down: prefix + '[B',
|
||||||
exit: '\x03',
|
exit: '\u0003',
|
||||||
space: ' '
|
space: ' '
|
||||||
};
|
};
|
||||||
|
|
||||||
var Interface = function () {
|
var Interface = (function () {
|
||||||
function Interface() {
|
function Interface() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
var output = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : stdout;
|
var output = arguments.length <= 0 || arguments[0] === undefined ? stdout : arguments[0];
|
||||||
var input = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : stdin;
|
var input = arguments.length <= 1 || arguments[1] === undefined ? stdin : arguments[1];
|
||||||
|
|
||||||
_classCallCheck(this, Interface);
|
_classCallCheck(this, Interface);
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ var Interface = function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (key === 'exit') {
|
if (key === 'exit') {
|
||||||
_this.output.write('\x1B[2J\x1B[0;0H');
|
_this.output.write('\u001b[2J\u001b[0;0H');
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ var Interface = function () {
|
|||||||
_createClass(Interface, [{
|
_createClass(Interface, [{
|
||||||
key: 'clear',
|
key: 'clear',
|
||||||
value: function clear() {
|
value: function clear() {
|
||||||
this.output.write('\x1B[2J\x1B[0;0H');
|
this.output.write('\u001b[2J\u001b[0;0H');
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'write',
|
key: 'write',
|
||||||
@ -111,7 +110,6 @@ var Interface = function () {
|
|||||||
|
|
||||||
var y = from.y;
|
var y = from.y;
|
||||||
|
|
||||||
|
|
||||||
for (var x = from.x; x < to.x; x++) {
|
for (var x = from.x; x < to.x; x++) {
|
||||||
this.cursor.goto(x, y);
|
this.cursor.goto(x, y);
|
||||||
this.write('.');
|
this.write('.');
|
||||||
@ -147,6 +145,6 @@ var Interface = function () {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Interface;
|
return Interface;
|
||||||
}();
|
})();
|
||||||
|
|
||||||
exports.default = Interface;
|
exports.default = Interface;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
exports.Bullet = undefined;
|
exports.Bullet = undefined;
|
||||||
|
|
||||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
||||||
|
|
||||||
var _unit = require('./unit');
|
var _unit = require('./unit');
|
||||||
|
|
||||||
var _unit2 = _interopRequireDefault(_unit);
|
var _unit2 = _interopRequireDefault(_unit);
|
||||||
@ -21,13 +21,13 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|||||||
|
|
||||||
var BULLET_SPEED = 10;
|
var BULLET_SPEED = 10;
|
||||||
|
|
||||||
var Tank = function (_Unit) {
|
var Tank = (function (_Unit) {
|
||||||
_inherits(Tank, _Unit);
|
_inherits(Tank, _Unit);
|
||||||
|
|
||||||
function Tank(ui) {
|
function Tank(ui) {
|
||||||
_classCallCheck(this, Tank);
|
_classCallCheck(this, Tank);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, (Tank.__proto__ || Object.getPrototypeOf(Tank)).call(this, ui));
|
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Tank).call(this, ui));
|
||||||
|
|
||||||
_this._angle = 0;
|
_this._angle = 0;
|
||||||
_this.bullets = [];
|
_this.bullets = [];
|
||||||
@ -51,8 +51,8 @@ var Tank = function (_Unit) {
|
|||||||
value: function draw() {
|
value: function draw() {
|
||||||
if (this.dead) return;
|
if (this.dead) return;
|
||||||
|
|
||||||
var x = this.x,
|
var x = this.x;
|
||||||
y = this.y;
|
var y = this.y;
|
||||||
|
|
||||||
if (this.color && this.color[0] === '#') {
|
if (this.color && this.color[0] === '#') {
|
||||||
this.output.cursor.hex(this.color);
|
this.output.cursor.hex(this.color);
|
||||||
@ -64,7 +64,7 @@ var Tank = function (_Unit) {
|
|||||||
x = Math.round(x) + 2;
|
x = Math.round(x) + 2;
|
||||||
y = Math.round(y) - 2;
|
y = Math.round(y) - 2;
|
||||||
|
|
||||||
var cannon = void 0;
|
var cannon = undefined;
|
||||||
if (this.angle < 35) cannon = '_';else if (this.angle < 70) cannon = '/';else if (this.angle < 115) cannon = '|';else if (this.angle < 160) cannon = '\\';else cannon = '_';
|
if (this.angle < 35) cannon = '_';else if (this.angle < 70) cannon = '/';else if (this.angle < 115) cannon = '|';else if (this.angle < 160) cannon = '\\';else cannon = '_';
|
||||||
|
|
||||||
this.output.cursor.goto(x + 2, y - 2);
|
this.output.cursor.goto(x + 2, y - 2);
|
||||||
@ -104,17 +104,17 @@ var Tank = function (_Unit) {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Tank;
|
return Tank;
|
||||||
}(_unit2.default);
|
})(_unit2.default);
|
||||||
|
|
||||||
exports.default = Tank;
|
exports.default = Tank;
|
||||||
|
|
||||||
var Bullet = exports.Bullet = function (_Unit2) {
|
var Bullet = exports.Bullet = (function (_Unit2) {
|
||||||
_inherits(Bullet, _Unit2);
|
_inherits(Bullet, _Unit2);
|
||||||
|
|
||||||
function Bullet(ui) {
|
function Bullet(ui) {
|
||||||
_classCallCheck(this, Bullet);
|
_classCallCheck(this, Bullet);
|
||||||
|
|
||||||
var _this2 = _possibleConstructorReturn(this, (Bullet.__proto__ || Object.getPrototypeOf(Bullet)).call(this, ui));
|
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Bullet).call(this, ui));
|
||||||
|
|
||||||
_this2.velocity = [0, 0];
|
_this2.velocity = [0, 0];
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ var Bullet = exports.Bullet = function (_Unit2) {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Bullet;
|
return Bullet;
|
||||||
}(_unit2.default);
|
})(_unit2.default);
|
||||||
|
|
||||||
function _radian(deg) {
|
function _radian(deg) {
|
||||||
return deg * Math.PI / 180;
|
return deg * Math.PI / 180;
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
||||||
|
|
||||||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Unit = function () {
|
var Unit = (function () {
|
||||||
function Unit(output) {
|
function Unit(output) {
|
||||||
_classCallCheck(this, Unit);
|
_classCallCheck(this, Unit);
|
||||||
|
|
||||||
@ -33,9 +33,9 @@ var Unit = function () {
|
|||||||
value: function draw() {
|
value: function draw() {
|
||||||
if (this.dead) return;
|
if (this.dead) return;
|
||||||
|
|
||||||
var x = this.x,
|
var x = this.x;
|
||||||
y = this.y,
|
var y = this.y;
|
||||||
shape = this.shape;
|
var shape = this.shape;
|
||||||
|
|
||||||
if (this.color && this.color[0] === '#') {
|
if (this.color && this.color[0] === '#') {
|
||||||
this.output.cursor.hex(this.color);
|
this.output.cursor.hex(this.color);
|
||||||
@ -123,6 +123,6 @@ var Unit = function () {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Unit;
|
return Unit;
|
||||||
}();
|
})();
|
||||||
|
|
||||||
exports.default = Unit;
|
exports.default = Unit;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })();
|
||||||
|
|
||||||
var _unit = require('./classes/unit');
|
var _unit = require('./classes/unit');
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ function loop() {
|
|||||||
gameover();
|
gameover();
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.cursor.goto(0, 0).yellow().write(i18n.__('Score') + ': ' + score);
|
ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
|
|
||||||
setTimeout(loop, FRAME);
|
setTimeout(loop, FRAME);
|
||||||
@ -107,7 +107,7 @@ function createPart() {
|
|||||||
var part = new _unit2.default(ui);
|
var part = new _unit2.default(ui);
|
||||||
var last = snake[snake.length - 1];
|
var last = snake[snake.length - 1];
|
||||||
|
|
||||||
var direction = void 0;
|
var direction = undefined;
|
||||||
if (!last) {
|
if (!last) {
|
||||||
direction = UP;
|
direction = UP;
|
||||||
} else {
|
} else {
|
||||||
@ -132,7 +132,7 @@ function createPart() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
part.speed = function () {
|
part.speed = function () {
|
||||||
var multiplier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
var multiplier = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
|
||||||
var direction = part.direction;
|
var direction = part.direction;
|
||||||
|
|
||||||
var x = direction == LEFT ? -1 : direction == RIGHT ? 1 : 0;
|
var x = direction == LEFT ? -1 : direction == RIGHT ? 1 : 0;
|
||||||
@ -141,10 +141,12 @@ function createPart() {
|
|||||||
return [x * multiplier, y * multiplier];
|
return [x * multiplier, y * multiplier];
|
||||||
};
|
};
|
||||||
|
|
||||||
var _part$speed = part.speed(),
|
var _part$speed = part.speed();
|
||||||
_part$speed2 = _slicedToArray(_part$speed, 2),
|
|
||||||
dX = _part$speed2[0],
|
var _part$speed2 = _slicedToArray(_part$speed, 2);
|
||||||
dY = _part$speed2[1];
|
|
||||||
|
var dX = _part$speed2[0];
|
||||||
|
var dY = _part$speed2[1];
|
||||||
|
|
||||||
dX *= -1;
|
dX *= -1;
|
||||||
dY *= -1;
|
dY *= -1;
|
||||||
@ -159,7 +161,7 @@ function createPart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function gameover() {
|
function gameover() {
|
||||||
var MSG = i18n.__('Game Over');
|
var MSG = 'Game Over!';
|
||||||
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
|
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
|
||||||
ui.cursor.red();
|
ui.cursor.red();
|
||||||
ui.cursor.bold();
|
ui.cursor.bold();
|
||||||
@ -167,7 +169,7 @@ function gameover() {
|
|||||||
|
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
ui.cursor.hex('#f65590');
|
ui.cursor.hex('#f65590');
|
||||||
var RETRY = i18n.__('Press any key to play again');
|
var RETRY = 'Press any key to play again';
|
||||||
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
||||||
ui.write(RETRY);
|
ui.write(RETRY);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ setInterval(function () {
|
|||||||
if (enemy.killed < 3) enemy.killed++;
|
if (enemy.killed < 3) enemy.killed++;
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.cursor.goto(0, 0).yellow().write(i18n.__('Score') + ': ' + score);
|
ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
}, FRAME);
|
}, FRAME);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ function loop() {
|
|||||||
|
|
||||||
if (one.dead || two.dead) {
|
if (one.dead || two.dead) {
|
||||||
var num = one.dead ? '2' : '1';
|
var num = one.dead ? '2' : '1';
|
||||||
var msg = i18n.__('Player %s won!', num);
|
var msg = 'Player ' + num + ' won!';
|
||||||
ui.cursor.red();
|
ui.cursor.red();
|
||||||
ui.cursor.bold();
|
ui.cursor.bold();
|
||||||
|
|
||||||
@ -62,12 +62,12 @@ function loop() {
|
|||||||
|
|
||||||
ui.cursor.goto(0, 1);
|
ui.cursor.goto(0, 1);
|
||||||
if (turn() === one) ui.cursor.hex('#54ffff');
|
if (turn() === one) ui.cursor.hex('#54ffff');
|
||||||
ui.write(i18n.__('Player') + ' 1');
|
ui.write('Player 1');
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
ui.cursor.goto(0, 2);
|
ui.cursor.goto(0, 2);
|
||||||
ui.write(i18n.__('Health') + ': ' + one.health);
|
ui.write('Health: ' + one.health);
|
||||||
ui.cursor.goto(0, 3);
|
ui.cursor.goto(0, 3);
|
||||||
ui.write(i18n.__('Angle') + ': ' + parseInt(one.angle));
|
ui.write('Angle: ' + parseInt(one.angle));
|
||||||
|
|
||||||
two.draw();
|
two.draw();
|
||||||
two.bullets.forEach(function (bullet, i) {
|
two.bullets.forEach(function (bullet, i) {
|
||||||
@ -87,12 +87,13 @@ function loop() {
|
|||||||
|
|
||||||
ui.cursor.goto(ui.output.columns - 10, 1);
|
ui.cursor.goto(ui.output.columns - 10, 1);
|
||||||
if (turn() === two) ui.cursor.hex('#54ffff');
|
if (turn() === two) ui.cursor.hex('#54ffff');
|
||||||
ui.write(i18n.__('Player') + ' 2');
|
ui.write('Player 2');
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
ui.cursor.goto(ui.output.columns - 10, 2);
|
ui.cursor.goto(ui.output.columns - 10, 2);
|
||||||
ui.write(i18n.__('Health') + ': ' + two.health);
|
ui.write('Health: ' + two.health);
|
||||||
ui.cursor.goto(ui.output.columns - 10, 3);
|
ui.cursor.goto(ui.output.columns - 10, 3);
|
||||||
ui.write(i18n.__('Angle') + ': ' + parseInt(two.angle));
|
ui.write('Angle: ' + parseInt(two.angle));
|
||||||
|
|
||||||
setTimeout(loop, FRAME);
|
setTimeout(loop, FRAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
index.js
16
index.js
@ -1,21 +1,11 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
i18n = require('i18n');
|
var game = process.argv[2];
|
||||||
path = require('path');
|
|
||||||
language = process.argv[3]
|
|
||||||
|
|
||||||
i18n.configure({
|
|
||||||
directory: path.join(__dirname, '/locales')
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.setLocale(language || 'en');
|
|
||||||
|
|
||||||
game = process.argv[2];
|
|
||||||
|
|
||||||
if (!game) {
|
if (!game) {
|
||||||
console.log('usage: node-games <game>');
|
console.log('usage: node-games <game>')
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log(i18n.__('Games'));
|
console.log('Games');
|
||||||
console.log('- spacecraft');
|
console.log('- spacecraft');
|
||||||
console.log('- snake');
|
console.log('- snake');
|
||||||
console.log('- tanks');
|
console.log('- tanks');
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"Score": "Score",
|
|
||||||
"Game Over": "Game Over!",
|
|
||||||
"Press any key to play again": "Press any key to play again",
|
|
||||||
"Angle": "Angle",
|
|
||||||
"Health": "Health",
|
|
||||||
"Player": "Player",
|
|
||||||
"Games": "Games",
|
|
||||||
"Player %s won!": "Player %s won!"
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"Score": "Puntaje",
|
|
||||||
"Game Over": "Juego terminado!",
|
|
||||||
"Press any key to play again": "Pulsa cualquier tecla para volver a jugar",
|
|
||||||
"Angle": "Ángulo",
|
|
||||||
"Health": "Salud",
|
|
||||||
"Player": "Jugador",
|
|
||||||
"Games": "Juegos",
|
|
||||||
"Player %s won!": "El jugador %s ganó!"
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-games",
|
"name": "node-games",
|
||||||
"version": "3.0.3",
|
"version": "3.0.2",
|
||||||
"description": "Simple node console games",
|
"description": "Simple node console games",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -25,8 +25,7 @@
|
|||||||
"ansi": "0.3.0",
|
"ansi": "0.3.0",
|
||||||
"babel-core": "6.3.17",
|
"babel-core": "6.3.17",
|
||||||
"babel-polyfill": "6.3.14",
|
"babel-polyfill": "6.3.14",
|
||||||
"babel-preset-es2015": "6.3.13",
|
"babel-preset-es2015": "6.3.13"
|
||||||
"i18n": "^0.8.3"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "0.4.5",
|
"grunt": "0.4.5",
|
||||||
|
@ -49,7 +49,7 @@ function loop() {
|
|||||||
gameover();
|
gameover();
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.cursor.goto(0, 0).yellow().write(`${i18n.__('Score')}: ${score}`);
|
ui.cursor.goto(0, 0).yellow().write(`Score: ${score}`);
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
|
|
||||||
setTimeout(loop, FRAME);
|
setTimeout(loop, FRAME);
|
||||||
@ -147,7 +147,7 @@ function createPart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function gameover() {
|
function gameover() {
|
||||||
const MSG = i18n.__('Game Over');
|
const MSG = 'Game Over!';
|
||||||
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
|
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
|
||||||
ui.cursor.red();
|
ui.cursor.red();
|
||||||
ui.cursor.bold();
|
ui.cursor.bold();
|
||||||
@ -155,7 +155,7 @@ function gameover() {
|
|||||||
|
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
ui.cursor.hex('#f65590');
|
ui.cursor.hex('#f65590');
|
||||||
const RETRY = i18n.__('Press any key to play again');
|
const RETRY = 'Press any key to play again';
|
||||||
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
||||||
ui.write(RETRY);
|
ui.write(RETRY);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ setInterval(() => {
|
|||||||
if (enemy.killed < 3) enemy.killed++;
|
if (enemy.killed < 3) enemy.killed++;
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.cursor.goto(0, 0).yellow().write(`${i18n.__('Score')}: ${score}`);
|
ui.cursor.goto(0, 0).yellow().write(`Score: ${score}`);
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
}, FRAME);
|
}, FRAME);
|
||||||
|
|
||||||
|
15
src/tanks.js
15
src/tanks.js
@ -21,7 +21,7 @@ function loop() {
|
|||||||
|
|
||||||
if (one.dead || two.dead) {
|
if (one.dead || two.dead) {
|
||||||
let num = one.dead ? '2' : '1';
|
let num = one.dead ? '2' : '1';
|
||||||
const msg = i18n.__('Player %s won!', num);
|
const msg = `Player ${num} won!`;
|
||||||
ui.cursor.red();
|
ui.cursor.red();
|
||||||
ui.cursor.bold();
|
ui.cursor.bold();
|
||||||
|
|
||||||
@ -50,12 +50,12 @@ function loop() {
|
|||||||
|
|
||||||
ui.cursor.goto(0, 1);
|
ui.cursor.goto(0, 1);
|
||||||
if (turn() === one) ui.cursor.hex('#54ffff');
|
if (turn() === one) ui.cursor.hex('#54ffff');
|
||||||
ui.write(`${i18n.__('Player')} 1`);
|
ui.write('Player 1');
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
ui.cursor.goto(0, 2);
|
ui.cursor.goto(0, 2);
|
||||||
ui.write(`${i18n.__('Health')}: ${one.health}`);
|
ui.write('Health: ' + one.health);
|
||||||
ui.cursor.goto(0, 3);
|
ui.cursor.goto(0, 3);
|
||||||
ui.write(`${i18n.__('Angle')}: ${parseInt(one.angle)}`);
|
ui.write('Angle: ' + parseInt(one.angle));
|
||||||
|
|
||||||
two.draw();
|
two.draw();
|
||||||
two.bullets.forEach((bullet, i) => {
|
two.bullets.forEach((bullet, i) => {
|
||||||
@ -75,12 +75,13 @@ function loop() {
|
|||||||
|
|
||||||
ui.cursor.goto(ui.output.columns - 10, 1);
|
ui.cursor.goto(ui.output.columns - 10, 1);
|
||||||
if (turn() === two) ui.cursor.hex('#54ffff');
|
if (turn() === two) ui.cursor.hex('#54ffff');
|
||||||
ui.write(`${i18n.__('Player')} 2`);
|
ui.write('Player 2');
|
||||||
ui.cursor.reset();
|
ui.cursor.reset();
|
||||||
ui.cursor.goto(ui.output.columns - 10, 2);
|
ui.cursor.goto(ui.output.columns - 10, 2);
|
||||||
ui.write(`${i18n.__('Health')}: ${two.health}`);
|
ui.write('Health: ' + two.health);
|
||||||
ui.cursor.goto(ui.output.columns - 10, 3);
|
ui.cursor.goto(ui.output.columns - 10, 3);
|
||||||
ui.write(`${i18n.__('Angle')}: ${parseInt(two.angle)}`);
|
ui.write('Angle: ' + parseInt(two.angle));
|
||||||
|
|
||||||
setTimeout(loop, FRAME);
|
setTimeout(loop, FRAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user