Use Polyglot to add spanish translations

This commit is contained in:
Julian Calvento 2019-05-09 17:04:06 -03:00
parent dd48a879c2
commit c1198070bd
16 changed files with 126 additions and 1139 deletions

View File

@ -10,6 +10,14 @@ module.exports = function(grunt) {
}]
}
},
copy: {
main: {
expand: true,
cwd: 'src',
src: 'locales/*',
dest: 'build'
}
},
watch: {
scripts: {
files: ['src/**/*.js'],
@ -20,6 +28,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('default', ['babel']);
};

View File

@ -1,150 +0,0 @@
'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", {
value: true
});
var _ansi = require('ansi');
var _ansi2 = _interopRequireDefault(_ansi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _process = process;
var stdout = _process.stdout;
var stdin = _process.stdin;
var listeners = [];
var prefix = '\u001b';
var keys = {
right: prefix + '[C',
up: prefix + '[A',
left: prefix + '[D',
down: prefix + '[B',
exit: '\u0003',
space: ' '
};
var Interface = (function () {
function Interface() {
var _this = this;
var output = arguments.length <= 0 || arguments[0] === undefined ? stdout : arguments[0];
var input = arguments.length <= 1 || arguments[1] === undefined ? stdin : arguments[1];
_classCallCheck(this, Interface);
this.output = output;
this.input = input;
this.input.setRawMode(true);
this.input.setEncoding('utf8');
this.cursor = (0, _ansi2.default)(this.output).hide();
this.input.addListener('data', function (data) {
var always = listeners.filter(function (listener) {
return listener.key === '';
});
always.forEach(function (listener) {
return listener.fn();
});
var key = Object.keys(keys).find(function (value, i) {
return keys[value] === data;
});
if (key === 'exit') {
_this.output.write('\u001b[2J\u001b[0;0H');
process.exit();
}
var match = listeners.filter(function (listener) {
return listener.key === key || listener.key === data;
});
match.forEach(function (listener) {
return listener.fn();
});
});
}
_createClass(Interface, [{
key: 'clear',
value: function clear() {
this.output.write('\u001b[2J\u001b[0;0H');
}
}, {
key: 'write',
value: function write() {
var _cursor;
(_cursor = this.cursor).write.apply(_cursor, arguments);
}
}, {
key: 'onKey',
value: function onKey(key, fn) {
if (typeof key === 'function') {
fn = key;
key = '';
}
listeners.push({ key: key, fn: fn });
}
}, {
key: 'line',
value: function line(from, to) {
var delta = {
x: to.x - from.x,
y: to.y - from.y
};
var error = 0;
var deltaerr = Math.abs(delta.y / delta.x);
var y = from.y;
for (var x = from.x; x < to.x; x++) {
this.cursor.goto(x, y);
this.write('.');
error += deltaerr;
while (error >= 0.5) {
this.cursor.goto(x, y);
this.write('.');
y += Math.sign(delta.y);
error -= 1;
}
}
}
}, {
key: 'columns',
get: function get() {
return this.output.columns;
}
}, {
key: 'rows',
get: function get() {
return this.output.rows;
}
}, {
key: 'center',
get: function get() {
return {
x: this.output.columns / 2,
y: this.output.rows / 2
};
}
}]);
return Interface;
})();
exports.default = Interface;

View File

@ -1,5 +0,0 @@
0(0) = 0,1
45(0.7853981633974483) = 0.7071067811865475,0.7071067811865476
112.5(1.9634954084936207) = 0.9238795325112867,-0.3826834323650897
157.5(2.748893571891069) = 0.3826834323650899,-0.9238795325112867
180(3.141592653589793) = 1.2246467991473532e-16,-1

View File

@ -1,162 +0,0 @@
'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", {
value: true
});
exports.Bullet = undefined;
var _unit = require('./unit');
var _unit2 = _interopRequireDefault(_unit);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var BULLET_SPEED = 10;
var Tank = (function (_Unit) {
_inherits(Tank, _Unit);
function Tank(ui) {
_classCallCheck(this, Tank);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Tank).call(this, ui));
_this._angle = 0;
_this.bullets = [];
_this.health = 100;
_this.size = { x: 5, y: 3 };
return _this;
}
_createClass(Tank, [{
key: 'shoot',
value: function shoot() {
var bullet = new Bullet(this.output);
bullet.go(this.x + 2, this.y - 2);
bullet.velocity = this.normalize();
this.bullets.push(bullet);
}
}, {
key: 'draw',
value: function draw() {
if (this.dead) return;
var x = this.x;
var y = this.y;
if (this.color && this.color[0] === '#') {
this.output.cursor.hex(this.color);
} else if (this.color) {
this.output.cursor[this.color]();
}
if (this.bold) this.output.cursor.bold();
x = Math.round(x) + 2;
y = Math.round(y) - 2;
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 = '_';
this.output.cursor.goto(x + 2, y - 2);
this.output.write(cannon);
this.output.cursor.goto(x, y - 1);
this.output.write('.===.');
this.output.cursor.goto(x, y);
this.output.write('o===o');
this.output.cursor.reset();
}
}, {
key: 'normalize',
value: function normalize() {
return [Math.cos(this._angle), Math.sin(this._angle) * -1];
}
}, {
key: 'angle',
set: function set(deg) {
if (deg < 0) deg = 0;
if (deg > 180) deg = 180;
this._angle = _radian(deg);
},
get: function get() {
return _degree(this._angle);
}
}], [{
key: 'radian',
value: function radian(deg) {
return _radian(deg);
}
}, {
key: 'degree',
value: function degree(rad) {
return _degree(rad);
}
}]);
return Tank;
})(_unit2.default);
exports.default = Tank;
var Bullet = exports.Bullet = (function (_Unit2) {
_inherits(Bullet, _Unit2);
function Bullet(ui) {
_classCallCheck(this, Bullet);
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Bullet).call(this, ui));
_this2.velocity = [0, 0];
_this2.shape = '•';
_this2.color = 'red';
_this2.dieOnExit = true;
_this2.gravity = [0.8, 0.8];
_this2.acceleration = [0, 0.015];
return _this2;
}
_createClass(Bullet, [{
key: 'speed',
value: function speed() {
this.velocity[0] += this.acceleration[0];
this.velocity[1] += this.acceleration[1];
var x = this.velocity[0] * this.gravity[0];
var y = this.velocity[1] * this.gravity[1];
return [x, y];
}
}, {
key: 'collides',
value: function collides(target) {
var targetX = Math.round(target.x);
var targetY = Math.round(target.y);
var x = Math.round(this.x);
var y = Math.round(this.y);
return x > targetX - target.size.x && x < targetX + target.size.x && y > targetY - target.size.y && y < targetY + target.size.y;
}
}]);
return Bullet;
})(_unit2.default);
function _radian(deg) {
return deg * Math.PI / 180;
}
function _degree(rad) {
return rad * 180 / Math.PI;
}

View File

@ -1,128 +0,0 @@
'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", {
value: true
});
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"); } }
var Unit = (function () {
function Unit(output) {
_classCallCheck(this, Unit);
this._health = 0;
this.dead = false;
this.output = output;
this.dieOnExit = false;
}
_createClass(Unit, [{
key: 'move',
value: function move(x, y) {
if (!x && !y) return this.move.apply(this, _toConsumableArray(this.speed()));
this.x += x;
this.y += y;
}
}, {
key: 'draw',
value: function draw() {
if (this.dead) return;
var x = this.x;
var y = this.y;
var shape = this.shape;
if (this.color && this.color[0] === '#') {
this.output.cursor.hex(this.color);
} else if (this.color) {
this.output.cursor[this.color]();
}
if (this.bold) this.output.cursor.bold();
this.output.cursor.goto(Math.round(x), Math.round(y));
this.output.write(shape);
this.output.cursor.reset();
}
}, {
key: 'go',
value: function go(x, y) {
this.x = x;
this.y = y;
}
}, {
key: 'random',
value: function random() {
this.x = Math.max(1, Math.floor(Math.random() * this.output.columns));
this.y = Math.max(1, Math.floor(Math.random() * this.output.rows));
}
}, {
key: 'speed',
value: function speed() {
var signs = [Math.random() > 0.5 ? -1 : 1, Math.random() > 0.5 ? -1 : 1];
return [Math.random() * signs[0], Math.random() * signs[1]];
}
}, {
key: 'collides',
value: function collides(target) {
var _this = this;
if (Array.isArray(target)) {
return target.find(function (t) {
return _this.collides(t);
});
}
var targetX = Math.round(target.x);
var targetY = Math.round(target.y);
var x = Math.round(this.x);
var y = Math.round(this.y);
return x === targetX && y == targetY;
}
}, {
key: 'health',
set: function set(value) {
this._health = Math.max(0, value);
if (this.health === 0) {
this.dead = true;
}
},
get: function get() {
return this._health;
}
}, {
key: 'x',
set: function set(value) {
this._x = value;
if (this.dieOnExit && this._x > this.output.columns) {
this.dead = true;
}
},
get: function get() {
return this._x;
}
}, {
key: 'y',
set: function set(value) {
this._y = value;
if (this.dieOnExit && this._y > this.output.rows) {
this.dead = true;
}
},
get: function get() {
return this._y;
}
}]);
return Unit;
})();
exports.default = Unit;

174
build/log
View File

@ -1,174 +0,0 @@
0 (0) = 0,1
45 (0.7853981633974483) = 0.7071067811865475,0.7071067811865476
45 (0.7853981633974483) = 0.7071067811865475,0.7071067811865476
90 (1.5707963267948966) = 1,6.123233995736766e-17
135 (2.356194490192345) = 0.7071067811865476,-0.7071067811865475
180 (3.141592653589793) = 1.2246467991473532e-16,-1
0 (0) = 1,0
45 (0.7853981633974483) = 0.7071067811865476,0.7071067811865475
90 (1.5707963267948966) = 6.123233995736766e-17,1
135 (2.356194490192345) = -0.7071067811865475,0.7071067811865476
180 (3.141592653589793) = -1,1.2246467991473532e-16
0 (0) = -1,0
45 (0.7853981633974483) = -0.7071067811865476,-0.7071067811865475
90 (1.5707963267948966) = -6.123233995736766e-17,-1
0 (0) = 1,0
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
90 (1.5707963267948966) = 6.123233995736766e-17,-1
135 (2.356194490192345) = -0.7071067811865475,-0.7071067811865476
180 (3.141592653589793) = -1,-1.2246467991473532e-16
0 (0) = 1,0
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
90 (1.5707963267948966) = 6.123233995736766e-17,-1
135 (2.356194490192345) = -0.7071067811865475,-0.7071067811865476
180 (3.141592653589793) = -1,-1.2246467991473532e-16
112.5 (1.9634954084936207) = -0.3826834323650897,-0.9238795325112867
112.5 (1.9634954084936207) = -0.3826834323650897,-0.9238795325112867
112.5 (1.9634954084936207) = -0.3826834323650897,-0.9238795325112867
90 (1.5707963267948966) = 6.123233995736766e-17,-1
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
22.5 (0.39269908169872414) = 0.9238795325112867,-0.3826834323650898
22.5 (0.39269908169872414) = 0.9238795325112867,-0.3826834323650898
45 (0.7853981633974483) = 0.7071067811865476,-0.7071067811865475
0 (0) = 1,0
22.5 (0.39269908169872414) = 0.9238795325112867,-0.3826834323650898
53.999999999999964 (0.9424777960769373) = 0.5877852522924737,-0.809016994374947
0 (0) = 1,0
54.999999999999964 (0.9599310885968807) = 0.5735764363510466,-0.8191520442889915
180 (3.141592653589793) = -1,-1.2246467991473532e-16
32.99999999999997 (0.5759586531581282) = 0.8386705679454243,-0.5446390350150266
170.00000000000003 (2.967059728390361) = -0.9848077530122081,-0.17364817766692983
42.99999999999997 (0.7504915783575612) = 0.7313537016191709,-0.6819983600624981
170.00000000000003 (2.967059728390361) = -0.9848077530122081,-0.17364817766692983
42.99999999999997 (0.7504915783575612) = 0.7313537016191709,-0.6819983600624981
170.00000000000003 (2.967059728390361) = -0.9848077530122081,-0.17364817766692983
45.99999999999997 (0.802851455917391) = 0.6946583704589977,-0.7193398003386507
170.00000000000003 (2.967059728390361) = -0.9848077530122081,-0.17364817766692983
35 (0.6108652381980153) = 0.8191520442889918,-0.573576436351046
49.99999999999997 (0.8726646259971643) = 0.6427876096865397,-0.7660444431189777
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
48.99999999999997 (0.8552113334772209) = 0.6560590289905077,-0.7547095802227716
167.00000000000009 (2.914699850830532) = -0.9743700647852356,-0.22495105434386348
46.999999999999964 (0.8203047484373343) = 0.6819983600624989,-0.73135370161917
48.99999999999997 (0.8552113334772209) = 0.6560590289905077,-0.7547095802227716
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
45.999999999999986 (0.8028514559173914) = 0.6946583704589975,-0.7193398003386511
162.00000000000009 (2.827433388230815) = -0.951056516295154,-0.3090169943749463
20.999999999999986 (0.366519142918809) = 0.9335804264972019,-0.35836794954530005
46.999999999999986 (0.8203047484373346) = 0.6819983600624987,-0.7313537016191702
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
26.999999999999993 (0.47123889803846886) = 0.8910065241883679,-0.4539904997395467
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
147 (2.5656340004316647) = -0.8386705679454242,-0.5446390350150269
10.99999999999999 (0.19198621771937607) = 0.981627183447664,-0.19080899537654464
48.99999999999998 (0.8552113334772211) = 0.6560590289905076,-0.7547095802227717
10 (0.17453292519943295) = 0.984807753012208,-0.17364817766693033
0 (0) = 1,0
10 (0.17453292519943295) = 0.984807753012208,-0.17364817766693033
0 (0) = 1,0
10 (0.17453292519943295) = 0.984807753012208,-0.17364817766693033
0 (0) = 1,0
10 (0.17453292519943295) = 0.984807753012208,-0.17364817766693033
0 (0) = 1,0
10 (0.17453292519943295) = 0.984807753012208,-0.17364817766693033
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
49.99999999999997 (0.8726646259971643) = 0.6427876096865397,-0.7660444431189777
19.999999999999986 (0.3490658503988657) = 0.9396926207859084,-0.3420201433256685
0 (0) = 1,0
19.999999999999986 (0.3490658503988657) = 0.9396926207859084,-0.3420201433256685
0 (0) = 1,0
19.999999999999986 (0.3490658503988657) = 0.9396926207859084,-0.3420201433256685
0 (0) = 1,0
0 (0) = 1,0
0 (0) = 1,0
180 (3.141592653589793) = -1,-1.2246467991473532e-16
180 (3.141592653589793) = -1,-1.2246467991473532e-16
180 (3.141592653589793) = -1,-1.2246467991473532e-16
180 (3.141592653589793) = -1,-1.2246467991473532e-16
180 (3.141592653589793) = -1,-1.2246467991473532e-16
180 (3.141592653589793) = -1,-1.2246467991473532e-16
0 (0) = 1,0
0 (0) = 1,0
47.99999999999998 (0.8377580409572778) = 0.6691306063588585,-0.743144825477394
134.99999999999991 (2.3561944901923435) = -0.7071067811865466,-0.7071067811865486

View File

@ -1,184 +0,0 @@
'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 _unit = require('./classes/unit');
var _unit2 = _interopRequireDefault(_unit);
var _interface = require('./classes/interface');
var _interface2 = _interopRequireDefault(_interface);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var FRAME = 100;
var ui = new _interface2.default();
var snake = [];
var UP = 0;
var DOWN = 1;
var LEFT = 2;
var RIGHT = 3;
var head = createPart();
head.color = '#71da29';
head.dieOnExit = true;
createPart();
createPart();
var point = new _unit2.default(ui);
point.shape = '+';
point.color = '#f3ff6a';
point.random();
var score = 0;
var stop = false;
function loop() {
if (stop) return;
ui.clear();
point.draw();
snake.forEach(function (part, i) {
part.draw();
if (i > 0) part.findWay(i);
part.move();
});
if (head.collides(point)) {
point.random();
createPart();
score++;
FRAME -= 5;
}
if (head.collides(snake.slice(2))) {
gameover();
}
ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
ui.cursor.reset();
setTimeout(loop, FRAME);
}
loop();
ui.onKey('right', function () {
changeDirection(RIGHT);
});
ui.onKey('down', function () {
changeDirection(DOWN);
});
ui.onKey('up', function () {
changeDirection(UP);
});
ui.onKey('left', function () {
changeDirection(LEFT);
});
ui.onKey(function () {
if (!stop) return;
stop = false;
snake = [];
head = createPart();
head.color = '#71da29';
createPart();
createPart();
score = 0;
point.random();
loop();
});
function changeDirection(dir) {
if (head.direction === UP && dir === DOWN || head.direction === DOWN && dir === UP || head.direction === LEFT && dir === RIGHT || head.direction === RIGHT && dir === LEFT) return;
head.direction = dir;
}
function createPart() {
var part = new _unit2.default(ui);
var last = snake[snake.length - 1];
var direction = undefined;
if (!last) {
direction = UP;
} else {
direction = last.direction;
}
part.shape = '•';
part.color = '#bdfe91';
part.direction = direction;
part.changeTo = null;
part.findWay = function (i) {
var ahead = snake[i - 1];
if (this.changeTo !== null) {
this.direction = this.changeTo;
this.changeTo = null;
}
if (this.direction !== ahead.direction) {
this.changeTo = ahead.direction;
}
};
part.speed = function () {
var multiplier = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
var direction = part.direction;
var x = direction == LEFT ? -1 : direction == RIGHT ? 1 : 0;
var y = direction == UP ? -1 : direction == DOWN ? 1 : 0;
return [x * multiplier, y * multiplier];
};
var _part$speed = part.speed();
var _part$speed2 = _slicedToArray(_part$speed, 2);
var dX = _part$speed2[0];
var dY = _part$speed2[1];
dX *= -1;
dY *= -1;
var x = last ? last.x + dX : ui.center.x;
var y = last ? last.y + dY : ui.center.y;
part.go(x, y);
snake.push(part);
return part;
}
function gameover() {
var MSG = 'Game Over!';
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
ui.cursor.red();
ui.cursor.bold();
ui.write(MSG);
ui.cursor.reset();
ui.cursor.hex('#f65590');
var RETRY = 'Press any key to play again';
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
ui.write(RETRY);
FRAME = 100;
stop = true;
}
process.on('exit', function () {
ui.cursor.horizontalAbsolute(0).eraseLine();
ui.cursor.show();
});

View File

@ -1,124 +0,0 @@
'use strict';
var _unit = require('./classes/unit');
var _unit2 = _interopRequireDefault(_unit);
var _interface = require('./classes/interface');
var _interface2 = _interopRequireDefault(_interface);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var FRAME = 20;
var ENEMY_SPAWN_RATE = 1000;
var RELOAD_TIME = 200;
var ui = new _interface2.default();
var player = new _unit2.default(ui);
player.go(1, ui.center.y);
player.shape = '=>';
player.color = '#77d6ff';
player.bold = true;
player.canShoot = true;
var explosion = new _unit2.default(ui);
explosion.dead = true;
var missles = [];
var enemies = [];
var score = 0;
setInterval(function () {
ui.clear();
player.draw();
missles.forEach(function (missle, i) {
missle.move(1, 0);
missle.draw();
var enemy = missle.collides(enemies);
if (enemy) {
enemy.killed = 1;
enemy.color = 'red';
enemy.shape = '*';
missle.dead = true;
ENEMY_SPAWN_RATE -= 5;
score++;
}
if (missle.dead) {
missles.splice(i, 1);
}
});
enemies.forEach(function (enemy, i) {
// move with speed
enemy.move();
enemy.draw();
if (enemy.dead) {
enemies.splice(i, 1);
}
if (enemy.killed == 3) enemy.dead = true;
if (enemy.killed < 3) enemy.killed++;
});
ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
ui.cursor.reset();
}, FRAME);
ui.onKey('right', function () {
player.move(1, 0);
});
ui.onKey('down', function () {
player.move(0, 1);
});
ui.onKey('up', function () {
player.move(0, -1);
});
ui.onKey('left', function () {
player.move(-1, 0);
});
ui.onKey('space', function () {
if (!player.canShoot) return;
player.canShoot = false;
var missle = new _unit2.default(ui);
missle.go(player.x, player.y);
missle.shape = '+';
missle.dieOnExit = true;
missles.push(missle);
setTimeout(function () {
player.canShoot = true;
}, RELOAD_TIME);
});
(function loop() {
var enemy = new _unit2.default(ui);
enemy.go(Math.random() * ui.output.columns, 0);
enemy.shape = 'o';
enemy.color = '#f7c71e';
enemy.dieOnExit = true;
enemy.speed = function () {
return [Math.random() > 0.9 ? 0.4 : 0, 0.06];
};
enemies.push(enemy);
setTimeout(loop, ENEMY_SPAWN_RATE);
})();
process.on('exit', function () {
ui.cursor.horizontalAbsolute(0).eraseLine();
ui.cursor.show();
});

View File

@ -1,156 +0,0 @@
'use strict';
var _unit = require('./classes/unit');
var _unit2 = _interopRequireDefault(_unit);
var _tank = require('./classes/tank');
var _tank2 = _interopRequireDefault(_tank);
var _interface = require('./classes/interface');
var _interface2 = _interopRequireDefault(_interface);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var FRAME = 50;
var ui = new _interface2.default();
var immoblize = false;
var one = new _tank2.default(ui);
one.go(10, ui.rows);
var two = new _tank2.default(ui);
two.go(ui.columns - 10, ui.rows);
var stop = false;
function loop() {
if (stop) return;
ui.clear();
if (one.dead || two.dead) {
var num = one.dead ? '2' : '1';
var msg = 'Player ' + num + ' won!';
ui.cursor.red();
ui.cursor.bold();
ui.cursor.goto(ui.center.x - msg.length / 2, ui.center.y);
ui.write(msg);
stop = true;
return;
}
one.draw();
one.bullets.forEach(function (bullet, i) {
if (bullet.dead) {
immoblize = false;
one.bullets.splice(i, 1);
return;
}
bullet.move();
bullet.draw();
if (bullet.collides(two)) {
two.health -= 10;
bullet.dead = true;
}
});
ui.cursor.goto(0, 1);
if (turn() === one) ui.cursor.hex('#54ffff');
ui.write('Player 1');
ui.cursor.reset();
ui.cursor.goto(0, 2);
ui.write('Health: ' + one.health);
ui.cursor.goto(0, 3);
ui.write('Angle: ' + parseInt(one.angle));
two.draw();
two.bullets.forEach(function (bullet, i) {
if (bullet.dead) {
immoblize = false;
two.bullets.splice(i, 1);
return;
}
bullet.move();
bullet.draw();
if (bullet.collides(one)) {
one.health -= 10;
bullet.dead = true;
}
});
ui.cursor.goto(ui.output.columns - 10, 1);
if (turn() === two) ui.cursor.hex('#54ffff');
ui.write('Player 2');
ui.cursor.reset();
ui.cursor.goto(ui.output.columns - 10, 2);
ui.write('Health: ' + two.health);
ui.cursor.goto(ui.output.columns - 10, 3);
ui.write('Angle: ' + parseInt(two.angle));
setTimeout(loop, FRAME);
}
loop();
ui.onKey('down', function () {
if (immoblize) return;
turn().angle -= 1;
});
ui.onKey('up', function () {
if (immoblize) return;
turn().angle += 1;
});
ui.onKey('left', function () {
if (immoblize) return;
turn().x -= 1;
});
ui.onKey('right', function () {
if (immoblize) return;
turn().x += 1;
});
ui.onKey('space', function () {
if (immoblize) return;
turn().shoot();
immoblize = true;
TURN = !TURN;
});
ui.onKey(function () {
if (one.dead || two.dead) {
one.go(10, ui.rows);
two.go(ui.columns - 10, ui.rows);
one.health = 100;
two.health = 100;
one.dead = false;
two.dead = false;
stop = false;
loop();
}
});
var TURN = true;
function turn() {
if (TURN) return one;
return two;
}

View File

@ -1,6 +1,7 @@
#!/usr/bin/env node
var game = process.argv[2];
var language = process.argv[3];
if (!game) {
console.log('usage: node-games <game>');
@ -14,4 +15,6 @@ if (!game) {
require('babel-polyfill');
require(__dirname + '/build/' + game);
const gameToPlay = require(__dirname + '/build/' + game).default;
gameToPlay(language);

View File

@ -4,6 +4,7 @@
"description": "Simple node console games",
"main": "index.js",
"scripts": {
"build": "grunt && grunt copy",
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": "index.js",
@ -23,13 +24,16 @@
"homepage": "https://github.com/mdibaiee/node-games#readme",
"dependencies": {
"ansi": "0.3.0",
"babel-core": "6.3.17",
"babel-core": "^6.26.3",
"babel-polyfill": "6.3.14",
"babel-preset-es2015": "6.3.13"
"babel-preset-es2015": "6.3.13",
"node-polyglot": "^2.3.0"
},
"devDependencies": {
"grunt": "0.4.5",
"grunt-babel": "6.0.0",
"grunt-cli": "^1.3.2",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "0.6.1"
}
}

17
src/locales/en.json Normal file
View File

@ -0,0 +1,17 @@
{
"snake": {
"score": "Score",
"gameOver": "Game Over!",
"anyKey": "Press any key to play again"
},
"tanks": {
"playerWon": "Player %{num} won!",
"player": "Player %{number}",
"health": "Health %{value}",
"angle": "Angle %{value}"
},
"spacecraft": {
"score": "Score"
}
}

16
src/locales/es.json Normal file
View File

@ -0,0 +1,16 @@
{
"snake": {
"score": "Puntaje",
"gameOver": "¡Se acabó el juego!",
"anyKey": "Presioná cualquier tecla para jugar nuevamente"
},
"tanks": {
"playerWon": "¡Ha ganado el jugador %{name}!",
"player": "Jugador %{number}",
"health": "Salud %{value}",
"angle": "Ángulo %{value}"
},
"spacecraft": {
"score": "Puntaje"
}
}

View File

@ -1,5 +1,6 @@
import Unit from './classes/unit';
import Interface from './classes/interface';
import Polyglot from "node-polyglot";
let FRAME = 100;
let ui = new Interface();
@ -23,7 +24,7 @@ point.random();
let score = 0;
let stop = false;
function loop() {
function loop(polyglot) {
if (stop) return;
ui.clear();
@ -46,17 +47,15 @@ function loop() {
}
if (head.collides(snake.slice(2))) {
gameover();
gameover(i18n);
}
ui.cursor.goto(0, 0).yellow().write(`Score: ${score}`);
ui.cursor.goto(0, 0).yellow().write(`${i18n.t('snake.score')}: ${score}`);
ui.cursor.reset();
setTimeout(loop, FRAME);
setTimeout(loop, FRAME, i18n);
}
loop();
ui.onKey('right', () => {
changeDirection(RIGHT);
});
@ -146,8 +145,8 @@ function createPart() {
return part;
}
function gameover() {
const MSG = 'Game Over!';
function gameover(i18n) {
const MSG = i18n.t('snake.gameOver');
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
ui.cursor.red();
ui.cursor.bold();
@ -155,7 +154,7 @@ function gameover() {
ui.cursor.reset();
ui.cursor.hex('#f65590');
const RETRY = 'Press any key to play again';
const RETRY = i18n.t('snake.anyKey');
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
ui.write(RETRY);
@ -165,6 +164,14 @@ function gameover() {
}
process.on('exit', function() {
ui.cursor.horizontalAbsolute(0).eraseLine()
ui.cursor.horizontalAbsolute(0).eraseLine();
ui.cursor.show();
});
export default function(language) {
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
const i18n = new Polyglot({phrases: locale});
loop(i18n);
}

View File

@ -1,5 +1,6 @@
import Unit from './classes/unit';
import Interface from './classes/interface';
import Polyglot from "node-polyglot";
const FRAME = 20;
let ENEMY_SPAWN_RATE = 1000;
@ -20,49 +21,55 @@ explosion.dead = true;
let missles = [];
let enemies = [];
let score = 0;
setInterval(() => {
ui.clear();
player.draw();
export default function(language) {
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
missles.forEach((missle, i) => {
missle.move(1, 0);
missle.draw();
const i18n = new Polyglot({phrases: locale});
let enemy = missle.collides(enemies)
if (enemy) {
enemy.killed = 1;
enemy.color = 'red';
enemy.shape = '*';
missle.dead = true;
setInterval((i18n) => {
ui.clear();
ENEMY_SPAWN_RATE -= 5;
player.draw();
score++;
}
missles.forEach((missle, i) => {
missle.move(1, 0);
missle.draw();
if (missle.dead) {
missles.splice(i, 1);
}
});
let enemy = missle.collides(enemies);
if (enemy) {
enemy.killed = 1;
enemy.color = 'red';
enemy.shape = '*';
missle.dead = true;
enemies.forEach((enemy, i) => {
// move with speed
enemy.move();
enemy.draw();
ENEMY_SPAWN_RATE -= 5;
if (enemy.dead) {
enemies.splice(i, 1);
}
score++;
}
if (enemy.killed == 3) enemy.dead = true;
if (enemy.killed < 3) enemy.killed++;
})
if (missle.dead) {
missles.splice(i, 1);
}
});
ui.cursor.goto(0, 0).yellow().write(`Score: ${score}`);
ui.cursor.reset();
}, FRAME);
enemies.forEach((enemy, i) => {
// move with speed
enemy.move();
enemy.draw();
if (enemy.dead) {
enemies.splice(i, 1);
}
if (enemy.killed == 3) enemy.dead = true;
if (enemy.killed < 3) enemy.killed++;
})
ui.cursor.goto(0, 0).yellow().write(`${i18n.t('spacecraft.score')}: ${score}`);
ui.cursor.reset();
}, FRAME, i18n);
}
ui.onKey('right', () => {
player.move(1, 0);

View File

@ -1,6 +1,7 @@
import Unit from './classes/unit';
import Tank from './classes/tank';
import Interface from './classes/interface';
import Polyglot from "node-polyglot";
let FRAME = 50;
let ui = new Interface();
@ -14,14 +15,14 @@ two.go(ui.columns - 10, ui.rows);
let stop = false;
function loop() {
function loop(i18n) {
if (stop) return;
ui.clear();
if (one.dead || two.dead) {
let num = one.dead ? '2' : '1';
const msg = `Player ${num} won!`;
const msg = i18n.t('tanks.playerWon', {num: num});
ui.cursor.red();
ui.cursor.bold();
@ -50,12 +51,12 @@ function loop() {
ui.cursor.goto(0, 1);
if (turn() === one) ui.cursor.hex('#54ffff');
ui.write('Player 1');
ui.write(i18n.t('tanks.player', {number: "1"}));
ui.cursor.reset();
ui.cursor.goto(0, 2);
ui.write('Health: ' + one.health);
ui.write(i18n.t('tanks.health', {value: one.health}));
ui.cursor.goto(0, 3);
ui.write('Angle: ' + parseInt(one.angle));
ui.write(i18n.t('tanks.angle', {value: parseInt(one.angle)}));
two.draw();
two.bullets.forEach((bullet, i) => {
@ -75,18 +76,16 @@ function loop() {
ui.cursor.goto(ui.output.columns - 10, 1);
if (turn() === two) ui.cursor.hex('#54ffff');
ui.write('Player 2');
ui.write(i18n.t('tanks.player', {number: "2"}));
ui.cursor.reset();
ui.cursor.goto(ui.output.columns - 10, 2);
ui.write('Health: ' + two.health);
ui.write(i18n.t('tanks.health', {value: two.health}));
ui.cursor.goto(ui.output.columns - 10, 3);
ui.write('Angle: ' + parseInt(two.angle));
ui.write(i18n.t('tanks.angle', {value: parseInt(two.angle)}));
setTimeout(loop, FRAME);
setTimeout(loop, FRAME, i18n);
}
loop();
ui.onKey('down', () => {
if (immoblize) return;
@ -142,3 +141,11 @@ function turn() {
if (TURN) return one;
return two;
}
export default function(language) {
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
const i18n = new Polyglot({phrases: locale});
loop(i18n);
}