質問編集履歴
1
かなり失礼な内でしたので修正させていただきました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,29 +38,365 @@
|
|
38
38
|
|
39
39
|
### 該当のソースコード
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
```ここに言語を入力
|
42
|
+
|
43
|
+
User.Java
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
import java.util.ArrayList;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public class User extends Human {
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
protected ArrayList<Integer> cards = new ArrayList<Integer>();
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
public void setCards(ArrayList<Integer> drawCard) {
|
60
|
+
|
61
|
+
for(int i= 0;i<drawCard.size();i++){
|
62
|
+
|
63
|
+
myCards.add(drawCard.get(i));
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
public int open() {
|
72
|
+
|
73
|
+
int total = 0;
|
74
|
+
|
75
|
+
for(int i =0; i<=myCards.size(); i++) {
|
76
|
+
|
77
|
+
if(10 <= myCards.get(i)) {
|
78
|
+
|
79
|
+
total += 10;
|
80
|
+
|
81
|
+
}else {
|
82
|
+
|
83
|
+
total += myCards.get(i);
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
return total;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public boolean checkSum() {
|
96
|
+
|
97
|
+
if (open() < 17) {
|
98
|
+
|
99
|
+
return true;
|
100
|
+
|
101
|
+
}else{
|
102
|
+
|
103
|
+
return false;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
```ここに言語を入力
|
118
|
+
|
119
|
+
Human.Java
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
import java.util.ArrayList;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
public abstract class Human {
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
protected ArrayList<Integer> myCards = new ArrayList<Integer>();
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
abstract public int open();
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
abstract public void setCards(ArrayList <Integer> drawCard);
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
abstract public boolean checkSum();
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
Dealer.Java
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
import java.util.ArrayList;
|
162
|
+
|
163
|
+
import java.util.Collections;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
public class Dealer extends Human {
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
protected ArrayList <Integer> cards = new ArrayList<Integer>();
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
public Dealer() {
|
178
|
+
|
179
|
+
for(int n=1; n<=4; n++) {
|
180
|
+
|
181
|
+
for(int i=1; i<=13; i++) {
|
182
|
+
|
183
|
+
cards.add(i);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
Collections.shuffle(cards);
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
public ArrayList<Integer> deal(){
|
196
|
+
|
197
|
+
ArrayList<Integer> setCards = new ArrayList<Integer>();
|
198
|
+
|
199
|
+
setCards.add(cards.get(0));
|
200
|
+
|
201
|
+
setCards.add(cards.get(1));
|
202
|
+
|
203
|
+
cards.remove(0);
|
204
|
+
|
205
|
+
cards.remove(0);
|
206
|
+
|
207
|
+
return setCards;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
public void setCards(ArrayList<Integer> drawCard) {
|
214
|
+
|
215
|
+
for(int i= 0; i<drawCard.size(); i++){
|
216
|
+
|
217
|
+
myCards.add(drawCard.get(i));
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
public int open() {
|
226
|
+
|
227
|
+
int total = 0;
|
228
|
+
|
229
|
+
for(int i=0; i<=myCards.size(); i++) {
|
230
|
+
|
231
|
+
if(0<= myCards.get(i)) {
|
232
|
+
|
233
|
+
total += 10;
|
234
|
+
|
235
|
+
}else {
|
236
|
+
|
237
|
+
total += myCards.get(i);
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
return total;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
public ArrayList<Integer> hit(){
|
252
|
+
|
253
|
+
ArrayList<Integer>setCards = new ArrayList<Integer>();
|
254
|
+
|
255
|
+
setCards.add(cards.get(0));
|
256
|
+
|
257
|
+
cards.remove(0);
|
258
|
+
|
259
|
+
return cards;
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
public boolean checkSum() {
|
264
|
+
|
265
|
+
if (open() < 17 ) {
|
266
|
+
|
267
|
+
return true;
|
268
|
+
|
269
|
+
}else{
|
270
|
+
|
271
|
+
return false;
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
```ここに言語を入力
|
286
|
+
|
287
|
+
BlackJack.Java
|
288
|
+
|
289
|
+
public class Blackjack {
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
public static void main(String[]args) {
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
Dealer dealer = new Dealer();
|
298
|
+
|
299
|
+
User user = new User();
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
System.out.println("ブラックジャックをこれから始めます!!");
|
304
|
+
|
305
|
+
System.out.println("カードを配りますね");
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
dealer.setCards(dealer.deal());
|
310
|
+
|
311
|
+
user.setCards(dealer.deal());
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
dealer.checkSum();
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
while (dealer.checkSum() == true) {
|
320
|
+
|
321
|
+
dealer.hit();
|
322
|
+
|
323
|
+
dealer.setCards(dealer.myCards);
|
324
|
+
|
325
|
+
break;
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
System.out.println("ディーラーの手札はこちらです‼!");
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
while (user.checkSum() == true) {
|
336
|
+
|
337
|
+
dealer.hit();
|
338
|
+
|
339
|
+
dealer.setCards(dealer.myCards);
|
340
|
+
|
341
|
+
break;
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
System.out.println("あなたの手札はこちらです‼");
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
user.checkSum();
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
System.out.println("ディーラーは"+ dealer.myCards);
|
356
|
+
|
357
|
+
System.out.println(dealer.open());
|
358
|
+
|
359
|
+
System.out.println("あなたは"+ user.myCards);
|
360
|
+
|
361
|
+
System.out.println(user.open());
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
if(user.open() == 21) {
|
366
|
+
|
367
|
+
System.out.println("ブラックジャック!あなたの勝ち");
|
368
|
+
|
369
|
+
}else if(user.open() < 21 && dealer.open()<user.open() || dealer.open()>21){
|
370
|
+
|
371
|
+
System.out.println("あなたの勝ち");
|
372
|
+
|
373
|
+
}else if(user.open() > 21){
|
374
|
+
|
375
|
+
System.out.println("バースト!あなたの負け");
|
376
|
+
|
377
|
+
}else if(dealer.open() ==21 || dealer.open() <=21 && user.open()<dealer.open()){
|
378
|
+
|
379
|
+
System.out.println("あなたの負け");
|
380
|
+
|
381
|
+
}else if(user.open() == dealer.open() || user.open()>21 && dealer.open()>21){
|
382
|
+
|
383
|
+
System.out.println("引き分け");
|
384
|
+
|
385
|
+
}
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
```
|
58
394
|
|
59
395
|
### 試したこと
|
60
396
|
|
61
397
|
|
62
398
|
|
63
|
-
|
399
|
+
エラーコードから配列内の数字を変更しましたが解決しませんでした。
|
64
400
|
|
65
401
|
|
66
402
|
|