Skip to content

Commit

Permalink
Merge pull request #2 from CamilaSosa96/develop
Browse files Browse the repository at this point in the history
Language system with spanish translation
  • Loading branch information
CamilaSosa96 committed May 30, 2019
2 parents dd48a87 + 623468f commit 34af58d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
39 changes: 39 additions & 0 deletions build/classes/languageSystem.js
@@ -0,0 +1,39 @@
class LanguageSystem{
constructor(_language = undefined){
this.language = _language;
}

translate(text){
if(this.language === 'es'){
return this.spanishTranslator(text);
}
return text;
}

spanishTranslator(text){
if(text === 'Score: '){
return 'Puntaje: ';
}
if(text === 'Game Over!'){
return 'Fin del juego!';
}
if(text === 'Press any key to play again'){
return 'Presione cualquier tecla para jugar nuevamente';
}
if(text === 'Player '){
return 'Jugador ';
}
if(text === ' won!'){
return ' ganó!';
}
if(text === 'Health: '){
return 'Vida: ';
}
if(text === 'Angle: '){
return 'Ángulo: ';
}
return text;
}
}

module.exports = LanguageSystem;
6 changes: 3 additions & 3 deletions build/snake.js
Expand Up @@ -60,7 +60,7 @@ function loop() {
gameover();
}

ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
ui.cursor.goto(0, 0).yellow().write(translator.translate('Score: ') + score);
ui.cursor.reset();

setTimeout(loop, FRAME);
Expand Down Expand Up @@ -161,15 +161,15 @@ function createPart() {
}

function gameover() {
var MSG = 'Game Over!';
var MSG = translator.translate('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';
var RETRY = translator.translate('Press any key to play again');
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
ui.write(RETRY);

Expand Down
2 changes: 1 addition & 1 deletion build/spacecraft.js
Expand Up @@ -68,7 +68,7 @@ setInterval(function () {
if (enemy.killed < 3) enemy.killed++;
});

ui.cursor.goto(0, 0).yellow().write('Score: ' + score);
ui.cursor.goto(0, 0).yellow().write(translator.translate('Score: ') + score);
ui.cursor.reset();
}, FRAME);

Expand Down
14 changes: 7 additions & 7 deletions build/tanks.js
Expand Up @@ -33,7 +33,7 @@ function loop() {

if (one.dead || two.dead) {
var num = one.dead ? '2' : '1';
var msg = 'Player ' + num + ' won!';
var msg = translator.translate('Player ') + num + translator.translate(' won!');
ui.cursor.red();
ui.cursor.bold();

Expand Down Expand Up @@ -62,12 +62,12 @@ function loop() {

ui.cursor.goto(0, 1);
if (turn() === one) ui.cursor.hex('#54ffff');
ui.write('Player 1');
ui.write(translator.translate('Player ') + '1');
ui.cursor.reset();
ui.cursor.goto(0, 2);
ui.write('Health: ' + one.health);
ui.write(translator.translate('Health: ') + one.health);
ui.cursor.goto(0, 3);
ui.write('Angle: ' + parseInt(one.angle));
ui.write(translator.translate('Angle: ') + parseInt(one.angle));

two.draw();
two.bullets.forEach(function (bullet, i) {
Expand All @@ -87,12 +87,12 @@ function loop() {

ui.cursor.goto(ui.output.columns - 10, 1);
if (turn() === two) ui.cursor.hex('#54ffff');
ui.write('Player 2');
ui.write(translator.translate('Player ') + '2');
ui.cursor.reset();
ui.cursor.goto(ui.output.columns - 10, 2);
ui.write('Health: ' + two.health);
ui.write(translator.translate('Health: ') + two.health);
ui.cursor.goto(ui.output.columns - 10, 3);
ui.write('Angle: ' + parseInt(two.angle));
ui.write(translator.translate('Angle: ') + parseInt(two.angle));

setTimeout(loop, FRAME);
}
Expand Down
12 changes: 10 additions & 2 deletions index.js
@@ -1,17 +1,25 @@
#!/usr/bin/env node
const LanguageSystem = require('./build/classes/languageSystem')

var game = process.argv[2];
var language = process.argv[3];

if (!game) {
console.log('usage: node-games <game>');
console.log('usage: node-games <game> <language>');
console.log('');
console.log('Games');
console.log('- spacecraft');
console.log('- snake');
console.log('- tanks');
console.log('');
console.log('Languages');
console.log('- NO PARAM : English (Default)');
console.log('- es : Español');
return;
}

global.translator = new LanguageSystem(language);

require('babel-polyfill');

require(__dirname + '/build/' + game);
require(__dirname + '/build/' + game);

0 comments on commit 34af58d

Please sign in to comment.