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

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>`,
主站蜘蛛池模板: 龙胜| 大同县| 疏附县| 交口县| 三门县| 临城县| 民丰县| 兰考县| 富源县| 蕲春县| 武汉市| 南开区| 昌都县| 金湖县| 梅州市| 乌鲁木齐县| 云南省| 油尖旺区| 平阳县| 平邑县| 略阳县| 孙吴县| 汤原县| 安宁市| 南溪县| 阿荣旗| 桦南县| 平阳县| 虎林市| 汽车| 漠河县| 呼伦贝尔市| 双流县| 易门县| 永胜县| 安顺市| 城市| 金坛市| 通渭县| 杂多县| 昂仁县|