質問編集履歴
1
ソースコードを記載いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,201 @@
|
|
8
8
|
|
9
9
|
いくつも質問して申し訳ないですが、よろしくお願い致します。
|
10
10
|
|
11
|
-
|
11
|
+
```Java1
|
12
|
+
|
13
|
+
package application;
|
14
|
+
|
15
|
+
class Actor extends Thread{
|
16
|
+
|
17
|
+
private int hitpoint;
|
18
|
+
|
19
|
+
private int offence;
|
20
|
+
|
21
|
+
private int deffence;
|
22
|
+
|
23
|
+
private String name;
|
24
|
+
|
25
|
+
private Actor target;
|
26
|
+
|
27
|
+
private int deley = 1;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public int getHitPoint() {
|
32
|
+
|
33
|
+
return hitpoint;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
public int getOffence() {
|
40
|
+
|
41
|
+
return offence;
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
public int getDeffence() {
|
48
|
+
|
49
|
+
return deffence;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
public Actor getTarget() {
|
54
|
+
|
55
|
+
return target;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public void setHitPoint(int hitpoint) {
|
62
|
+
|
63
|
+
this.hitpoint = hitpoint;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
public void setAttack(int offence) {
|
68
|
+
|
69
|
+
this.offence = offence;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
public void setDeffence(int deffence) {
|
74
|
+
|
75
|
+
this.deffence = deffence;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
public void setTarget(Actor target) {
|
82
|
+
|
83
|
+
this.target = target;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
public boolean isDead() {
|
88
|
+
|
89
|
+
return target.hitpoint<=0;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public Actor(String name,int hitpoint,int offence,int deffence) {
|
96
|
+
|
97
|
+
this.name = name;
|
98
|
+
|
99
|
+
this.hitpoint = hitpoint;
|
100
|
+
|
101
|
+
this.offence = offence;
|
102
|
+
|
103
|
+
this.deffence = deffence;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
public void attack(Actor pActor) {
|
110
|
+
|
111
|
+
int damage = offence - pActor.getDeffence();
|
112
|
+
|
113
|
+
if(damage >= 0) {
|
114
|
+
|
115
|
+
pActor.setHitPoint(pActor.getHitPoint()-damage);
|
116
|
+
|
117
|
+
System.out.println(name+"は"+pActor.getName()+"に"+damage+"のダメージを与えた!");
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
}else if(damage<=0) {
|
122
|
+
|
123
|
+
System.out.println("ダメージを受けない");
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
public void run() {
|
136
|
+
|
137
|
+
while(true) {
|
138
|
+
|
139
|
+
try {
|
140
|
+
|
141
|
+
sleep(0 * deley);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
}catch(InterruptedException e) {
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
if(isDead()) {
|
150
|
+
|
151
|
+
System.out.println(target+"を倒した!");
|
152
|
+
|
153
|
+
break;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
attack(target);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
```html
|
170
|
+
|
171
|
+
package application;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
public class MyMain {
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
public static void main(String[] args) {
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
Actor Hero = new Actor("主人公",100,25,15);
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
Actor Enemy1 = new Actor("敵1",60,30,5);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
Hero.setTarget(Enemy1);
|
194
|
+
|
195
|
+
Enemy1.setTarget(Hero);
|
196
|
+
|
197
|
+
Hero.start();
|
198
|
+
|
199
|
+
Enemy1.start();
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
```
|
12
206
|
|
13
207
|
実行時の結果
|
14
208
|
|