-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (46 loc) · 1.47 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Vue.component('pokemon', {
template: [
'<div class="pokemon">',
'<div class="pokemon-head"></div>',
'<div class="pokemon-body"></div>',
'<div class="pokemon-feet"></div>',
'</div>'
].join('')
});
const app = new Vue({
el: '#app',
data: {
player1: { pokemon: {}, winner: false },
player2: { pokemon: {}, winner: false },
pokemons: [
{ id: 0, name: 'pikachu', type: 'electro' },
{ id: 1, name: 'bulvasaur', type: 'planta' },
{ id: 2, name: 'squirtle', type: 'agua' },
{ id: 3, name: 'charmander', type: 'fuego' }
],
results: [
[0, 2, 1, 0],
[1, 0, 2, 2],
[2, 1, 0, 1],
[0, 1, 2, 0],
]
},
methods: {
fight: function () {
const result = this.results[this.player1.pokemon.id][this.player2.pokemon.id];
const selectWinner = [
() => { this.player1.winner = true; this.player2.winner = true; },
// empate
() => { this.player1.winner = true; this.player2.winner = false; },
// gana jugador 1
() => {this.player1.winner = false; this.player2.winner = true; }
// gana jugador 2
];
selectWinner[result]();
},
resetWinner: function () {
this.player1.winner = false;
this.player2.winner = false;
}
}
});