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

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.

主站蜘蛛池模板: 仪征市| 弥勒县| 龙井市| 南雄市| 南昌市| 奉贤区| 环江| 新龙县| 磐石市| 永德县| 启东市| 西畴县| 阳信县| 鸡泽县| 雷波县| 宁阳县| 佛坪县| 察哈| 漠河县| 环江| 民权县| 巴里| 玉树县| 铅山县| 灵武市| 彩票| 横峰县| 穆棱市| 安吉县| 巴中市| 安岳县| 甘孜县| 黄梅县| 叶城县| 泊头市| 大宁县| 辽中县| 繁昌县| 新沂市| 凉城县| 马公市|