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

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.

主站蜘蛛池模板: 金寨县| 松阳县| 耒阳市| 滦南县| 大安市| 洛宁县| 綦江县| 宜宾县| 永德县| 渑池县| 绥化市| 清流县| 阿尔山市| 民乐县| 南宫市| 江门市| 宜良县| 安多县| 高淳县| 罗定市| 乐至县| 宿州市| 改则县| 新兴县| 河北区| 仪陇县| 普兰店市| 雷波县| 托克逊县| 仲巴县| 宁国市| 岱山县| 若尔盖县| 长春市| 萨迦县| 乃东县| 聂拉木县| 武清区| 阳信县| 利川市| 屏东县|