- Vue.js 2 Web Development Projects
- Guillaume Chau
- 120字
- 2021-07-02 22:34:32
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.
推薦閱讀
- Python快樂(lè)編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- Mastering Zabbix(Second Edition)
- SQL Server 2016從入門(mén)到精通(視頻教學(xué)超值版)
- Developing Mobile Web ArcGIS Applications
- Java程序設(shè)計(jì)與實(shí)踐教程(第2版)
- Internet of Things with Intel Galileo
- Java軟件開(kāi)發(fā)基礎(chǔ)
- MATLAB定量決策五大類問(wèn)題
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- Apex Design Patterns
- RealSenseTM互動(dòng)開(kāi)發(fā)實(shí)戰(zhàn)
- Web前端開(kāi)發(fā)最佳實(shí)踐
- Less Web Development Cookbook
- Java EE實(shí)用教程
- HTML5+CSS+JavaScript深入學(xué)習(xí)實(shí)錄