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