Prechádzať zdrojové kódy

Add display of one player cards

Jojo 5 rokov pred
rodič
commit
3c954c127b

+ 20 - 0
src/controller/behaviors/game-master-steps.js

@@ -0,0 +1,20 @@
+'use strict';
+
+
+const GameMasterSteps = self => ({
+  selectFactionDeck: () => {
+    // Hardcoded
+    if (self.color === 'Blue') {
+      return Faction.HUMANS;
+    } else {
+      return Faction.ELVES;
+    }
+  },
+  selectDraftHeroes: (heroesDraftBurst) => {
+    console.log('Choose 2 heroes among : ', heroesDraftBurst);
+  },
+  selectTournamentDeck: (allHeroes) => {
+    console.log('Choose 12 heroes among : ', heroesDraftBurst);
+  }
+
+});

+ 13 - 8
src/controller/game-master-passnplay.js

@@ -2,19 +2,24 @@
 import {PlayerControllerLocal} from './player-controller';
 import HeroFactory from '../model/heroes/hero-factory';
 import TerminalRenderer from './../view/terminal-renderer';
+import PhaserRenderer from './../view/phaser-renderer';
 
 export default class GameMasterPassnplay {
   constructor(gameParams) {
-    let heroFactory = new HeroFactory();
-    let terminalRenderer = new TerminalRenderer();
-    let playerControllerRed = new PlayerControllerLocal(gameParams.playerRed);
-    let playerControllerBlue = new PlayerControllerLocal(gameParams.playerBlue);
-    playerControllerBlue.selectFactionDeck(terminalRenderer,heroFactory);
-    playerControllerRed.selectFactionDeck(terminalRenderer,heroFactory);
+    this.heroFactory = new HeroFactory();
+    this.terminalRenderer = new TerminalRenderer();
+    this.phaserRenderer = new PhaserRenderer();
+    this.playerControllerRed = new PlayerControllerLocal(gameParams.playerRed);
+    this.playerControllerBlue = new PlayerControllerLocal(gameParams.playerBlue);
+    this.playerControllerBlue.selectFactionDeck(this.terminalRenderer,this.heroFactory);
+    this.playerControllerRed.selectFactionDeck(this.terminalRenderer,this.heroFactory);
 
-    console.log('player Red deck : ', playerControllerRed.player.getHeroesDeck());
-    console.log('player Blue deck : ', playerControllerBlue.player.getHeroesDeck());
+    console.log('player Red deck : ', this.playerControllerRed.player.getHeroesDeck());
+    console.log('player Blue deck : ', this.playerControllerBlue.player.getHeroesDeck());
 
   }
 
+  start(game) {
+    this.phaserRenderer.render(game,this.playerControllerRed.player.getHeroesDeck());
+  }
 }

+ 1 - 42
src/controller/game/game-world-scene.js

@@ -3,47 +3,6 @@ import { PhaserScene } from '../../utils/const/phaser-scene-enum';
 import Phaser from 'phaser';
 import GameMasterPassnplay from '../game-master-passnplay';
 
-// function displayHeroes() {
-
-//   let i = 0;
-//   let j = 0;
-//   this.heroesSet.forEach(hero => {
-//     let x = 10 + (i * 80) + 5;
-//     let y = 10 + (j * 120) + 5;
-//     addCard(x, y, this, hero.name, hero.cost, hero.power, hero.ability.description);
-//     if (x >= 1040) {
-//       i = 0;
-//       j++;
-//     } else {
-
-//       i++;
-//     }
-
-//   });
-// }
-
-// function addCard(x, y, game, heroName, heroCost, heroPower, heroDesc) {
-//   let textStyle = {
-//     font: "normal 12px Arial",
-//     fill: '#000000',
-//     align: 'center',
-//     boundsAlignH: "center", // bounds center align horizontally
-//     boundsAlignV: "middle" // bounds center align vertically
-//   };
-//   let graphics = game.add.graphics(0, 0);
-//   let color = 0x654321;
-//   let thickness = 2;
-//   let alpha = 1;
-
-//   graphics.lineStyle(thickness, color, alpha);
-//   graphics.strokeRect(0, 0, 80, 120);
-//   let text = `${heroName}\ncost : ${heroCost}\npower : ${heroPower}`;
-//   let label = game.add.text(3, 3, text, textStyle);
-//   label.setOrigin(0, 0);
-//   let container = game.add.container(x, y, [graphics, label]).setSize(5, 5);
-//   // container.setOrigin(0, 0);
-// }
-
 export default class World extends Phaser.Scene {
 
   constructor() {
@@ -64,7 +23,7 @@ export default class World extends Phaser.Scene {
 
   create() {
     console.log('create');
-    // this.GameMasterPassnplay.start();
+    this.GameMasterPassnplay.start(this);
   }
 
   update() {

+ 59 - 0
src/view/phaser-renderer.js

@@ -0,0 +1,59 @@
+'use strict'
+
+import Renderer from './renderer';
+
+
+function addCard(x, y, game, heroName, heroCost, heroPower, heroDesc) {
+  let textStyle = {
+    font: "normal 12px Arial",
+    fill: '#000000',
+    align: 'center',
+    boundsAlignH: "center", // bounds center align horizontally
+    boundsAlignV: "middle" // bounds center align vertically
+  }
+  let graphics = game.add.graphics(0, 0);
+  let color = 0x654321;
+  let thickness = 2;
+  let alpha = 1;
+
+  graphics.lineStyle(thickness, color, alpha);
+  graphics.strokeRect(0, 0, 80, 120);
+  let text = `${heroName}\ncost : ${heroCost}\npower : ${heroPower}`;
+  let label = game.add.text(3, 3, text, textStyle);
+  label.setOrigin(0, 0);
+  let container = game.add.container(x, y, [graphics, label]).setSize(5, 5);
+  // container.setOrigin(0, 0);
+}
+
+export default class PhaserRenderer extends Renderer {
+  constructor() {
+    super();
+  }
+
+  render(game, heroesSet) {
+
+    let i = 0;
+    let j = 0;
+    heroesSet.forEach(hero => {
+      let x = 10 + (i * 80) + 5;
+      let y = 10 + (j * 120) + 5;
+      addCard(x, y, game, hero.name, hero.cost, hero.power, hero.ability.description);
+      if (x >= 1040) {
+        i = 0;
+        j++;
+      } else {
+
+        i++;
+      }
+
+    });
+  }
+
+
+
+
+  getInput(question) {
+    return prompt(question);
+  }
+}
+