-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
144 lines (140 loc) · 6.13 KB
/
index.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue JS Dersleri</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>
<body>
<div id="app">
<div class="container">
<div class="row mt-4">
<div class="col-12 text-center">
<h1>{{ gameName }}</h1>
</div>
</div>
<div class="row mt-2 text-center">
<div class="col-6"><strong>{{ yourName }}</strong></div>
<div class="col-6"><strong>{{ foreignerName }}</strong></div>
</div>
<div class="row">
<div class="col-6">
<div class="progress" style="height: 40px;">
<div class="progress-bar bg-danger" role="progressbar" v-bind:style="{width: health1 + '%'}" v-bind:aria-valuenow="health1" aria-valuemin="0" v-bind:aria-valuemax="health1">{{ health1 }}%</div>
</div>
</div>
<div class="col-6">
<div class="progress" style="height: 40px;">
<div class="progress-bar bg-danger" role="progressbar" v-bind:style="{width: health2 + '%'}" v-bind:aria-valuenow="health2" aria-valuemin="0" v-bind:aria-valuemax="health2">{{ health2 }}%</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-12 text-center">
<small class="text-secondary">Actions</small>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<div class="btn-group w-100">
<button v-on:click="fight" class="btn btn-success">Fight</button>
<button v-on:click="specialFight" class="btn btn-warning">Special Fight</button>
<button v-on:click="health" class="btn btn-primary">Healt</button>
<button v-on:click="giveup" class="btn btn-secondary">Give up!</button>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-12 text-center">
<small class="text-secondary">History</small>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item" v-for="item in histories">{{ item }}</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
histories : ["The game reading to start."],
gameName: 'Monster Fight Game',
yourName: 'I am Monster Killer!',
foreignerName: 'Monster',
health1: 100,
health2: 100,
},
methods: {
fight: function()
{
this.histories.push(this.yourName + ' attacked.');
this.health1 = damage(this.health1, 10);
this.health2 = damage(this.health2, 10);
this.histories.push(this.yourName + ' health is ' + this.health1);
this.histories.push(this.foreignerName + ' health is ' + this.health2);
},
specialFight: function()
{
this.histories.push('Oh my god! "' + this.yourName + '" used special attack.');
this.health1 = damage(this.health1, 10);
this.health2 = damage(this.health2, 30);
this.histories.push(this.yourName + ' health is ' + this.health1);
this.histories.push(this.foreignerName + ' health is ' + this.health2);
},
health: function()
{
this.histories.push(this.yourName + ' increased health.');
this.health1 = health(this.health1, 30);
this.histories.push(this.yourName + ' health is ' + this.health1);
this.histories.push(this.foreignerName + ' health is ' + this.health2);
},
giveup: function()
{
this.histories.push(this.yourName + ' gived up!');
this.health1 = 0;
this.histories.push(this.yourName + ' health is ' + this.health1);
this.histories.push(this.foreignerName + ' health is ' + this.health2);
},
},
watch: {
health1: function()
{
if(this.health1 == 0)
{
alert('You lost! Winner: ' + this.foreignerName);
this.histories.push('Winner: ' + this.foreignerName);
}
},
health2: function()
{
if(this.health2 == 0)
{
alert('You win! Winner: ' + this.yourName);
this.histories.push('Winner: ' + this.yourName);
}
}
}
});
function damage(current, power)
{
var score = current - Math.ceil(Math.random() * power);
return score <= 0 ? 0 : score;
}
function health(current, power)
{
var health = current + Math.ceil(Math.random() * power);
return health >= 100 ? 100 : health;
}
</script>
</body>
</html>