Use Polyglot to add spanish translations
This commit is contained in:
@ -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;
|
@ -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
|
@ -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;
|
||||
}
|
@ -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;
|
Reference in New Issue
Block a user