Sauvegarde des infos des stats du robot en json - Recharger la page en changeant de langue garde les stats du robots - Réessayer un niveau à la fin de celui-ci garde notre arbre d'action et nos statistiques - Modification de HealthBar pour implémenter l'écriture dans la barre - Implémentation de l'écriture "Bouclier" et "Vie" dans leurs barres respectives - L'edition d'action est normalement fonctionnelle - Création des boutons modifier en anglais et en français

master
clmaisonha 5 years ago
parent 680ed6088d
commit 29a70f9c78

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,11 +1,11 @@
class AddAttack extends AddNode {
constructor(father, game, selected) {
super(father, game, selected);
constructor(father, game, selected, ...option) {
super(father, game, selected, option);
}
create() {
console.log("ATTACK");
super.create(this);
super.create();
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : ATTACK", "AJOUTER ACTION : ATTAQUE"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 7), selectWord("TARGET FILTERS (OPTIONAL)", "FILTRES CIBLES (FACULTATIF)"));
@ -19,9 +19,16 @@ class AddAttack extends AddNode {
addNode() {
if (super.verifyCategory()) {
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'attack', this.lCategory[1].getValue()));
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'attack', [this.lCategory[1].getValue()]));
super.cancel();
}
}
modifyNode() {
if (super.verifyCategory()) {
this.selected.node.percentRange = this.lCategory[1].getValue();
this.selected.rect.setFrame(this.selected.node.getFrame());
super.cancel();
}
}
}

@ -1,10 +1,10 @@
class AddCondition extends AddNode {
constructor(father, game, selected) {
super(father, game, selected);
constructor(father, game, selected, ...option) {
super(father, game, selected, option);
}
create() {
super.create(this);
super.create();
console.log("CONDITION");
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : CONDITION", "AJOUTER ACTION : CONDITION"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
@ -21,9 +21,17 @@ class AddCondition extends AddNode {
addNode() {
if (super.verifyCategory()) {
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0));
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', [this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0]));
super.cancel();
}
}
modifyNode() {
if (super.verifyCategory()) {
this.selected.node.myself = this.lCategory[0].getValue();
this.selected.node.shield = this.lCategory[1].getValue();
this.selected.rect.setFrame(this.selected.node.getFrame());
super.cancel();
}
}
}

@ -1,11 +1,11 @@
class AddMove extends AddNode {
constructor(father, game, selected) {
super(father, game, selected);
constructor(father, game, selected, ...option) {
super(father, game, selected, option);
}
create() {
console.log("MOVE");
super.create(this);
super.create();
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : MOVE", "AJOUTER ACTION : DEPLACEMENT"));
super.addTitle(WIDTH_WINDOW / 4, HEIGHT_WINDOW / (16 / 3), selectWord("FLEE OR MOVE ?", "RECULER OU AVANCER ?"));
let c1 = super.newCategory('direction', true, true);
@ -19,7 +19,16 @@ class AddMove extends AddNode {
addNode() {
if (super.verifyCategory()) {
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'move', this.lCategory[0].getValue(), this.lCategory[1].getValue()));
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'move', [this.lCategory[0].getValue(), this.lCategory[1].getValue()]));
super.cancel();
}
}
modifyNode() {
if (super.verifyCategory()) {
this.selected.node.toward = this.lCategory[0].getValue();
this.selected.node.enemyBot = this.lCategory[1].getValue();
this.selected.rect.setFrame(this.selected.node.getFrame());
super.cancel();
}
}

@ -1,9 +1,9 @@
class Bar extends HealthBar {
constructor(scene, name = "", width, height, x, y, color, categoryBar = new CategoryBar(), value = 1, valueMax) {
if (valueMax !== undefined) {
super(scene, width, height, x, y, valueMax, color, color, false);
super(scene, name, width, height, x, y, valueMax, color, color, false);
} else {
super(scene, width, height, x, y, categoryBar.valueMax, color, color, false);
super(scene, name, width, height, x, y, categoryBar.valueMax, color, color, false);
}
this.name = name;
this.scene = scene;
@ -11,9 +11,6 @@ class Bar extends HealthBar {
let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"};
this.text = this.scene.add.text(this.bar.x + this.width + 10, this.bar.y, this.value.toString(), style).setOrigin(0, 0);
style = {font: height.toString() + 'px stencil', fill: "#000000"};
let nameText = this.scene.add.text(x + 5, y, this.name, style).setOrigin(0, 0);
nameText.alpha = 0.5;
this.categoryBar = categoryBar;
this.setValue(0);
this.categoryBar.setValueOf(this, value);
@ -52,7 +49,7 @@ class Bar extends HealthBar {
this.bar.fillStyle(0x969696);
this.bar.fillRect(posX, 0, 10, this.height);
if (this.text !== undefined) {
this.text.setText(this.value);
this.text.setText(this.value + 1);
}
}
}

@ -1,12 +1,8 @@
class CategoryBar {
constructor(scene, text, posX, posY, height, valueMax = VALUE_MAX_BAR, startValue = 1) {
constructor(valueMax = VALUE_MAX_BAR, startValue = 1) {
this.startValue = startValue;
this.valueMax = valueMax;
this.point = this.valueMax;
this.text = text;
let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"};
this.textScene = scene.add.text(posX, posY, this.text, style).setOrigin(0, 0);
this.draw();
}
addPoint(point) {
@ -34,7 +30,24 @@ class CategoryBar {
this.draw();
}
draw(){
addText(scene, text, posX, posY, height) {
this.text = text;
let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"};
this.textScene = scene.add.text(posX, posY, this.text, style).setOrigin(0, 0);
this.draw();
}
setTextPos(posX, posY) {
this.textScene.setX(posX);
this.textScene.setY(posY);
}
setText(text) {
this.text = text;
this.draw();
}
draw() {
this.textScene.setText(this.text + this.point);
}
}

@ -7,11 +7,11 @@ function selectWord(en, fr) {
}
}
function newGame(father) {
function newGame(father, game = new Game(father)) {
if (father.scene.getIndex('Game') !== -1) {
father.scene.remove('Game');
}
father.scene.add('Game', new Game(father));
father.scene.add('Game', game);
}
function chooseTarget(robot, list) {
@ -34,4 +34,29 @@ function chooseTarget(robot, list) {
} else {
return l[0];
}
}
function toJson(name, value, end = false) {
let val;
switch (typeof value) {
case "string":
val = '"' + name.toString() + '":"' + value + '"';
break;
default:
//console.log(typeof value);
val = '"' + name.toString() + '":' + value;
break;
}
if (!end)
val += ','
return val;
}
function endLineJson(json) {
if (json.length > 0) {
if (json[json.length - 1] === ",") {
json = json.substr(0, json.length - 1);
}
}
return json;
}

@ -26,11 +26,6 @@ class Game extends ManageLang {
let width = 200;
let height = 30;
let c1 = new CategoryBar(this, selectWord("TOKEN : ", "JETON : "), OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 6, height, 10);
this.damageRobot = new Bar(this, selectWord("DAMAGE", "DEGAT"), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP, COLOR_ATTACK, c1, DAMAGE_BEGIN, 5);
this.speedReloadRobot = new Bar(this, selectWord("R.S", "V.R."), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 1.5, COLOR_SPEED_RELOAD, c1, SPEED_RELOAD_BEGIN, 5);
this.speedRobot = new Bar(this, selectWord("SPEED", "VITESSE"), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 3, COLOR_MOVE, c1, SPEED_BEGIN, 5);
this.rangeRobot = new Bar(this, selectWord("RANGE", "PORTEE"), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 4.5, COLOR_RANGE, c1, RANGE_BEGIN, 5);
this.createButton();
@ -38,21 +33,31 @@ class Game extends ManageLang {
let diffX = WIDTH_WINDOW / 10;
if (this.tree === undefined) {
this.initStat = new InitStat(this, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP, width, height, 10);
this.initStat.addBar(DAMAGE_BEGIN, 5, COLOR_ATTACK, ["DAMAGE", "DEGATS"]);
this.initStat.addBar(SPEED_RELOAD_BEGIN, 5, COLOR_SPEED_RELOAD, ["R.S", "RECHARGEMENT"]);
this.initStat.addBar(SPEED_BEGIN, 5, COLOR_MOVE, ["SPEED", "VITESSE"]);
this.initStat.addBar(RANGE_BEGIN, 5, COLOR_RANGE, ["RANGE", "PORTEE"]);
this.tree = new RectangleNode(centerX, HEIGHT_WINDOW / 10, this, 'waria');
this.tree.addRect(new RectangleNode(centerX - 2 * diffX, HEIGHT_WINDOW / 3, this, 'move', true, false));
this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', true));
this.tree.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 3, this, 'attack', 1 / 3));
this.tree.addRect(new RectangleNode(centerX - 2 * diffX, HEIGHT_WINDOW / 3, this, 'move', [true, false]));
this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', [true]));
this.tree.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 3, this, 'attack', [1 / 3]));
let condition = new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 3, this, 'condition', true, true, false, 1 / 3, 0);
let condition = new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 3, this, 'condition', [true, true, false, 1 / 3, 0]);
this.tree.addRect(condition);
condition.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 1.5, this, 'move', false));
condition.addRect(new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 1.5, this, 'attack'))
condition.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 1.5, this, 'move', [false]));
condition.addRect(new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 1.5, this, 'attack', [1]))
} else {
let save = this.tree.save();
save = JSON.parse(save);
this.loadSave(save);
let tree = this.tree.getJson();
tree = JSON.parse(tree);
let initStat = this.initStat.getJson();
initStat = JSON.parse(initStat);
this.loadSave(tree, initStat);
}
@ -73,8 +78,9 @@ class Game extends ManageLang {
}
loadSave(save) {
this.tree = this.loadTree(save);
loadSave(tree, initStat) {
this.initStat = this.loadInitSave(initStat);
this.tree = this.loadTree(tree);
}
loadTree(element) {
@ -85,13 +91,24 @@ class Game extends ManageLang {
return tree;
}
loadInitSave(element) {
let width = 200;
let height = 30;
let initStat = new InitStat(this, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP, width, height, 10);
for (let i = 0; i < element.lBar.length; i++) {
initStat.addBar(element.lBar[i].value, element.lBar[i].valueMax, element.lBar[i].color, element.lText[i]);
}
return initStat;
}
finish() {
console.log("FINISH");
let winner;
if (this.gm.winner()) {
winner = new Winner(this.father);
winner = new Winner(this.father, this);
} else {
winner = new Looser(this.father);
winner = new Looser(this.father, this);
}
this.father.scene.add('Finish', winner);
@ -150,7 +167,7 @@ class Game extends ManageLang {
let sortDesc = (a, b) => a.getX() - b.getX();
this.tree.sort(sortDesc);
this.gm.modifyNodes(this.tree.getNode());
this.gm.modifyValue(this.speedRobot.value, this.rangeRobot.value, this.speedReloadRobot.value, this.damageRobot.value);
this.gm.modifyValue(this.initStat.lBar[0].value, this.initStat.lBar[1].value, this.initStat.lBar[2].value, this.initStat.lBar[3].value);
this.gm.resume();
}
@ -253,9 +270,23 @@ class Game extends ManageLang {
clickPencil() {
console.log("PENCIL");
this.changeFrame(this.pencil, 0);
switch (this.selected.type) {
case 'attack':
this.father.scene.add('AddNode', new AddAttack(this.father, this, this.selected, false, this.selected.node.percentRange))
break;
case 'move':
this.father.scene.add('AddNode', new AddMove(this.father, this, this.selected, this.selected.node.toward, this.selected.node.enemyBot))
break;
case 'condition':
this.father.scene.add('AddNode', new AddCondition(this.father, this, this.selected, this.selected.node.myself, this.selected.node.shield))
break;
default:
return;
}
this.scene.pause('Game');
this.scene.launch('AddNode');
}
clickBin() {

@ -30,7 +30,6 @@ class GamingBoard extends Phaser.Scene {
update(time, delta) {
super.update(time, delta);
console.log(delta);
this.listRobot.forEach(function (robot) {
robot.read();
})
@ -85,7 +84,7 @@ class GamingBoard extends Phaser.Scene {
return false;
}
modifyValue(speed, range, speedReload, damage) {
modifyValue(damage, speedReload, speed, range) {
let myRobot = this.getMyRobot();
if (myRobot !== undefined) {
myRobot.setSpeed(speed);

@ -0,0 +1,40 @@
class InitStat {
constructor(scene, posX, posY, width, height, valueMax) {
this.scene = scene;
this.posX = posX;
this.posY = posY;
this.width = width;
this.height = height;
this.category = new CategoryBar(valueMax);
this.lBar = [];
this.lText = [];
this.category.addText(this.scene, selectWord("TOKENS : ", "JETONS : "), this.posX, this.posY, this.height);
}
addBar(value, valueMax, color, text) {
this.lText.push(text);
this.lBar.push(new Bar(this.scene, selectWord(text[0], text[1]), this.width, this.height, this.posX, this.posY, color, this.category, value, valueMax));
this.posY += this.height * 1.5;
this.category.setTextPos(this.posX, this.posY);
}
getJson() {
let json = '{';
json += '"lBar":[';
this.lBar.forEach(bar => json += bar.getJson() + ',');
json = endLineJson(json) + '],';
json += '"lText":[';
this.lText.forEach(text => {
json += '[';
text.forEach(word => {
json += '"' + word + '",';
});
json = endLineJson(json);
json += '],';
});
json = endLineJson(json);
json += ']';
json += '}';
return json;
}
}

@ -50,6 +50,7 @@ class LoadFile extends Phaser.Scene {
this.loadSprite('playLetter', 550, 150, 'buttons/');
this.loadSprite('cancel', 550, 150, 'buttons/');
this.loadSprite('add', 550, 150, 'buttons/');
this.loadSprite('modify', 550, 150, 'buttons/');
this.loadSprite('home', 550, 150, 'buttons/');
this.loadSprite('next', 550, 150, 'buttons/');
this.loadSprite('retry', 550, 150, 'buttons/');

@ -1,6 +1,6 @@
class Looser extends Finish {
constructor(father) {
super(father);
constructor(father, game) {
super(father, game);
}
create() {

@ -1,5 +1,5 @@
class RectangleNode {
constructor(x, y, scene, type, ...option) {
constructor(x, y, scene, type, option = []) {
switch (type.toString().toLowerCase()) {
case 'attack':
this.rect = new Phaser.GameObjects.Image(scene, x, y, 'attackNode');
@ -96,43 +96,19 @@ class RectangleNode {
}
}
toJson(name, value, end = false) {
let val;
if (typeof value === "string") {
val = '"' + name.toString() + '":"' + value + '"';
} else {
val = '"' + name.toString() + '":' + value;
}
if (!end)
val += ','
return val;
}
endLineJson(json) {
if (json.length > 0) {
if (json[json.length - 1] === ",") {
json = json.substr(0, json.length - 1);
}
}
return json;
}
save() {
getJson() {
let json = '{';
json += this.toJson("x", this.rect.x) + this.toJson("y", this.rect.y) + this.toJson("type", this.type);
json += toJson("x", this.rect.x) + toJson("y", this.rect.y) + toJson("type", this.type);
json += '"option":[';
this.option.forEach(option => json += option + ',');
json = this.endLineJson(json) + '],';
json = endLineJson(json) + '],';
if (this.canAddNode) {
json += '"lRect":[';
this.lRect.forEach(rect => json += rect.save() + ',');
json = this.endLineJson(json) + ']';
this.lRect.forEach(rect => json += rect.getJson() + ',');
json = endLineJson(json) + ']';
}
json = this.endLineJson(json);
json = endLineJson(json);
json += '}';
console.log(json)
return json;
}

@ -10,8 +10,8 @@ class Robot {
this.width = width;
this.x = posX;
this.y = posY;
this.life = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000);
this.shield = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF);
this.life = new HealthBar(scene, selectWord("LIFE", "VIE"), this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000);
this.shield = new HealthBar(scene, selectWord("SHIELD", "BOUCLIER"), this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF);
this.circleRange = null;
this.canAttack = true;

@ -1,6 +1,6 @@
class Winner extends Finish {
constructor(father) {
super(father);
constructor(father, game) {
super(father, game);
}
create() {

@ -1,5 +1,5 @@
class AddNode extends Phaser.Scene {
constructor(father, game, selected) {
constructor(father, game, selected, option = []) {
super('AddNode');
this.father = father;
this.gameR = game;
@ -8,20 +8,31 @@ class AddNode extends Phaser.Scene {
let sizeText = HEIGHT_WINDOW / 14;
this.style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"};
this.heightButton = HEIGHT_WINDOW / 8;
this.lastCategory = null;
this.option = option;
}
create(son) {
create() {
let height = HEIGHT_WINDOW / (4 / 3);
this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5);
this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5);
this.createButtonCancel();
this.createButtonAdd(son);
if (this.option.length > 0) {
this.createButtonModify();
} else {
this.createButtonAdd();
}
}
addButton(x, y, texture, category = new Category(), value) {
let btn = this.createButton(x, y, texture);
btn.on('pointerdown', () => this.click(btn, category, value));
if (category !== this.lastCategory && this.option.length > 0 && this.option[0] === value) {
this.option.splice(0, 1);
this.lastCategory = category;
this.click(btn, category, value);
}
return btn;
}
@ -62,9 +73,14 @@ class AddNode extends Phaser.Scene {
.on('pointerdown', () => this.cancel());
}
createButtonAdd(son) {
createButtonAdd() {
this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), 'add', HEIGHT_WINDOW / 9)
.on('pointerdown', () => son.addNode());
.on('pointerdown', () => this.addNode());
}
createButtonModify() {
this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), 'modify', HEIGHT_WINDOW / 9)
.on('pointerdown', () => this.modifyNode());
}
verifyCategory() {

@ -1,7 +1,8 @@
class Finish extends Phaser.Scene {
constructor(father) {
constructor(father, game) {
super('Finish');
this.father = father;
this.game = game;
}
create() {
@ -31,9 +32,11 @@ class Finish extends Phaser.Scene {
}
retry() {
console.log("RETRY");
this.close();
newGame(this.father);
console.log("RETRY");
if (this.father.scene.getIndex('Game') === -1) {
newGame(this.father);
}
this.father.scene.start('Game');
}
@ -44,6 +47,7 @@ class Finish extends Phaser.Scene {
home() {
console.log("HOME");
this.close();
this.father.scene.remove('Game');
this.father.scene.start('Type');
}
@ -58,7 +62,6 @@ class Finish extends Phaser.Scene {
close() {
this.sound.stopAll();
this.father.scene.remove('GamingBoard');
this.father.scene.remove('Game');
this.father.scene.remove('Finish');
}
}

@ -1,5 +1,5 @@
class HealthBar {
constructor(scene, width, height, x, y, valueMax, color, colorMin = COLOR_RED, middle = true) {
constructor(scene, name = "", width, height, x, y, valueMax, color, colorMin = COLOR_RED, middle = true) {
this.bar = new Phaser.GameObjects.Graphics(scene);
this.width = Math.floor(width);
@ -11,9 +11,15 @@ class HealthBar {
this.draw();
scene.add.existing(this.bar);
height = height - 4;
let style = {font: height.toString() + 'px stencil', fill: "#000000"};
this.nameText = scene.add.text(x, y, name, style).setOrigin(0, 0);
this.nameText.alpha = 0.5;
this.setX(x, middle);
this.setY(y);
scene.add.existing(this.bar);
}
setValue(value) {
@ -55,15 +61,16 @@ class HealthBar {
this.draw();
}
setX(x, middle= true) {
if(middle)
this.bar.setX(x - this.width / 2);
else
this.bar.setX(x);
setX(x, middle = true) {
if (middle)
x = x - this.width / 2;
this.bar.setX(x);
this.nameText.setX(x + 5);
}
setY(y) {
this.bar.setY(y);
this.nameText.setY(y);
}
draw() {
@ -93,5 +100,14 @@ class HealthBar {
destroy() {
this.bar.destroy();
this.nameText.destroy();
}
getJson() {
let json = '{';
json += toJson("value", this.value) + toJson("valueMax", this.valueMax) + toJson("color", this.color) + toJson("colorMin", this.colorMin);
json = endLineJson(json);
json += '}';
return json;
}
}
Loading…
Cancel
Save