Nikatlas 6 lat temu
rodzic
commit
69359cd994

+ 6 - 2
src/Game/game/machine/GameMachine.js

@@ -1,6 +1,5 @@
 // var Card = require('./Card.js');
 var SHA256 = require("crypto-js/sha256");
-
 // TO-DO
 
 // Need to create an initialization move or something to get verified!
@@ -14,7 +13,6 @@ class GameMachine {
             hash: "0123456789",
             stack: []
         };
-
     }
 
     setState(state) {
@@ -39,6 +37,11 @@ class GameMachine {
         this.state = { ...this.state, players};
     }
 
+    getPlayerNumber(player) {
+        return this.state.players[0] === player ? 0 : 1;
+        // return this.state.players[0] === UserService.getUsername() ? 0 : 1;
+    }
+
     runMove(move) {
         const spray = SHA256(JSON.stringify(move)).toString(); 
         if (this.state.stack.includes(spray)) {
@@ -52,6 +55,7 @@ class GameMachine {
             throw e;
         }
     }
+
     ownerOf(x) {
         return this.state.board.owners[x];
     }

+ 7 - 6
src/Game/services/GameService.js

@@ -1,5 +1,6 @@
 import Game from '../game/';
 import SocketService from '../services/SocketService';
+import UserService from '../services/UserService';
 
 class GameService {
     constructor() {
@@ -20,6 +21,9 @@ class GameService {
         this.state.salts = game.cards.saltArray;
         this.state.setup = game.setup;
 
+        // this.GameMachine.setPlayers([game.setup.id.playerOne, game.setup.id.playerTwo]);
+        
+        
         if(this.onInit) this.onInit();
         SocketService.on('move', (data) => this.move(data));
         SocketService.on('result', (data) => this.end(data));
@@ -27,11 +31,12 @@ class GameService {
 
     move(data) {
         // Game Machine perform internal Move
-
         let {cardid, position, player} = data;
 
+        let playerNum = player === UserService.getUsername();
         const card = new Game.Card(cardid);
-        const move = new Game.GameMoves.PlaceMove(card, position, player);
+        const move = new Game.GameMoves.PlaceMove(card, position, playerNum);
+
         try{
             this.GameMachine.runMove(move);
         } catch(e) {
@@ -43,12 +48,8 @@ class GameService {
     }
 
     end(data) {
-
-
-
         SocketService.close();
     }
-
 }
 
 export default new GameService();

+ 1 - 1
src/Game/views/buildings/Board.js

@@ -70,7 +70,7 @@ class BoardHandler extends GuiableContainer{
     sync = (board) => {
         const owners = board.owners;
         const data = board.data;
-
+        console.log(owners);
         this.holders.forEach((holder, index) => {
             if ( data[index] && !holder.isEmpty() ) {
                 holder.getCard().setTeam(owners[index]);

+ 5 - 0
src/Game/views/buildings/Deck.js

@@ -65,11 +65,16 @@ class DeckHandler extends GuiableContainer{
         }
     }
 
+    setTeam(team) {
+        this.cards.forEach((item) => item.setTeam(team));
+    }
+
     sync(cards) {
         if(!cards)return;
         this.cards.forEach((holder, index) => {
             const card = new Card({id: cards[index]});
             this.addChild(card);
+            card.setTeam();
             card.attach(holder);
         });
     }

+ 1 - 4
src/Game/views/buildings/Menu.js

@@ -42,10 +42,9 @@ class Menu extends GuiableContainer{
 
     construct(props) {
         this.parentLayer = Injector.getByName('MainLayer');
-
         this.textSprite = new Text({text: "123", y: -345});
         this.textSprite.setText(UserService.getUsername() + ':' + UserService.getToken());
-            
+
         let play = new Button({  y:-100 , Text: {text: "Play"}});
         play.onClick((e) => {
             SocketService.openSocket('randomFree');
@@ -69,8 +68,6 @@ class Menu extends GuiableContainer{
             nav.go('Login');
         });
 
-
-
         this.addChild(play);
         this.addChild(collection);
         this.addChild(logout);

+ 2 - 3
src/Game/views/demo/Board.js

@@ -38,11 +38,10 @@ class BoardDemo extends PIXI.Container{
             this.board.sync(GameService.GameMachine.state.board);
         }
     }
-    update() {}
 
-    _kill = () => {
+    update() {}
 
-    }
+    _kill = () => {}
 
     getAsJSON = () => {return {component: 'demo/Board'}}
 }