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

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.

主站蜘蛛池模板: 尼玛县| 观塘区| 游戏| 施甸县| 闻喜县| 赤水市| 新巴尔虎左旗| 河津市| 原阳县| 邳州市| 曲水县| 家居| 福鼎市| 綦江县| 城步| 凉山| 秀山| 朝阳区| 连云港市| 溆浦县| 和静县| 凌源市| 安溪县| 剑川县| 城固县| 汕头市| 成都市| 乐业县| 灵山县| 长寿区| 安仁县| 云浮市| 稻城县| 龙山县| 英超| 于田县| 沅陵县| 临清市| 原平市| 景德镇市| 泽州县|