Browse Source

introducing composition + prompt renderer

Jojo 5 years ago
parent
commit
66ee802f7b

+ 6 - 0
package-lock.json

@@ -9079,6 +9079,12 @@
         "readable-stream": "^2.0.2"
       }
     },
+    "readline-sync": {
+      "version": "1.4.10",
+      "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz",
+      "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==",
+      "dev": true
+    },
     "rechoir": {
       "version": "0.7.0",
       "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.7.0.tgz",

+ 1 - 0
package.json

@@ -52,6 +52,7 @@
     "open": "6.4.0",
     "path": "0.12.7",
     "raw-loader": "3.1.0",
+    "readline-sync": "1.4.10",
     "webpack": "4.41.0",
     "webpack-cli": "3.3.9",
     "webpack-dev-middleware": "3.7.2",

+ 16 - 0
src/controller/behaviors/deck-building-steps.js

@@ -0,0 +1,16 @@
+'use strict';
+
+
+export const DeckBuildingSteps = self => ({
+  selectFactionDeck: (renderer,heroFactory) => {
+    self.player.faction = renderer.getInput(self.player.name + ' to choose faction');
+    self.player.setHeroesDeck(heroFactory.getFactionRandom(self.player.faction));
+  },
+  selectDraftHeroes: (heroesDraftBurst) => {
+    console.log('Choose 2 heroes among : ', heroesDraftBurst);
+  },
+  selectTournamentDeck: (allHeroes) => {
+    console.log('Choose 12 heroes among : ', allHeroes);
+  }
+
+});

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


+ 0 - 19
src/controller/game-generator.js

@@ -1,19 +0,0 @@
-'use strict';
-import HeroFactory from '../model/heroes/hero-factory';
-import { Faction } from '../utils/const/faction-enum';
-
-export default class GameGenerator {
-  constructor(gameType) {
-    let heroFactory = new HeroFactory();
-
-
-    this.heroesSet = heroFactory.getFactionRandom(Faction.MECA);
-    console.log('Faction Set : ', this.heroesSet);
-
-
-
-  }
-  getHeroesSet(){
-    return this.heroesSet;
-  }
-}

+ 20 - 0
src/controller/game-master-passnplay.js

@@ -0,0 +1,20 @@
+'use strict';
+import {PlayerControllerLocal} from './player-controller';
+import HeroFactory from '../model/heroes/hero-factory';
+import TerminalRenderer from './../view/terminal-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);
+
+    console.log('player Red deck : ', playerControllerRed.player.getHeroesDeck());
+    console.log('player Blue deck : ', playerControllerBlue.player.getHeroesDeck());
+
+  }
+
+}

+ 11 - 0
src/controller/game-params.js

@@ -0,0 +1,11 @@
+'use strict';
+
+export default class GameParams {
+  constructor(gameType, playerBlue, playerRed, gameMode, advancedRules = []) {
+    this.gameType = gameType;
+    this.playerBlue = playerBlue;
+    this.playerRed = playerRed;
+    this.gameMode = gameMode;
+    this.advancedRules = advancedRules;
+  }
+}

+ 47 - 40
src/controller/game/game-world-scene.js

@@ -1,27 +1,48 @@
 'use strict';
 import { PhaserScene } from '../../utils/const/phaser-scene-enum';
+import Phaser from 'phaser';
+import GameMasterPassnplay from '../game-master-passnplay';
 
-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;
+// function displayHeroes() {
 
-  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);
-}
+//   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 {
 
@@ -30,9 +51,11 @@ export default class World extends Phaser.Scene {
     console.log('constructor');
   }
 
-  init(data){
-    console.log('Init');
-    this.heroesSet = data.heroesSet;
+  init(gameParams){
+    console.log('Init', gameParams);
+    this.gameParams = gameParams;
+    this.GameMasterPassnplay = new GameMasterPassnplay(gameParams);
+
   }
   preload() {
     console.log('Preload');
@@ -41,23 +64,7 @@ export default class World extends Phaser.Scene {
 
   create() {
     console.log('create');
-    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++;
-      }
-
-    });
-//     this.fformUtil.scaleToGameW("optList", .8);
-// this.formUtil.placeElementAt(27, "optList");
+    // this.GameMasterPassnplay.start();
   }
 
   update() {

+ 14 - 9
src/controller/menu/main-menu-scene.js

@@ -1,7 +1,10 @@
 'use strict';
-import GameGenerator from '../game-generator';
 import {GameType} from '../../utils/const/game-type-enum';
+import {GameMode} from '../../utils/const/game-mode-enum';
 import { PhaserScene } from '../../utils/const/phaser-scene-enum';
+import Phaser from 'phaser';
+import GameParams from '../game-params';
+import Player from '../../model/player';
 
 export default class MainMenu extends Phaser.Scene {
 
@@ -9,9 +12,6 @@ export default class MainMenu extends Phaser.Scene {
     super({ key: PhaserScene.MAIN_MENU, active: false });
   }
 
-  init(data){
-    console.log('Init');
-  }
   preload() {
     console.log('Preload');
     this.load.image('logo', '../../assets/twelveHeroes_cover.png');
@@ -19,13 +19,18 @@ export default class MainMenu extends Phaser.Scene {
 
   create() {
     console.log('create');
-    let logo = this.add.sprite(20,0,'logo');
+    let logo = this.add.sprite(0,0,'logo');
     logo.setOrigin(0,0);
     setTimeout(() => {
-      console.log('timeout end');
-      let gameGen = new GameGenerator(GameType.PASSNPLAY);
-      this.scene.start('World',{heroesSet:gameGen.getHeroesSet()});
-    }, 5000);
+
+
+      let playerBlue = new Player('Jojo', 'Blue');
+      let playerRed = new Player('Mart', 'Red');
+
+      let gameParams = new GameParams(GameType.PASSNPLAY,playerBlue,playerRed,GameMode.FACTIONS);
+
+      this.scene.start(PhaserScene.WORLD,gameParams);
+    }, 3000);
   }
 
   update() {

+ 1 - 1
src/controller/phaser-engine.js

@@ -1,4 +1,4 @@
-import 'phaser';
+import Phaser from 'phaser';
 import World from './game/game-world-scene';
 import MainMenu from './menu/main-menu-scene';
 import { PhaserScene } from '../utils/const/phaser-scene-enum';

+ 10 - 0
src/controller/player-controller.js

@@ -0,0 +1,10 @@
+'use-strict';
+import {DeckBuildingSteps} from './behaviors/deck-building-steps';
+
+export const PlayerControllerLocal = function(player) {
+  const self = {
+    player
+  };
+
+  return Object.assign(self, DeckBuildingSteps(self));
+};

+ 1 - 1
src/main.js

@@ -6,7 +6,7 @@
 import PhaserEngine from './controller/phaser-engine';
 
 function startGame() {
-  console.log('start Game')
+  console.log('start Game');
   let phaserEngine = new PhaserEngine();
   phaserEngine.start();
 }

+ 18 - 0
src/model/player.js

@@ -0,0 +1,18 @@
+'use strict';
+
+export default class Player {
+  constructor(name, color, faction = 'None') {
+    this.name = name;
+    this.color = color;
+    this.faction = faction;
+  }
+  setFaction(faction) {
+    this.faction = faction;
+  }
+  setHeroesDeck(heroesDeck) {
+    this.heroesDeck = heroesDeck;
+  }
+  getHeroesDeck(){
+    return this.heroesDeck;
+  }
+}

+ 1 - 0
src/utils/const/faction-enum.js

@@ -6,4 +6,5 @@ export const Faction = Object.freeze({
     ELVES: "Elves",
     MECA: "Meca",
     None:"None"
+
   });

+ 7 - 0
src/utils/const/game-mode-enum.js

@@ -0,0 +1,7 @@
+'use strict';
+
+export const GameMode = Object.freeze({
+    FACTIONS : "Factions",
+    DRAFT: "Draft",
+    TOURNAMENT: "Tournament"
+  });

+ 15 - 0
src/view/renderer.js

@@ -0,0 +1,15 @@
+'user strict';
+
+export default class Renderer {
+  constructor() {
+    if (this.constructor === Renderer) {
+      throw new TypeError('Abstract class "Renderer" cannot be instantiated directly.');
+    }
+
+
+  }
+
+  render(){}
+
+  getInput(){}
+}

+ 15 - 0
src/view/terminal-renderer.js

@@ -0,0 +1,15 @@
+'use strict';
+import Renderer from './renderer';
+export default class TerminalRenderer extends Renderer {
+  constructor() {
+    super();
+  }
+
+  render(info) {
+    console.log (info);
+  }
+
+  getInput(question) {
+    return prompt(question);
+  }
+}

+ 1 - 1
webpack.config.js

@@ -12,7 +12,7 @@ var definePlugin = new webpack.DefinePlugin({
 var outpath = './webpack/';
 
 if (process.env.CORDOVA) {
-  var outpath = 'www/';
+  outpath = 'www/';
 }
 
 module.exports = {