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

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>`,
主站蜘蛛池模板: 咸丰县| 绥中县| 朝阳市| 兴仁县| 淮南市| 平利县| 淮南市| 南华县| 东辽县| 巧家县| 凤城市| 文登市| 黄龙县| 长汀县| 肇庆市| 遵义县| 都兰县| 财经| 庆云县| 汉川市| 射洪县| 大关县| 江油市| 宜川县| 瓮安县| 济阳县| 阿合奇县| 阳泉市| 通辽市| 中卫市| 邵阳市| 泰顺县| 山东| 沾益县| 朝阳县| 左贡县| 平江县| 霍州市| 广安市| 兰溪市| 玛多县|