afiodorov / stratego

Lord of the rings inspired stratego game
GNU Lesser General Public License v3.0
0 stars 0 forks source link

GameState api for Board class #5

Open afiodorov opened 10 years ago

afiodorov commented 10 years ago

Board class implements update() method which receives an instance of gameState class.

GameState class:

var GameState = function() {};
gameState = new GameState();
gameState.mySide = "light" | "dark";
gameState.stage = "start" | "move" | "battle" | "finish";
gameState.light.pieces = [{name: "gandalf", position: [2,2]}, ... ];
/* names ommited */
gameState.dark.pieces = [{position: [2,2]}, ... ];
gameState.turn = "light" | "dark";
MatthewEnevoldsen commented 10 years ago

I'd suggest having a main game state, the whole one that the server stores, and functions to turn the gameState into a side specific one. (see below) gameState = { turn: side.light | side.dark, stage: stage.start | stage.move | stage.battle | stage.finish, pieces: [{name: "gandalf", position: [2,1]}, ...] } lightState { turn: side.light | side.dark, stage: stage.start | stage.move | stage.battle | stage.finish, friendlyPieces: [{name: "gandalf", position: [2,1]}, ...], enemyPieces: [[2,1],[0,0]] } Same for dark.

afiodorov commented 10 years ago

no quite the same, but on master in models/utils/gameutils.js

/**

MatthewEnevoldsen commented 10 years ago

gameState = { turn: side.light | side.dark, stage: stage.start | stage.move | stage.battle | stage.finish, pieces: [{name: "gandalf", position: {row:2, col:1}}, ...] } lightState { turn: side.light | side.dark, stage: stage.start | stage.move | stage.battle | stage.finish, friendlyPieces: [{name: "gandalf", position: {row: 2,col:1 } }, ...], enemyPieces: [{position:{row:2, col:1}}, {position:{row:0,col:0}},...] }