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

Castle banners

The castle banners will display the health and food for the castle. There will be two components inside the castle-banners component:

  • A vertical banner whose height changes, depending of the amount of the stat
  • A bubble with the actual number displayed

It will look like this:

  1. First, create a new castle-banners component with only the stat icons and a player prop:
      Vue.component('castle-banners', {
template: `<p class="banners">
<!-- Food -->
<img class="food-icon" src="svg/food-icon.svg" />
<!-- Bubble here -->
<!-- Banner bar here -->

<!-- Health -->
<img class="health-icon" src="svg/health-icon.svg" />
<!-- Bubble here -->
<!-- Banner bar here -->
</p>`,
props: ['player'],
})
  1. We also need two computed properties that calculate the health and food ratios:
      computed: {
foodRatio () {
return this.player.food / maxFood
},
healthRatio () {
return this.player.health / maxHealth
},
}

The maxFood and maxHealth variables are defined at the beginning of the state.js file.

  1. In the castle component, add the new castle-banners component:
      template: `<p class="castle" :class="'player-' + index">
<img class="building" :src="'svg/castle' + index + '.svg'" />
<img class="ground" :src="'svg/ground' + index + '.svg'" />
<castle-banners :player="player" />
</p>`,
主站蜘蛛池模板: 九龙坡区| 耒阳市| 宁波市| 沂水县| 盐山县| 南溪县| 高安市| 扎囊县| 宁夏| 绥阳县| 犍为县| 公主岭市| 益阳市| 剑川县| 河间市| 逊克县| 商丘市| 巴中市| 日喀则市| 延庆县| 页游| 拜泉县| 右玉县| 内江市| 三原县| 广南县| 龙泉市| 烟台市| 宝应县| 平阳县| 锡林浩特市| 中超| 新沂市| 莆田市| 德安县| 东阳市| 天祝| 泾阳县| 普陀区| 焉耆| 普安县|