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

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>`,
主站蜘蛛池模板: 山西省| 平定县| 屯留县| 手游| 綦江县| 大田县| 东源县| 日照市| 瑞丽市| 昆山市| 壤塘县| 常山县| 岳阳市| 井研县| 五大连池市| 焉耆| 涿鹿县| 新营市| 石狮市| 梨树县| 大城县| 安顺市| 葵青区| 霸州市| 囊谦县| 南宫市| 西青区| 兰州市| 兴仁县| 开平市| 西充县| 杭锦后旗| 杭州市| 溧水县| 内丘县| 大冶市| 延边| 德昌县| 禹城市| 基隆市| 惠东县|