Browse Source

adding socket.io

jojo 5 years ago
parent
commit
95e6788666
40 changed files with 867 additions and 549 deletions
  1. 373 204
      package-lock.json
  2. 7 3
      package.json
  3. 7 0
      server/game-server/duel-controller.js
  4. 33 0
      server/main.js
  5. 16 0
      server/players/player-id.js
  6. 37 37
      src/assets/all-heroes.json
  7. 20 0
      src/common/game-params.js
  8. 35 0
      src/common/socket-service.js
  9. 10 0
      src/common/utils/const/faction-enum.js
  10. 7 0
      src/common/utils/const/game-deck-mode-enum.js
  11. 0 0
      src/common/utils/const/game-type-enum.js
  12. 7 0
      src/common/utils/const/phaser-scene-enum.js
  13. 9 0
      src/common/utils/prompt-renderer.js
  14. 0 20
      src/controller/behaviors/game-master-steps.js
  15. 0 25
      src/controller/game-master-passnplay.js
  16. 0 11
      src/controller/game-params.js
  17. 0 32
      src/controller/game/game-world-scene.js
  18. 0 39
      src/controller/menu/main-menu-scene.js
  19. 0 25
      src/controller/phaser-engine.js
  20. 0 0
      src/game/control/behaviors/deck-building-steps.js
  21. 65 0
      src/game/control/game-controller-pnp.js
  22. 0 0
      src/game/control/player-controller.js
  23. 0 0
      src/game/game-model/game-global-state.js
  24. 0 0
      src/game/game-model/heroes/hero-ability.js
  25. 1 1
      src/game/game-model/heroes/hero-factory.js
  26. 0 0
      src/game/game-model/heroes/hero.js
  27. 0 0
      src/game/game-model/player.js
  28. 10 0
      src/game/views/deck-building-scene.js
  29. 36 0
      src/game/views/faction-deck-building-scene.js
  30. 69 0
      src/game/views/game-world-scene.js
  31. 15 40
      src/main.js
  32. 15 0
      src/main.test.js
  33. 40 0
      src/menu/control/menu-controller.js
  34. 55 0
      src/menu/views/main-menu-scene.js
  35. 0 10
      src/utils/const/faction-enum.js
  36. 0 7
      src/utils/const/game-mode-enum.js
  37. 0 6
      src/utils/const/phaser-scene-enum.js
  38. 0 59
      src/view/phaser-renderer.js
  39. 0 15
      src/view/renderer.js
  40. 0 15
      src/view/terminal-renderer.js

File diff suppressed because it is too large
+ 373 - 204
package-lock.json


+ 7 - 3
package.json

@@ -6,11 +6,12 @@
     "ecosystem:cordova"
   ],
   "scripts": {
+    "server": "babel-node server/main.js",
     "dev": "webpack --watch",
     "precor-build": "cordova prepare",
     "cor-build": "CORDOVA=true cordova build -- --webpackConfig webpack.config.js",
     "cordova": "CORDOVA=true cordova run -- -w webpack.config.js",
-    "start": "npm-run-all --parallel dev lint:watch",
+    "start": "npm-run-all --parallel server dev lint:watch",
     "lint": "esw webpack.config.* src --color",
     "lint:watch": "npm run lint -- --watch",
     "localtunnel": "lt --port 3000",
@@ -24,14 +25,15 @@
   "dependencies": {
     "@babel/node": "7.6.2",
     "@babel/polyfill": "7.6.0",
+    "express": "^4.17.1",
     "phaser": "3.19.0"
   },
   "devDependencies": {
     "@babel/cli": "7.6.2",
-    "@babel/core": "7.6.2",
+    "@babel/core": "^7.6.2",
     "@babel/plugin-proposal-object-rest-spread": "^7.6.2",
     "@babel/preset-env": "7.6.2",
-    "@babel/register": "7.6.2",
+    "@babel/register": "^7.6.2",
     "babel-loader": "8.0.6",
     "browser-sync": "2.26.7",
     "browser-sync-webpack-plugin": "2.2.2",
@@ -53,6 +55,8 @@
     "path": "0.12.7",
     "raw-loader": "3.1.0",
     "readline-sync": "1.4.10",
+    "socket.io": "^2.3.0",
+    "socket.io-client": "^2.3.0",
     "webpack": "4.41.0",
     "webpack-cli": "3.3.9",
     "webpack-dev-middleware": "3.7.2",

+ 7 - 0
server/game-server/duel-controller.js

@@ -0,0 +1,7 @@
+'use strict';
+
+export default class DuelController {
+  constructor(playerOne, playerTwo) {
+    console.log('DuelCtrl constructor : ' + playerOne.playerName + ' and : ' + playerTwo.playerName);
+  }
+}

+ 33 - 0
server/main.js

@@ -0,0 +1,33 @@
+'use strict';
+import PlayerId from './players/player-id';
+import DuelController from './game-server/duel-controller';
+
+const io = require('socket.io'); //(http)
+const server = io.listen(4000);
+
+let players = [];
+
+let addNewPlayer = function (playerSocket, playerName) {
+  console.log('players length : ' + players.length + ' : ' + players);
+  if (players.length < 2) {
+    let newPlayer = new PlayerId(playerSocket,playerName);
+    console.log('push player : ' + newPlayer);
+    players.push(newPlayer);
+  }
+  if (players.length === 2) {
+    let duelController = new DuelController(players[0], players[1]);
+  }
+}
+
+server.on('connection', function (socket) {
+  console.log("A player connected with id : " + socket.id);
+  socket.on ('disconnect', () => {
+    console.log("A player disconnected with id : " + socket.id);
+  });
+
+  socket.on('auth', (playerName) => {
+    console.log(' Received auth message, player name : ' + playerName);
+    addNewPlayer(socket, playerName);
+  });
+
+})

+ 16 - 0
server/players/player-id.js

@@ -0,0 +1,16 @@
+'use strict';
+
+export default class PlayerId {
+  constructor(playerSocket, playerName = '', playerColor = 'unk') {
+    this.playerSocket = playerSocket;
+    this.playerName = playerName;
+    this.playerColor = playerColor;
+  }
+
+  setPlayerName(playerName) {
+    this.playerName = playerName;
+  }
+  setPlayerColor(playerColor) {
+    this.playerColor = playerColor;
+  }
+}

+ 37 - 37
src/assets/all-heroes.json

@@ -5,7 +5,7 @@
       "name" : "Paysan",
       "cost" : 0,
       "power" : 1,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : true,
       "ability": "PaysanAbility",
       "nbInDeck": 2
@@ -14,7 +14,7 @@
       "name" : "Dragon",
       "cost" : 7,
       "power" : 6,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : true,
       "ability": "DragonAbility",
       "nbInDeck": 1
@@ -23,7 +23,7 @@
       "name" : "Archange",
       "cost" : 4,
       "power" : 3,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : true,
       "ability": "ArchangeAbility",
       "nbInDeck": 1
@@ -32,7 +32,7 @@
       "name" : "Chevalier",
       "cost" : 3,
       "power" : 4,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : true,
       "ability": "ChevalierAbility",
       "nbInDeck": 2
@@ -41,7 +41,7 @@
       "name" : "Faucon Geant",
       "cost" : 1,
       "power" : 2,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : false,
       "ability": "FauconAbility",
       "nbInDeck": 1
@@ -50,7 +50,7 @@
       "name" : "Intendant",
       "cost" : 2,
       "power" : 2,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : false,
       "ability": "IntendantAbility",
       "nbInDeck": 1
@@ -59,7 +59,7 @@
       "name" : "Canon",
       "cost" : 1,
       "power" : 4,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : false,
       "ability": "CanonAbility",
       "nbInDeck": 1
@@ -68,7 +68,7 @@
       "name" : "Char",
       "cost" : 3,
       "power" : 3,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : false,
       "ability": "CharAbility",
       "nbInDeck": 1
@@ -77,7 +77,7 @@
       "name" : "Chevre",
       "cost" : 1,
       "power" : 2,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : false,
       "ability": "ChevreAbility",
       "nbInDeck": 1
@@ -86,7 +86,7 @@
       "name" : "Stratege",
       "cost" : 1,
       "power" : 2,
-      "faction": "Humans",
+      "faction": "humans",
       "draftMode" : false,
       "ability": "StrategeAbility",
       "nbInDeck": 1
@@ -95,7 +95,7 @@
       "name" : "Homme-Arbre",
       "cost" : 4,
       "power" : 4,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : true,
       "ability": "HommeArbreAbility",
       "nbInDeck": 2
@@ -104,7 +104,7 @@
       "name" : "Elf",
       "cost" : 2,
       "power" : 2,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : true,
       "ability": "ElfAbility",
       "nbInDeck": 2
@@ -113,7 +113,7 @@
       "name" : "Stratege",
       "cost" : 1,
       "power" : 2,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : true,
       "ability": "StrategeAbility",
       "nbInDeck": 1
@@ -122,7 +122,7 @@
       "name" : "Intendant",
       "cost" : 2,
       "power" : 2,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : true,
       "ability": "IntendantAbility",
       "nbInDeck": 1
@@ -131,7 +131,7 @@
       "name" : "Faucon Geant",
       "cost" : 1,
       "power" : 2,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : true,
       "ability": "FauconAbility",
       "nbInDeck": 2
@@ -140,7 +140,7 @@
       "name" : "Paysan",
       "cost" : 0,
       "power" : 1,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : false,
       "ability": "PaysanAbility",
       "nbInDeck": 1
@@ -149,7 +149,7 @@
       "name" : "Archange",
       "cost" : 4,
       "power" : 3,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : true,
       "ability": "ArchangeAbility",
       "nbInDeck": 1
@@ -158,7 +158,7 @@
       "name" : "Chevre",
       "cost" : 1,
       "power" : 2,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : false,
       "ability": "ChevreAbility",
       "nbInDeck": 1
@@ -167,7 +167,7 @@
       "name" : "Voilier Celeste",
       "cost" : 1,
       "power" : 2,
-      "faction": "Elves",
+      "faction": "elves",
       "draftMode" : false,
       "ability": "VoilierAbility",
       "nbInDeck": 1
@@ -176,16 +176,16 @@
       "name" : "Orc",
       "cost" : 3,
       "power" : 3,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : true,
-      "ability": "OrcAbility",
+      "ability": "orcsAbility",
       "nbInDeck": 2
     },
     {
       "name" : "Behemoth",
       "cost" : 5,
       "power" : 5,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : true,
       "ability": "BehemothAbility",
       "nbInDeck": 2
@@ -194,7 +194,7 @@
       "name" : "Gobelin",
       "cost" : 0,
       "power" : 2,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : true,
       "ability": "GobelinAbility",
       "nbInDeck": 2
@@ -203,7 +203,7 @@
       "name" : "Char",
       "cost" : 3,
       "power" : 3,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : true,
       "ability": "CharAbility",
       "nbInDeck": 2
@@ -212,7 +212,7 @@
       "name" : "Chevre",
       "cost" : 1,
       "power" : 2,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : true,
       "ability": "ChevreAbility",
       "nbInDeck": 2
@@ -221,7 +221,7 @@
       "name" : "Paysan",
       "cost" : 0,
       "power" : 1,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : false,
       "ability": "PaysanAbility",
       "nbInDeck": 1
@@ -230,7 +230,7 @@
       "name" : "Intendant",
       "cost" : 2,
       "power" : 2,
-      "faction": "Orcs",
+      "faction": "orcs",
       "draftMode" : true,
       "ability": "IntendantAbility",
       "nbInDeck": 1
@@ -239,7 +239,7 @@
       "name" : "Geant de Fer",
       "cost" : 2,
       "power" : 3,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : true,
       "ability": "GeantAbility",
       "nbInDeck": 2
@@ -248,7 +248,7 @@
       "name" : "Golem",
       "cost" : 4,
       "power" : 4,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : true,
       "ability": "GolemAbility",
       "nbInDeck": 2
@@ -257,7 +257,7 @@
       "name" : "Canon",
       "cost" : 1,
       "power" : 4,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : true,
       "ability": "CanonAbility",
       "nbInDeck": 2
@@ -266,7 +266,7 @@
       "name" : "Char",
       "cost" : 3,
       "power" : 3,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : false,
       "ability": "CharAbility",
       "nbInDeck": 1
@@ -275,7 +275,7 @@
       "name" : "Voilier Celeste",
       "cost" : 1,
       "power" : 2,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : true,
       "ability": "VoilierAbility",
       "nbInDeck": 2
@@ -284,7 +284,7 @@
       "name" : "Intendant",
       "cost" : 2,
       "power" : 2,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : false,
       "ability": "IntendantAbility",
       "nbInDeck": 1
@@ -293,7 +293,7 @@
       "name" : "Gobelin",
       "cost" : 0,
       "power" : 2,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : false,
       "ability": "GobelinAbility",
       "nbInDeck": 1
@@ -302,7 +302,7 @@
       "name" : "Stratege",
       "cost" : 1,
       "power" : 2,
-      "faction": "Meca",
+      "faction": "meca",
       "draftMode" : true,
       "ability": "StrategeAbility",
       "nbInDeck": 1
@@ -397,10 +397,10 @@
       "abilityDesc-FR" : "Quand le Voilier Celeste est deploye, vous pouvez ajouter gratuitement avec lui un Heros de cout 0 ou 1 de votre main. Si ce Heros a un effet quand il est recrute, appliquez-le."
     },
     {
-      "abilityName" : "OrcAbility",
+      "abilityName" : "orcsAbility",
       "abilityHook": "AfterDeploy",
       "optionnal": "false",
-      "abilityDesc-FR" : "Quand l'Orc est deploye, chaque joueur doit defausser 1 Nourriture dans cette region, s'il le peut."
+      "abilityDesc-FR" : "Quand l'orcs est deploye, chaque joueur doit defausser 1 Nourriture dans cette region, s'il le peut."
     },
     {
       "abilityName" : "BehemothAbility",

+ 20 - 0
src/common/game-params.js

@@ -0,0 +1,20 @@
+'use strict';
+
+export default class GameParams {
+  constructor(playerBlueName, playerRedName, gameDeckMode, advancedRules = []) {
+    this.playerBlueName = playerBlueName;
+    this.playerRedName = playerRedName;
+    this.gameDeckMode = gameDeckMode;
+    this.advancedRules = advancedRules;
+  }
+
+  setCurrentPlayer(playerController) {
+    this.currentPlayer = playerController;
+  }
+
+  getCurrentPlayer() {
+    return this.currentPlayer;
+  }
+
+
+}

+ 35 - 0
src/common/socket-service.js

@@ -0,0 +1,35 @@
+'use strict';
+import io from 'socket.io-client';
+
+/*
+  Messages :
+    - disconnect
+    - reconnecting
+    - reconnect
+    - reconnect_failed
+    -
+*/
+const SERVER_URL = process.env.SERVER_URL || 'http://localhost';
+const SERVER_PORT = process.env.SERVER_PORT || 4000;
+
+export default class SocketService {
+  constructor(namespace) {
+
+    this.ioClient = io.connect(SERVER_URL + ":" + SERVER_PORT + '/');
+  }
+
+  connect(serverUrl, serverPort) {
+    this.disconnected=false;
+    this.ioClient = io.connect(serverUrl + ":" + serverPort);
+
+    console.log("is connected : " + this.ioClient.connected);
+    this.ioClient.on('disconnect', () => {
+      console.log("Connection with server lost");
+
+    });
+  }
+  auth(name) {
+    console.log("Authenticate to server player name : " + name);
+    this.ioClient.emit('auth', name);
+  }
+}

+ 10 - 0
src/common/utils/const/faction-enum.js

@@ -0,0 +1,10 @@
+'use strict';
+
+export const Faction = Object.freeze({
+    HUMANS : "humans",
+    ORCS: "orcs",
+    ELVES: "elves",
+    MECA: "meca",
+    NONE:"none"
+
+  });

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

@@ -0,0 +1,7 @@
+'use strict';
+
+export const GameDeckMode = Object.freeze({
+    FACTIONS : "factions",
+    DRAFT: "draft",
+    TOURNAMENT: "tournament"
+  });

+ 0 - 0
src/utils/const/game-type-enum.js → src/common/utils/const/game-type-enum.js


+ 7 - 0
src/common/utils/const/phaser-scene-enum.js

@@ -0,0 +1,7 @@
+'use strict';
+
+export const PhaserScene = Object.freeze({
+    MAIN_MENU : "MainMenuScene",
+    GAME_WORLD: "GameWorldScene",
+    DECK_BUILDING: "DeckBuildingScene"
+  });

+ 9 - 0
src/common/utils/prompt-renderer.js

@@ -0,0 +1,9 @@
+'use strict';
+
+export function promptSelectAmongOptions(message, options) {
+  let selection = "";
+  while (options.includes(selection) === false) {
+    selection = prompt(`${message} (${options}) :`);
+  }
+  return selection;
+}

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

@@ -1,20 +0,0 @@
-'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);
-  }
-
-});

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

@@ -1,25 +0,0 @@
-'use strict';
-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) {
-    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 : ', this.playerControllerRed.player.getHeroesDeck());
-    console.log('player Blue deck : ', this.playerControllerBlue.player.getHeroesDeck());
-
-  }
-
-  start(game) {
-    this.phaserRenderer.render(game,this.playerControllerRed.player.getHeroesDeck());
-  }
-}

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

@@ -1,11 +0,0 @@
-'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;
-  }
-}

+ 0 - 32
src/controller/game/game-world-scene.js

@@ -1,32 +0,0 @@
-'use strict';
-import { PhaserScene } from '../../utils/const/phaser-scene-enum';
-import Phaser from 'phaser';
-import GameMasterPassnplay from '../game-master-passnplay';
-
-export default class World extends Phaser.Scene {
-
-  constructor() {
-    super({ key: PhaserScene.WORLD, active: false });
-    console.log('constructor');
-  }
-
-  init(gameParams){
-    console.log('Init', gameParams);
-    this.gameParams = gameParams;
-    this.GameMasterPassnplay = new GameMasterPassnplay(gameParams);
-
-  }
-  preload() {
-    console.log('Preload');
-
-  }
-
-  create() {
-    console.log('create');
-    this.GameMasterPassnplay.start(this);
-  }
-
-  update() {
-
-  }
-}

+ 0 - 39
src/controller/menu/main-menu-scene.js

@@ -1,39 +0,0 @@
-'use strict';
-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 {
-
-  constructor() {
-    super({ key: PhaserScene.MAIN_MENU, active: false });
-  }
-
-  preload() {
-    console.log('Preload');
-    this.load.image('logo', '../../assets/twelveHeroes_cover.png');
-  }
-
-  create() {
-    console.log('create');
-    let logo = this.add.sprite(0,0,'logo');
-    logo.setOrigin(0,0);
-    setTimeout(() => {
-
-
-      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() {
-
-  }
-}

+ 0 - 25
src/controller/phaser-engine.js

@@ -1,25 +0,0 @@
-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';
-
-export default class PhaserEngine {
-  constructor() {
-
-    // our game's configuration
-    let config = {
-      type: Phaser.CANVAS,
-      width: 1200,
-      height: 500,
-      scene: [MainMenu,World],
-      backgroundColor: 'rgba(34,139,34 ,1 )'
-    };
-
-    this.gameEngine = new Phaser.Game(config);
-  }
-
-  start() {
-    this.gameEngine.scene.start(PhaserScene.MAIN_MENU);
-  }
-
-}

+ 0 - 0
src/controller/behaviors/deck-building-steps.js → src/game/control/behaviors/deck-building-steps.js


+ 65 - 0
src/game/control/game-controller-pnp.js

@@ -0,0 +1,65 @@
+'use strict';
+import HeroFactory from '../game-model/heroes/hero-factory';
+import { PhaserScene } from '../../common/utils/const/phaser-scene-enum';
+import GameWorldScene from '../views/game-world-scene';
+import { GameDeckMode } from '../../common/utils/const/game-deck-mode-enum';
+import FactionDeckBuildingScene from '../views/faction-deck-building-scene';
+import Player from '../game-model/player';
+
+export default class GameControllerPnp {
+  constructor(phaserEngine, gameParams) {
+    this.phaserEngine = phaserEngine;
+    console.log("In constructor" + this.phaserEngine);
+    this.gameParams = gameParams;
+
+    this.playerBlue = new Player(gameParams.playerBlueName, "Blue");
+    this.playerRed = new Player(gameParams.playerResName, "Red");
+
+    console.log();
+    switch (this.gameParams.gameDeckMode) {
+      case GameDeckMode.FACTIONS:
+        this.deckBuildingScene = new FactionDeckBuildingScene(this.gameEventListener());
+        break;
+
+      default:
+        // ONLY Factions mode
+        this.deckBuildingScene = new FactionDeckBuildingScene(this.gameEventListener());
+        break;
+    }
+
+    // Instantiates Heroes
+    this.heroFactory = new HeroFactory();
+  }
+
+  displayDeckBuilding() {
+    console.log("In displayDeckBuilding " + this.phaserEngine);
+    this.phaserEngine.scene.add(PhaserScene.DECK_BUILDING, this.deckBuildingScene);
+    this.phaserEngine.scene.start(PhaserScene.DECK_BUILDING);
+    this.phaserEngine.scene.remove(PhaserScene.MAIN_MENU);
+  }
+  displayGameWorld() {
+    this.phaserEngine.scene.add(PhaserScene.GAME_WORLD, this.gameWorldScene);
+    this.phaserEngine.scene.start (PhaserScene.GAME_WORLD);
+    this.phaserEngine.scene.remove(PhaserScene.DECK_BUILDING);
+  }
+
+  gameEventListener() {
+    return {
+      onFactionsSelected: this.onFactionsSelected.bind(this)
+    };
+  }
+
+  onFactionsSelected(playerBlueFaction, playerRedFaction ) {
+    this.playerBlue.setFaction(playerBlueFaction);
+    this.playerRed.setFaction(playerRedFaction);
+
+    this.playerBlue.setHeroesDeck(this.heroFactory.getFactionRandom(this.playerBlue.faction));
+    this.playerRed.setHeroesDeck(this.heroFactory.getFactionRandom(this.playerRed.faction));
+
+    console.log('player Blue deck : ', this.playerBlue.getHeroesDeck());
+    console.log('player Red deck : ', this.playerRed.getHeroesDeck());
+    this.gameWorldScene = new GameWorldScene(this.playerBlue, this.playerRed);
+    this.displayGameWorld();
+  }
+
+}

+ 0 - 0
src/controller/player-controller.js → src/game/control/player-controller.js


+ 0 - 0
src/game/game-model/game-global-state.js


+ 0 - 0
src/model/heroes/hero-ability.js → src/game/game-model/heroes/hero-ability.js


+ 1 - 1
src/model/heroes/hero-factory.js → src/game/game-model/heroes/hero-factory.js

@@ -1,5 +1,5 @@
 'use strict';
-import allHeroesJson from "../../assets/all-heroes.json";
+import allHeroesJson from "../../../assets/all-heroes.json";
 import Hero from './hero';
 import HeroAbility from './hero-ability';
 

+ 0 - 0
src/model/heroes/hero.js → src/game/game-model/heroes/hero.js


+ 0 - 0
src/model/player.js → src/game/game-model/player.js


+ 10 - 0
src/game/views/deck-building-scene.js

@@ -0,0 +1,10 @@
+'use strict';
+import { PhaserScene } from '../../common/utils/const/phaser-scene-enum';
+import Phaser from 'phaser';
+
+export default class DeckBuildingScene extends Phaser.Scene {
+
+  constructor() {
+    super({ key: PhaserScene.DECK_BUILDING, active: false });
+  }
+}

+ 36 - 0
src/game/views/faction-deck-building-scene.js

@@ -0,0 +1,36 @@
+'use strict';
+import DeckBuildingScene from './deck-building-scene';
+import { Faction } from '../../common/utils/const/faction-enum';
+import * as Utils from '../../common/utils/prompt-renderer';
+
+export default class FactionDeckBuildingScene extends DeckBuildingScene {
+
+  constructor(gameEventListener) {
+    super();
+    this.gameEventListener = gameEventListener;
+  }
+
+  preload() {
+    console.log('Preload');
+
+  }
+
+  create() {
+    console.log('create');
+
+
+    setTimeout(() => {
+      let factionOptions = Object.values(Faction).filter(faction => faction !== Faction.NONE);
+      let pBlueFaction = Utils.promptSelectAmongOptions("Select Player Blue Faction", factionOptions);
+
+      factionOptions = factionOptions.filter(faction => faction !== pBlueFaction);
+      let pRedFaction = Utils.promptSelectAmongOptions("Select Player Red Faction", factionOptions);
+      this.gameEventListener.onFactionsSelected(pBlueFaction, pRedFaction );
+    }, 100);
+  }
+
+  update() {
+
+  }
+}
+

+ 69 - 0
src/game/views/game-world-scene.js

@@ -0,0 +1,69 @@
+'use strict';
+import { PhaserScene } from '../../common/utils/const/phaser-scene-enum';
+import Phaser from 'phaser';
+
+export default class GameWorldScene extends Phaser.Scene {
+
+  constructor(playerBlue, playerRed) {
+    super({ key: PhaserScene.GAME_WORLD, active: false });
+    this.playerBlue = playerBlue;
+    this.playerRed = playerRed;
+  }
+
+  preload() {
+    console.log('Preload');
+
+  }
+
+  create() {
+    console.log('create');
+    render(this, this.playerBlue.getHeroesDeck(),0 );
+    render(this, this.playerRed.getHeroesDeck(),300 );
+  }
+
+  update() {
+
+  }
+}
+
+function addCard(x, y, phaser, 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 = phaser.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 = phaser.add.text(3, 3, text, textStyle);
+  label.setOrigin(0, 0);
+  let container = phaser.add.container(x, y, [graphics, label]).setSize(5, 5);
+  // container.setOrigin(0, 0);
+}
+
+
+  function render(game, heroesSet, offset) {
+
+    let i = 0;
+    let j = 0;
+    heroesSet.forEach(hero => {
+      let x = 10 + (i * 80) + 5;
+      let y = 10 + offset + (j * 120) + 5;
+      addCard(x, y, game, hero.name, hero.cost, hero.power, hero.ability.description);
+      if (x >= 1040) {
+        i = 0;
+        j++;
+      } else {
+
+        i++;
+      }
+
+    });
+  }

+ 15 - 40
src/main.js

@@ -1,14 +1,25 @@
 'use strict';
 
 /* eslint-disable no-unused-vars */
-/* eslint-disable no-console */
 
-import PhaserEngine from './controller/phaser-engine';
+import MenuController from './menu/control/menu-controller';
+import Phaser from 'phaser';
 
 function startGame() {
   console.log('start Game');
-  let phaserEngine = new PhaserEngine();
-  phaserEngine.start();
+
+  let phaserConfig = {
+    type: Phaser.CANVAS,
+    width: 1200,
+    height: 500,
+    scene: [],
+    backgroundColor: 'rgba(34,139,34 ,1 )'
+  };
+  let phaserEngine = new Phaser.Game(phaserConfig);
+  let menuController = new MenuController(phaserEngine);
+
+  //menuController.displayMainMenu();
+
 }
 
 let app = {
@@ -48,39 +59,3 @@ if (process.env.CORDOVA) {
 } else {
   startGame();
 }
-
-
-
-
-
-// const config = {
-//   type: Phaser.AUTO,
-//   parent: "phaser-example",
-//   width: 800,
-//   height: 600,
-//   scene: {
-//     preload: preload,
-//     create: create
-//   }
-// };
-
-// const game = new Phaser.Game(config);
-
-// function preload() {
-//   this.load.image("logo", logoImg);
-// }
-
-// function create() {
-//   const logo = this.add.image(400, 150, "logo");
-
-//   this.tweens.add({
-//     targets: logo,
-//     y: 350,
-//     duration: 2000,
-//     ease: "Power2",
-//     yoyo: true,
-//     loop: -1
-//   });
-// }
-
-

+ 15 - 0
src/main.test.js

@@ -0,0 +1,15 @@
+'use strict';
+
+// import * as chai from 'chai';
+
+// let assert = chai.assert;
+// let should = chai.should();
+// let expect = chai.expect;
+
+
+describe('Main', () => {
+  it('Should start cordova game', (done) => {
+    process.env.CORDOVA = null;
+    done();
+  });
+});

+ 40 - 0
src/menu/control/menu-controller.js

@@ -0,0 +1,40 @@
+'use strict';
+
+import MainMenuScene from '../views/main-menu-scene';
+import { PhaserScene } from '../../common/utils/const/phaser-scene-enum';
+import GameParams from '../../common/game-params';
+import GameControllerPnp from '../../game/control/game-controller-pnp';
+import SocketService from '../../common/socket-service';
+
+export default class MenuController {
+
+  constructor(phaserEngine) {
+    this.phaserEngine = phaserEngine;
+    console.log("In constructor MenuController " + this.phaserEngine);
+
+    this.mainMenuScene = new MainMenuScene(this.menuEventListener());
+    this.socketService = new SocketService();
+    this.socketService.connect('http://localhost', 4000);
+    this.socketService.auth('Jojo');
+  }
+
+  displayMainMenu() {
+
+    this.phaserEngine.scene.add(PhaserScene.MAIN_MENU,this.mainMenuScene);
+    this.phaserEngine.scene.start(PhaserScene.MAIN_MENU);
+  }
+
+  menuEventListener() {
+    return {
+      onNewPnpGame: this.onNewPnpGame.bind(this)
+    };
+  }
+
+  onNewPnpGame(pBlueName, pRedName, gameMode, advancedRules) {
+    console.log("onNewPnpGame this  : " + this);
+      let gameParams = new GameParams(pBlueName,pRedName,gameMode,advancedRules);
+      let gameControllerPnp = new GameControllerPnp(this.phaserEngine, gameParams);
+      gameControllerPnp.displayDeckBuilding();
+  }
+
+}

+ 55 - 0
src/menu/views/main-menu-scene.js

@@ -0,0 +1,55 @@
+'use strict';
+import {GameDeckMode} from '../../common/utils/const/game-deck-mode-enum';
+import { PhaserScene } from '../../common/utils/const/phaser-scene-enum';
+import Phaser from 'phaser';
+import * as Utils from '../../common/utils/prompt-renderer';
+
+export default class MainMenuScene extends Phaser.Scene {
+
+  constructor(menuEventListener) {
+    super({ key: PhaserScene.MAIN_MENU, active: false });
+    this.menuEventListener = menuEventListener;
+
+  }
+
+  preload() {
+    console.log('Preload');
+    this.load.image('game-cover', '../../assets/twelveHeroes_cover.png');
+  }
+
+  create() {
+    console.log('create');
+    let logo = this.add.image(0,0,'game-cover');
+    logo.setOrigin(0,0);
+
+
+    //this.add.dom
+
+
+
+    // TODO : Display main menu
+    // Create new scenes : Local player room / Multi player room
+    // Pass to them the event listener
+    // On local player room, user can enter player names, selected color, game deck mode & rules
+
+    // FOR TESTING
+    this.fakeNewPnpGameSelected();
+  }
+
+  update() {
+
+  }
+
+  fakeNewPnpGameSelected() {
+    setTimeout(() => {
+      let pBlueName = prompt("Player blue name : ");
+      let pRedName = prompt("Player red name : ");
+
+      let gameDeckModeOptions = Object.values(GameDeckMode);
+      let gameDeckMode = Utils.promptSelectAmongOptions("Select Deck Mode", gameDeckModeOptions);
+      let advancedRules = [];
+      console.log("Calling listener");
+      this.menuEventListener.onNewPnpGame(pBlueName, pRedName, gameDeckMode, advancedRules);
+    }, 1000);
+  }
+}

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

@@ -1,10 +0,0 @@
-'use strict';
-
-export const Faction = Object.freeze({
-    HUMANS : "Humans",
-    ORCS: "Orcs",
-    ELVES: "Elves",
-    MECA: "Meca",
-    None:"None"
-
-  });

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

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

+ 0 - 6
src/utils/const/phaser-scene-enum.js

@@ -1,6 +0,0 @@
-'use strict';
-
-export const PhaserScene = Object.freeze({
-    MAIN_MENU : "MainMenu",
-    WORLD: "World"
-  });

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

@@ -1,59 +0,0 @@
-'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);
-  }
-}
-

+ 0 - 15
src/view/renderer.js

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

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

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

Some files were not shown because too many files changed in this diff