Add Spanish translations #7
@ -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']);
|
||||
};
|
||||
|
34
README.es.md
Normal file
34
README.es.md
Normal file
@ -0,0 +1,34 @@
|
||||
node-games
|
||||
==========
|
||||
|
||||
[English Version](README.md)
|
||||
|
||||
Algunos juegos de consola escritos en Node.
|
||||
|
||||
```
|
||||
npm i -g node-games
|
||||
|
||||
node-games
|
||||
```
|
||||
|
||||
Sin instalar el juego globalmente:
|
||||
```
|
||||
npm start <juego> <idioma>
|
||||
|
||||
Ejemplo:
|
||||
npm start snake es
|
||||
|
||||
(Si no se especifica el lenguage, por defecto se usa inglés)
|
||||
```
|
||||
|
||||
spacecraft
|
||||
----------
|
||||
![spacecraft](spacecraft-es.gif)
|
||||
|
||||
snake
|
||||
-----
|
||||
![snake](snake-es.gif)
|
||||
|
||||
tanks
|
||||
-----
|
||||
![tanks](tanks-es.gif)
|
10
README.md
10
README.md
@ -1,6 +1,8 @@
|
||||
node-games
|
||||
==========
|
||||
|
||||
[Version en español](README.es.md)
|
||||
|
||||
Some fun console games written using Node.
|
||||
|
||||
```
|
||||
@ -9,6 +11,14 @@ npm i -g node-games
|
||||
node-games
|
||||
```
|
||||
|
||||
Without installing node-games globally:
|
||||
```
|
||||
npm start <game> <language>
|
||||
npm start snake es
|
||||
|
||||
(English will be default language if none is given)
|
||||
```
|
||||
|
||||
spacecraft
|
||||
----------
|
||||
![spacecraft](https://raw.githubusercontent.com/mdibaiee/node-games/master/spacecraft.gif)
|
||||
|
@ -1,11 +1,11 @@
|
||||
'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 _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 _ansi2 = _interopRequireDefault(_ansi);
|
||||
@ -14,28 +14,29 @@ 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"); } }
|
||||
|
||||
var _process = process;
|
||||
var stdout = _process.stdout;
|
||||
var stdin = _process.stdin;
|
||||
var _process = process,
|
||||
stdout = _process.stdout,
|
||||
stdin = _process.stdin;
|
||||
|
||||
|
||||
var listeners = [];
|
||||
|
||||
var prefix = '\u001b';
|
||||
var prefix = '\x1B';
|
||||
var keys = {
|
||||
right: prefix + '[C',
|
||||
up: prefix + '[A',
|
||||
left: prefix + '[D',
|
||||
down: prefix + '[B',
|
||||
exit: '\u0003',
|
||||
exit: '\x03',
|
||||
space: ' '
|
||||
};
|
||||
|
||||
var Interface = (function () {
|
||||
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];
|
||||
var output = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : stdout;
|
||||
var input = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : stdin;
|
||||
|
||||
_classCallCheck(this, Interface);
|
||||
|
||||
@ -61,7 +62,7 @@ var Interface = (function () {
|
||||
});
|
||||
|
||||
if (key === 'exit') {
|
||||
_this.output.write('\u001b[2J\u001b[0;0H');
|
||||
_this.output.write('\x1B[2J\x1B[0;0H');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ var Interface = (function () {
|
||||
_createClass(Interface, [{
|
||||
key: 'clear',
|
||||
value: function clear() {
|
||||
this.output.write('\u001b[2J\u001b[0;0H');
|
||||
this.output.write('\x1B[2J\x1B[0;0H');
|
||||
}
|
||||
}, {
|
||||
key: 'write',
|
||||
@ -110,6 +111,7 @@ var Interface = (function () {
|
||||
|
||||
var y = from.y;
|
||||
|
||||
|
||||
for (var x = from.x; x < to.x; x++) {
|
||||
this.cursor.goto(x, y);
|
||||
this.write('.');
|
||||
@ -145,6 +147,6 @@ var Interface = (function () {
|
||||
}]);
|
||||
|
||||
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,12 +1,12 @@
|
||||
'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 _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 _unit2 = _interopRequireDefault(_unit);
|
||||
@ -21,13 +21,13 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||
|
||||
var BULLET_SPEED = 10;
|
||||
|
||||
var Tank = (function (_Unit) {
|
||||
var Tank = function (_Unit) {
|
||||
_inherits(Tank, _Unit);
|
||||
|
||||
function Tank(ui) {
|
||||
_classCallCheck(this, Tank);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Tank).call(this, ui));
|
||||
var _this = _possibleConstructorReturn(this, (Tank.__proto__ || Object.getPrototypeOf(Tank)).call(this, ui));
|
||||
|
||||
_this._angle = 0;
|
||||
_this.bullets = [];
|
||||
@ -51,8 +51,8 @@ var Tank = (function (_Unit) {
|
||||
value: function draw() {
|
||||
if (this.dead) return;
|
||||
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
var x = this.x,
|
||||
y = this.y;
|
||||
|
||||
if (this.color && this.color[0] === '#') {
|
||||
this.output.cursor.hex(this.color);
|
||||
@ -64,7 +64,7 @@ var Tank = (function (_Unit) {
|
||||
x = Math.round(x) + 2;
|
||||
y = Math.round(y) - 2;
|
||||
|
||||
var cannon = undefined;
|
||||
var cannon = void 0;
|
||||
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);
|
||||
@ -104,17 +104,17 @@ var Tank = (function (_Unit) {
|
||||
}]);
|
||||
|
||||
return Tank;
|
||||
})(_unit2.default);
|
||||
}(_unit2.default);
|
||||
|
||||
exports.default = Tank;
|
||||
|
||||
var Bullet = exports.Bullet = (function (_Unit2) {
|
||||
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));
|
||||
var _this2 = _possibleConstructorReturn(this, (Bullet.__proto__ || Object.getPrototypeOf(Bullet)).call(this, ui));
|
||||
|
||||
_this2.velocity = [0, 0];
|
||||
|
||||
@ -151,7 +151,7 @@ var Bullet = exports.Bullet = (function (_Unit2) {
|
||||
}]);
|
||||
|
||||
return Bullet;
|
||||
})(_unit2.default);
|
||||
}(_unit2.default);
|
||||
|
||||
function _radian(deg) {
|
||||
return deg * Math.PI / 180;
|
||||
|
@ -1,16 +1,16 @@
|
||||
'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 _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 _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) {
|
||||
_classCallCheck(this, Unit);
|
||||
|
||||
@ -33,9 +33,9 @@ var Unit = (function () {
|
||||
value: function draw() {
|
||||
if (this.dead) return;
|
||||
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
var shape = this.shape;
|
||||
var x = this.x,
|
||||
y = this.y,
|
||||
shape = this.shape;
|
||||
|
||||
if (this.color && this.color[0] === '#') {
|
||||
this.output.cursor.hex(this.color);
|
||||
@ -123,6 +123,6 @@ var Unit = (function () {
|
||||
}]);
|
||||
|
||||
return Unit;
|
||||
})();
|
||||
}();
|
||||
|
||||
exports.default = Unit;
|
||||
|
17
build/locales/en.json
Normal file
17
build/locales/en.json
Normal 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
build/locales/es.json
Normal file
16
build/locales/es.json
Normal 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"
|
||||
}
|
||||
}
|
174
build/log
174
build/log
@ -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
|
@ -1,6 +1,31 @@
|
||||
'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"); } }; })();
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
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"); } }; }();
|
||||
|
||||
exports.default = function (i18n) {
|
||||
loop(i18n);
|
||||
|
||||
ui.onKey(function () {
|
||||
if (!stop) return;
|
||||
|
||||
stop = false;
|
||||
snake = [];
|
||||
head = createPart();
|
||||
head.color = '#71da29';
|
||||
createPart();
|
||||
createPart();
|
||||
|
||||
score = 0;
|
||||
|
||||
point.random();
|
||||
|
||||
loop(i18n);
|
||||
});
|
||||
};
|
||||
|
||||
var _unit = require('./classes/unit');
|
||||
|
||||
@ -34,7 +59,7 @@ point.random();
|
||||
var score = 0;
|
||||
|
||||
var stop = false;
|
||||
function loop() {
|
||||
function loop(i18n) {
|
||||
if (stop) return;
|
||||
ui.clear();
|
||||
|
||||
@ -57,17 +82,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', function () {
|
||||
changeDirection(RIGHT);
|
||||
});
|
||||
@ -81,23 +104,6 @@ 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;
|
||||
@ -107,7 +113,7 @@ function createPart() {
|
||||
var part = new _unit2.default(ui);
|
||||
var last = snake[snake.length - 1];
|
||||
|
||||
var direction = undefined;
|
||||
var direction = void 0;
|
||||
if (!last) {
|
||||
direction = UP;
|
||||
} else {
|
||||
@ -132,21 +138,19 @@ function createPart() {
|
||||
};
|
||||
|
||||
part.speed = function () {
|
||||
var multiplier = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
|
||||
var multiplier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
||||
var direction = part.direction;
|
||||
|
||||
var x = direction == LEFT ? -1 : direction == RIGHT ? 1 : 0;
|
||||
var y = direction == UP ? -1 : direction == DOWN ? 1 : 0;
|
||||
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];
|
||||
var _part$speed = part.speed(),
|
||||
_part$speed2 = _slicedToArray(_part$speed, 2),
|
||||
dX = _part$speed2[0],
|
||||
dY = _part$speed2[1];
|
||||
|
||||
dX *= -1;
|
||||
dY *= -1;
|
||||
@ -160,8 +164,8 @@ function createPart() {
|
||||
return part;
|
||||
}
|
||||
|
||||
function gameover() {
|
||||
var MSG = 'Game Over!';
|
||||
function gameover(i18n) {
|
||||
var MSG = i18n.t('snake.gameOver');
|
||||
ui.cursor.goto(ui.center.x - MSG.length / 2, ui.center.y);
|
||||
ui.cursor.red();
|
||||
ui.cursor.bold();
|
||||
@ -169,7 +173,7 @@ function gameover() {
|
||||
|
||||
ui.cursor.reset();
|
||||
ui.cursor.hex('#f65590');
|
||||
var RETRY = 'Press any key to play again';
|
||||
var RETRY = i18n.t('snake.anyKey');
|
||||
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
||||
ui.write(RETRY);
|
||||
|
||||
|
@ -1,35 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var _unit = require('./classes/unit');
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
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 () {
|
||||
exports.default = function (i18n) {
|
||||
setInterval(function (i18n) {
|
||||
ui.clear();
|
||||
|
||||
player.draw();
|
||||
@ -64,13 +40,44 @@ setInterval(function () {
|
||||
enemies.splice(i, 1);
|
||||
}
|
||||
|
||||
if (enemy.killed == 3) enemy.dead = true;
|
||||
if (enemy.killed === 3) enemy.dead = true;
|
||||
if (enemy.killed < 3) enemy.killed++;
|
||||
});
|
||||
|
||||
ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
|
||||
ui.cursor.goto(0, 0).yellow().write(i18n.t('spacecraft.score') + ': ' + score);
|
||||
ui.cursor.reset();
|
||||
}, FRAME);
|
||||
}, FRAME, i18n);
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
ui.onKey('right', function () {
|
||||
player.move(1, 0);
|
||||
|
@ -1,8 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var _unit = require('./classes/unit');
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _unit2 = _interopRequireDefault(_unit);
|
||||
exports.default = function (i18n) {
|
||||
loop(i18n);
|
||||
};
|
||||
|
||||
var _tank = require('./classes/tank');
|
||||
|
||||
@ -26,14 +30,14 @@ two.go(ui.columns - 10, ui.rows);
|
||||
|
||||
var stop = false;
|
||||
|
||||
function loop() {
|
||||
function loop(i18n) {
|
||||
if (stop) return;
|
||||
|
||||
ui.clear();
|
||||
|
||||
if (one.dead || two.dead) {
|
||||
var num = one.dead ? '2' : '1';
|
||||
var msg = 'Player ' + num + ' won!';
|
||||
var msg = i18n.t('tanks.playerWon', { num: num });
|
||||
ui.cursor.red();
|
||||
ui.cursor.bold();
|
||||
|
||||
@ -62,12 +66,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(function (bullet, i) {
|
||||
@ -87,18 +91,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', function () {
|
||||
if (immoblize) return;
|
||||
|
||||
|
10
index.js
10
index.js
@ -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,11 @@ if (!game) {
|
||||
|
||||
require('babel-polyfill');
|
||||
|
||||
require(__dirname + '/build/' + game);
|
||||
const gameToPlay = require(__dirname + '/build/' + game).default;
|
||||
|
||||
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
|
||||
const Polyglot = require('node-polyglot');
|
||||
const i18n = new Polyglot({phrases: locale});
|
||||
|
||||
gameToPlay(i18n);
|
||||
|
||||
|
17
locales/en.json
Normal file
17
locales/en.json
Normal 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
locales/es.json
Normal file
16
locales/es.json
Normal 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"
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
"description": "Simple node console games",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "grunt && grunt copy",
|
||||
"start": "node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"bin": "index.js",
|
||||
@ -23,13 +25,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"
|
||||
}
|
||||
}
|
||||
|
BIN
snake-es.gif
Normal file
BIN
snake-es.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
BIN
spacecraft-es.gif
Normal file
BIN
spacecraft-es.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
68
src/snake.js
68
src/snake.js
@ -23,7 +23,7 @@ point.random();
|
||||
let score = 0;
|
||||
|
||||
let stop = false;
|
||||
function loop() {
|
||||
function loop(i18n) {
|
||||
if (stop) return;
|
||||
ui.clear();
|
||||
|
||||
@ -46,17 +46,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);
|
||||
});
|
||||
@ -70,23 +68,6 @@ ui.onKey('left', () => {
|
||||
changeDirection(LEFT);
|
||||
});
|
||||
|
||||
ui.onKey(() => {
|
||||
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 ||
|
||||
@ -121,17 +102,17 @@ function createPart() {
|
||||
if (this.direction !== ahead.direction) {
|
||||
this.changeTo = ahead.direction;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
part.speed = function(multiplier = 1) {
|
||||
let { direction } = part;
|
||||
let x = direction == LEFT ? -1 :
|
||||
direction == RIGHT ? 1 : 0;
|
||||
let y = direction == UP ? -1 :
|
||||
direction == DOWN ? 1 : 0;
|
||||
let x = direction === LEFT ? -1 :
|
||||
direction === RIGHT ? 1 : 0;
|
||||
let y = direction === UP ? -1 :
|
||||
direction === DOWN ? 1 : 0;
|
||||
|
||||
return [x * multiplier, y * multiplier];
|
||||
}
|
||||
};
|
||||
|
||||
let [dX, dY] = part.speed();
|
||||
dX *= -1;
|
||||
@ -146,8 +127,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 +136,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 +146,27 @@ function gameover() {
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
ui.cursor.horizontalAbsolute(0).eraseLine()
|
||||
ui.cursor.horizontalAbsolute(0).eraseLine();
|
||||
ui.cursor.show();
|
||||
});
|
||||
|
||||
export default function(i18n) {
|
||||
loop(i18n);
|
||||
|
||||
ui.onKey(() => {
|
||||
if (!stop) return;
|
||||
|
||||
stop = false;
|
||||
snake = [];
|
||||
head = createPart();
|
||||
head.color = '#71da29';
|
||||
createPart();
|
||||
createPart();
|
||||
|
||||
score = 0;
|
||||
|
||||
point.random();
|
||||
|
||||
loop(i18n);
|
||||
});
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ explosion.dead = true;
|
||||
let missles = [];
|
||||
let enemies = [];
|
||||
let score = 0;
|
||||
setInterval(() => {
|
||||
|
||||
export default function(i18n) {
|
||||
setInterval((i18n) => {
|
||||
ui.clear();
|
||||
|
||||
player.draw();
|
||||
@ -29,7 +31,7 @@ setInterval(() => {
|
||||
missle.move(1, 0);
|
||||
missle.draw();
|
||||
|
||||
let enemy = missle.collides(enemies)
|
||||
let enemy = missle.collides(enemies);
|
||||
if (enemy) {
|
||||
enemy.killed = 1;
|
||||
enemy.color = 'red';
|
||||
@ -55,14 +57,14 @@ setInterval(() => {
|
||||
enemies.splice(i, 1);
|
||||
}
|
||||
|
||||
if (enemy.killed == 3) enemy.dead = true;
|
||||
if (enemy.killed === 3) enemy.dead = true;
|
||||
if (enemy.killed < 3) enemy.killed++;
|
||||
})
|
||||
});
|
||||
|
||||
ui.cursor.goto(0, 0).yellow().write(`Score: ${score}`);
|
||||
ui.cursor.goto(0, 0).yellow().write(`${i18n.t('spacecraft.score')}: ${score}`);
|
||||
ui.cursor.reset();
|
||||
}, FRAME);
|
||||
|
||||
}, FRAME, i18n);
|
||||
}
|
||||
|
||||
ui.onKey('right', () => {
|
||||
player.move(1, 0);
|
||||
@ -103,7 +105,7 @@ ui.onKey('space', () => {
|
||||
|
||||
enemy.speed = () => {
|
||||
return [Math.random() > 0.9 ? 0.4 : 0, 0.06];
|
||||
}
|
||||
};
|
||||
|
||||
enemies.push(enemy);
|
||||
|
||||
@ -111,6 +113,6 @@ ui.onKey('space', () => {
|
||||
}());
|
||||
|
||||
process.on('exit', function() {
|
||||
ui.cursor.horizontalAbsolute(0).eraseLine()
|
||||
ui.cursor.horizontalAbsolute(0).eraseLine();
|
||||
ui.cursor.show();
|
||||
});
|
||||
|
31
src/tanks.js
31
src/tanks.js
@ -1,4 +1,3 @@
|
||||
import Unit from './classes/unit';
|
||||
import Tank from './classes/tank';
|
||||
import Interface from './classes/interface';
|
||||
|
||||
@ -14,14 +13,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 +49,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,29 +74,27 @@ 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;
|
||||
|
||||
turn().angle -= 1;
|
||||
})
|
||||
});
|
||||
|
||||
ui.onKey('up', () => {
|
||||
if (immoblize) return;
|
||||
|
||||
turn().angle += 1;
|
||||
})
|
||||
});
|
||||
|
||||
ui.onKey('left', () => {
|
||||
if (immoblize) return;
|
||||
@ -135,10 +132,14 @@ ui.onKey(() => {
|
||||
|
||||
loop();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let TURN = true;
|
||||
function turn() {
|
||||
if (TURN) return one;
|
||||
return two;
|
||||
}
|
||||
|
||||
export default function(i18n) {
|
||||
loop(i18n);
|
||||
}
|
||||
|
BIN
tanks-es.gif
Normal file
BIN
tanks-es.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
Loading…
Reference in New Issue
Block a user