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

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.

主站蜘蛛池模板: 漾濞| 武乡县| 贞丰县| 剑川县| 孝感市| 霞浦县| 宿州市| 黔西| 茂名市| 安达市| 喀喇| 中牟县| 报价| 定南县| 南溪县| 苏尼特左旗| 宁武县| 思南县| 大名县| 中卫市| 汕头市| 祁门县| 丁青县| 汪清县| 元阳县| 沈丘县| 长沙市| 瑞丽市| 鄯善县| 阿克苏市| 长白| 郯城县| 武平县| 安庆市| 土默特左旗| 开鲁县| 伊通| 博兴县| 洛浦县| 桐梓县| 邳州市|