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

The overlays

The last UI elements we need are the overlays. The following are three of them:

  • The 'new turn' overlay shows the name of the current player when it is their turn. Clicking on the 'new turn' player switches to the 'last play' overlay.
  • The 'last play' overlay shows the player what their opponent did just before. It displays either of the following:
    • The card played by the opponent during the preceding turn
    • A reminder that their turn was skipped
  • The 'game over' overlay shows whenever a player or both players lose. It displays the names of the players with the phrase "is victorious" or "is defeated". Clicking on the 'game over' overlay reloads the game.

All of these overlays have two things in common--they do something when the user clicks on them, and they have a similar layout design. So, we should be smart here and structure our components to reuse code as much as we can where it makes sense. The idea here is to create a generic overlay component, which will take care of the click event and the layout and three specific overlay-content components for each one of the overlays we need.

Before starting, add a new activeOverlay property to the app state in the state.js file:

// The consolidated state of our app
var state = {
// UI
activeOverlay: null,
// ...
}

This will hold the name of the currently displayed overlay or will be null if no overlay is shown.

主站蜘蛛池模板: 永定县| 莲花县| 纳雍县| 甘谷县| 神农架林区| 明水县| 芦山县| 桦南县| 富川| 合肥市| 大同市| 高碑店市| 界首市| 万安县| 镇平县| 枣阳市| 深圳市| 鹿邑县| 英德市| 兴文县| 志丹县| 民乐县| 勐海县| 邛崃市| 广德县| 五莲县| 婺源县| 屏东市| 从江县| 宾川县| 双峰县| 乌拉特后旗| 义乌市| 于田县| 齐河县| 台南县| 武冈市| 正定县| 罗田县| 巴楚县| 子洲县|