Skip to content

Commit 65348d6

Browse files
author
Shaun Pelling
committed
added lesson 13 code - punch bag
1 parent cda1fe7 commit 65348d6

File tree

5 files changed

+49
-26
lines changed

5 files changed

+49
-26
lines changed

app.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
new Vue({
22
el: '#vue-app',
33
data: {
4-
characters: ['Mario', 'Luigi', 'Yoshi', 'Bowser'],
5-
ninjas: [
6-
{ name: 'Ryu', age: 25 },
7-
{ name: 'Yoshi', age: 35 },
8-
{ name: 'Ken', age: 55 }
9-
]
4+
health: 100,
5+
ended: false
106
},
117
methods: {
12-
8+
punch: function(){
9+
this.health -= 10;
10+
if ( this.health <= 0 ){
11+
this.ended = true;
12+
}
13+
},
14+
restart: function(){
15+
this.health = 100;
16+
this.ended = false;
17+
}
1318
},
1419
computed: {
1520

img/bag-burst.png

13.6 KB
Loading

img/bag.png

6.98 KB
Loading

index.html

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
</head>
99
<body>
1010
<div id="vue-app">
11-
<h1>Looping through lists</h1>
12-
<ul>
13-
<li v-for="character in characters">{{ character }}</li>
14-
</ul>
15-
<ul>
16-
<li v-for="(ninja, index) in ninjas">{{ index }} . {{ ninja.name }} - {{ ninja.age }}</li>
17-
</ul>
18-
<template v-for="(ninja, index) in ninjas">
19-
<h3>{{ index }} . {{ ninja.name }}</h3>
20-
<p>Age - {{ ninja.age }}</p>
21-
</template>
11+
<!-- bag image -->
12+
<div id="bag" v-bind:class="{ burst: ended }"></div>
13+
14+
<!-- bag health bar -->
15+
<div id="bag-health">
16+
<div v-bind:style="{ width: health + '%' }"></div>
17+
</div>
18+
19+
<!-- game control buttons -->
20+
<div id="controls">
21+
<button v-on:click="punch" v-show="!ended">Punch</button>
22+
<button v-on:click="restart">Restart</button>
23+
</div>
2224
</div>
2325
</body>
2426

styles.css

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
.error{
2-
background: red;
3-
padding: 10px;
4-
color: white;
1+
#bag{
2+
width: 200px;
3+
height: 500px;
4+
margin: 0 auto;
5+
background: url(/img/bag.png) center no-repeat;
6+
background-size: 80%;
57
}
68

7-
.success{
8-
background: green;
9-
padding: 10px;
10-
color: white;
9+
#bag.burst{
10+
background-image: url(/img/bag-burst.png);
11+
}
12+
13+
#bag-health{
14+
width: 200px;
15+
border: 2px solid #000;
16+
margin: 0 auto 20px auto;
17+
}
18+
19+
#bag-health div{
20+
height: 20px;
21+
background: crimson
22+
}
23+
24+
#controls{
25+
width: 120px;
26+
margin: 0 auto;
1127
}

0 commit comments

Comments
 (0)