-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattle.ts
More file actions
40 lines (37 loc) · 983 Bytes
/
Copy pathbattle.ts
File metadata and controls
40 lines (37 loc) · 983 Bytes
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
/*
The Battlefield component, rendered by the App component.
Responsible for rendering two Combatant components, and listening to
their `stars` output in order to highlight the winner.
*/
import { Component } from '@angular/core';
@Component({
selector: 'battle',
template: `
<div class="combatants">
<combatant [class.winner]="winner===1" (stars)="setUserStars(1, $event)"></combatant>
<combatant [class.winner]="winner===2" (stars)="setUserStars(2, $event)"></combatant>
</div>
`,
styles: [`
.combatants {
display: flex;
justify-content: space-around;
}
.winner {
background-color: gold;
}
`]
})
export class BattleComponent {
plrs = ["FOO",null,null]
get winner(){
let result = this.plrs[1] === null || this.plrs[2] === null ? 0
: this.plrs[1] === this.plrs[2] ? 0
: this.plrs[1] > this.plrs[2] ? 1
: 2;
return result;
}
setUserStars(plr, data){
this.plrs[plr] = data;
}
}