質問編集履歴
1
付け加えました
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,9 +2,109 @@
|
|
2
2
|
何かいい方法はありますか?
|
3
3
|
functionをそれぞれ定数で置いて$(this).を使えればよいのですが、そのthisを取得してそれに応じて定数を呼び出すやり方が分からないです。
|
4
4
|
|
5
|
+
```html
|
6
|
+
<!DOCTYPE HTML>
|
5
7
|
|
8
|
+
<html lang="jp" dir="ltr">
|
9
|
+
<head>
|
6
10
|
|
11
|
+
<meta charset="utf-8">
|
12
|
+
<title>test</title>
|
13
|
+
<link rel="stylesheet" href="style.css">
|
14
|
+
<script src="http://code.jquery.com/jquery-3.3.1.js"></script>
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<div id = "soft"></div>
|
18
|
+
<div class="title">
|
19
|
+
TEST GAME
|
20
|
+
</div>
|
7
21
|
|
22
|
+
<div id="player"></div>
|
23
|
+
<div>
|
24
|
+
<ul class="menu">
|
25
|
+
<li id = "Attack" class="Attack">攻撃</li>
|
26
|
+
<li id = "Magic" class="Magic">魔法</li>
|
27
|
+
</ul>
|
28
|
+
<ul class="magicMenu">
|
29
|
+
<li id ="Fspell">炎魔法</li>
|
30
|
+
<li id ="Ispell">氷魔法</li>
|
31
|
+
<li id ="Lspell">雷魔法</li>
|
32
|
+
<li id ="Hspell">回復魔法</li>
|
33
|
+
<li id ="return">戻る</li>
|
34
|
+
|
35
|
+
</ul>
|
36
|
+
|
37
|
+
<ul class="Pstatus">
|
38
|
+
<li class="PHitPoint">Pl.HP</li>
|
39
|
+
<li class="PMagicPoint">Pl.MP</li>
|
40
|
+
</ul>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="enemy">
|
44
|
+
<ul class="Estatus">
|
45
|
+
<li class="EHitPoint">En.HP</li>
|
46
|
+
<li class="EMagicPoint">En.MP</li>
|
47
|
+
</ul>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
<script type="text/javascript">
|
53
|
+
|
54
|
+
//画面処理
|
55
|
+
var soft1 = document.getElementById("soft");
|
56
|
+
var input1 = document.createElement("input");
|
57
|
+
var div1 = document.createElement("div");
|
58
|
+
|
59
|
+
input1.setAttribute("value" , "START");
|
60
|
+
input1.setAttribute("id", "input");
|
61
|
+
input1.setAttribute("type", "button");
|
62
|
+
|
63
|
+
|
64
|
+
div1.appendChild(input1);
|
65
|
+
soft1.appendChild(div1);
|
66
|
+
|
67
|
+
//ゲーム処理
|
68
|
+
|
69
|
+
var Attack = document.getElementById("Attack");
|
70
|
+
var Magic = document.getElementById("Magic");
|
71
|
+
|
72
|
+
class Player {
|
73
|
+
constructor(HP,MP){
|
74
|
+
this.HP =HP;
|
75
|
+
this.MP =MP;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
class Enemy {
|
79
|
+
constructor(HP,MP){
|
80
|
+
this.HP =HP;
|
81
|
+
this.MP =MP;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
const Pl = new Player(100,50);
|
86
|
+
const En = new Enemy(200,50);
|
87
|
+
|
88
|
+
function statusShow() {
|
89
|
+
|
90
|
+
$(".PHitPoint").html("HP:"+Pl.HP);
|
91
|
+
$(".PMagicPoint").html("MP:"+Pl.MP);
|
92
|
+
|
93
|
+
$(".EHitPoint").html("HP:"+En.HP);
|
94
|
+
$(".EMagicPoint").html("MP:"+En.MP);
|
95
|
+
}
|
96
|
+
|
97
|
+
statusShow () ;
|
98
|
+
|
99
|
+
</script>
|
100
|
+
<script src="script.js"></script>
|
101
|
+
|
102
|
+
</body>
|
103
|
+
</html>
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
|
8
108
|
```jQuery
|
9
109
|
//炎魔法を唱える
|
10
110
|
$("#Fspell").on("click", function(){
|
@@ -34,4 +134,86 @@
|
|
34
134
|
statusShow ();
|
35
135
|
$(".magicMenu").hide();
|
36
136
|
});
|
137
|
+
```
|
138
|
+
```css
|
139
|
+
#input {
|
140
|
+
position:absolute;
|
141
|
+
top:0px;
|
142
|
+
bottom:0px;
|
143
|
+
left:0px;
|
144
|
+
right:0px;
|
145
|
+
margin: auto;
|
146
|
+
width:80px;
|
147
|
+
height:30px;
|
148
|
+
}
|
149
|
+
|
150
|
+
.title {
|
151
|
+
width:300px;
|
152
|
+
height:100px;
|
153
|
+
font-size:50px;
|
154
|
+
position:absolute;
|
155
|
+
top:0px;
|
156
|
+
bottom:150px;
|
157
|
+
left:0px;
|
158
|
+
right:0px;
|
159
|
+
margin: auto;
|
160
|
+
}
|
161
|
+
|
162
|
+
#player {
|
163
|
+
//display:none;
|
164
|
+
width:100px;
|
165
|
+
height:100px;
|
166
|
+
background-color:black;
|
167
|
+
position:absolute;
|
168
|
+
top:350px;
|
169
|
+
}
|
170
|
+
|
171
|
+
#enemy {
|
172
|
+
//display:none;
|
173
|
+
width:100px;
|
174
|
+
height:100px;
|
175
|
+
background-color:red;
|
176
|
+
position:absolute;
|
177
|
+
top:350px;
|
178
|
+
right:50px;
|
179
|
+
}
|
180
|
+
.menu {
|
181
|
+
//display:none;
|
182
|
+
border: 2px solid black;
|
183
|
+
width:130px;
|
184
|
+
height:100px;
|
185
|
+
position:absolute;
|
186
|
+
top:200px;
|
187
|
+
left:200px;
|
188
|
+
}
|
189
|
+
|
190
|
+
.Pstatus{
|
191
|
+
//display:none;
|
192
|
+
border: 2px solid black;
|
193
|
+
width:130px;
|
194
|
+
height:100px;
|
195
|
+
position:absolute;
|
196
|
+
top:200px;
|
197
|
+
left:10px;
|
198
|
+
}
|
199
|
+
.Estatus{
|
200
|
+
//display:none;
|
201
|
+
border: 2px solid black;
|
202
|
+
width:130px;
|
203
|
+
height:100px;
|
204
|
+
position:absolute;
|
205
|
+
bottom:110px;
|
206
|
+
right:10px;
|
207
|
+
}
|
208
|
+
|
209
|
+
.magicMenu{
|
210
|
+
display:none;
|
211
|
+
border: 2px solid black;
|
212
|
+
background-color: white;
|
213
|
+
width:130px;
|
214
|
+
height:130px;
|
215
|
+
position:absolute;
|
216
|
+
top:200px;
|
217
|
+
left:200px;
|
218
|
+
}
|
37
219
|
```
|