官术网_书友最值得收藏!

Adding some gameplay data to the state

Before creating the component, we need some new data properties:

  • turn: The number of the current turn; starts at 1
  • players: The array of player objects
  • currentPlayerIndex: The index of the current player in the players array

Add them in the state in the state.js file:

// The consolidated state of our app
var state = {
// World
worldRatio: getWorldRatio(),
// Game
turn: 1,
players: [
{
name: 'Anne of Cleves',
},
{
name: 'William the Bald',
},
],
currentPlayerIndex: Math.round(Math.random()),
}

Math.round(Math.random()) will use 0 or 1 randomly to choose who goes first.

We will use these properties to display the player names and the turn counter in the top bar.

主站蜘蛛池模板: 高邮市| 张家川| 黄大仙区| 闽清县| 义马市| 衡阳市| 新巴尔虎右旗| 松溪县| 南安市| 旬阳县| 南川市| 成安县| 类乌齐县| 蒲江县| 沛县| 平果县| 绥棱县| 洛隆县| 玉环县| 县级市| 灵宝市| 宣威市| 克拉玛依市| 蒲江县| 黔西| 乳山市| 福贡县| 根河市| 米易县| 麻江县| 常州市| 沁水县| 金门县| 贵溪市| 临安市| 依兰县| 北安市| 安吉县| 横峰县| 彭州市| 乐昌市|