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

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.

主站蜘蛛池模板: 遂平县| 宁阳县| 湾仔区| 太原市| 南澳县| 板桥市| 黄山市| 绥德县| 嘉兴市| 邹城市| 洛扎县| 乌兰察布市| 曲靖市| 格尔木市| 汝阳县| 安丘市| 天台县| 安阳县| 龙南县| 闽侯县| 崇义县| 泰州市| 汪清县| 沛县| 高邮市| 延边| 仲巴县| 岳阳县| 九江市| 磴口县| 尤溪县| 印江| 渭源县| 新和县| 青州市| 巴彦淖尔市| 抚宁县| 称多县| 博白县| 航空| 渑池县|