無人機動兵器ダンジョン探索ゲーム JAVAベース
ダンジョン出撃後、一定時間にボタンを押さないと自動出撃モードに移行するようにした
@@ -0,0 +1,75 @@ | ||
1 | +package CarnageHack; | |
2 | + | |
3 | +import java.awt.Button; | |
4 | +import java.awt.Dialog; | |
5 | +import java.awt.Window; | |
6 | +import java.util.TimerTask; | |
7 | + | |
8 | +/** | |
9 | + * 自動クローズタスク | |
10 | + * | |
11 | + * @author terry | |
12 | + */ | |
13 | +public class CHtimerAutoClose extends TimerTask { | |
14 | + | |
15 | + Window wnd; | |
16 | + boolean bdone; | |
17 | + long starttime; | |
18 | + long targettime; | |
19 | + Button targetc; | |
20 | + String buttonmesg; | |
21 | + | |
22 | + CHtimerAutoClose(Dialog d) { | |
23 | + wnd = d; | |
24 | + bdone = false; | |
25 | + starttime = System.currentTimeMillis(); | |
26 | + targettime = starttime + 1000; | |
27 | + targetc = null; | |
28 | + } | |
29 | + | |
30 | + CHtimerAutoClose(Window w) { | |
31 | + wnd = w; | |
32 | + bdone = false; | |
33 | + starttime = System.currentTimeMillis(); | |
34 | + targettime = starttime + 1000; | |
35 | + targetc = null; | |
36 | + } | |
37 | + | |
38 | + public void set_timeout(long n) { | |
39 | + starttime = System.currentTimeMillis(); | |
40 | + targettime = starttime + n; | |
41 | + } | |
42 | + | |
43 | + public void set_button(Button b, String s) { | |
44 | + targetc = b; | |
45 | + buttonmesg = s; | |
46 | + } | |
47 | + | |
48 | + @Override | |
49 | + public void run() { | |
50 | + long n = System.currentTimeMillis(); | |
51 | + if (n >= targettime) { | |
52 | + bdone = true; | |
53 | + wnd.dispose(); | |
54 | + } | |
55 | + if (targetc != null) { | |
56 | + StringBuilder str = new StringBuilder(40); | |
57 | + n = (targettime - n) / 1000; | |
58 | + str.append(buttonmesg); | |
59 | + str.append('['); | |
60 | + str.append(n); | |
61 | + str.append(']'); | |
62 | + targetc.setLabel(str.toString()); | |
63 | + targetc.getParent().doLayout(); | |
64 | + } | |
65 | + } | |
66 | + | |
67 | + /** | |
68 | + * 自動タイマーで閉じたか? | |
69 | + * | |
70 | + * @return タイマー処理後ならtrue | |
71 | + */ | |
72 | + public boolean is_done() { | |
73 | + return bdone; | |
74 | + } | |
75 | +} |
@@ -8,6 +8,7 @@ | ||
8 | 8 | import java.security.InvalidAlgorithmParameterException; |
9 | 9 | import java.security.InvalidKeyException; |
10 | 10 | import java.security.NoSuchAlgorithmException; |
11 | +import java.util.Timer; | |
11 | 12 | import java.util.logging.Level; |
12 | 13 | import java.util.logging.Logger; |
13 | 14 | import javax.crypto.Cipher; |
@@ -24,7 +25,7 @@ | ||
24 | 25 | */ |
25 | 26 | public final class CarnageHack extends Panel implements ActionListener { |
26 | 27 | |
27 | - public static final String version = "CarnageHack2 V1.3.2 alpha"; | |
28 | + public static final String version = "CarnageHack2 V1.4.0 alpha"; | |
28 | 29 | public static final ResourceBundle resource; |
29 | 30 | public static CHArrayList main_weapon_list; |
30 | 31 | public static CHArrayList sub_weapon_list; |
@@ -302,6 +303,152 @@ | ||
302 | 303 | } |
303 | 304 | } |
304 | 305 | |
306 | + /** | |
307 | + * ダンジョンへ出撃 | |
308 | + */ | |
309 | + boolean dungeon_go(boolean bauto) { | |
310 | + save_data(); //save data now! :D | |
311 | + collected_parts.clear(); | |
312 | + //process dungeon... | |
313 | + Dialog dialog = new Dialog(frame, resource.getString( | |
314 | + "titleDUNGEON"), true); | |
315 | + Oke myoke = new Oke(Oke.IFF_FRIEND, 1000, hardware, software, | |
316 | + software2); | |
317 | + OkeDungeon dungeon = new OkeDungeon(dialog, myoke); | |
318 | + CarnageHackDialogEvent chevent | |
319 | + = new CarnageHackDialogEvent(dialog, dungeon); | |
320 | + dungeon.start_timer(); | |
321 | + dialog.add(dungeon, BorderLayout.CENTER); | |
322 | + dialog.addWindowListener(chevent); | |
323 | + Button button; | |
324 | + button = new Button(CarnageHack.resource. | |
325 | + getString("buttonDisconnect")); | |
326 | + button.setActionCommand("OK"); | |
327 | + button.addActionListener(chevent); | |
328 | + dialog.add(button, BorderLayout.SOUTH); | |
329 | + dialog.pack(); | |
330 | + dialog.setLocation(dungeonpos); | |
331 | + dialog.setVisible(true); | |
332 | + dialog.getLocation(dungeonpos); | |
333 | + dungeon.close_status(); | |
334 | + //display tombstone or goal screen | |
335 | + Toolkit tk = Toolkit.getDefaultToolkit(); | |
336 | + String mesg; | |
337 | + Image icon; | |
338 | + if (dungeon.get_goalin() == true) { | |
339 | + collect_parts(myoke); | |
340 | + save_data(); //save data again! :D | |
341 | + mesg = resource.getString("RTBmessage"); | |
342 | + if (dungeon.is_havehige() == true) { | |
343 | + mesg += resource.getString("SuccessMessage"); | |
344 | + icon = tk.getImage(getClass(). | |
345 | + getResource("icon/success.png")); | |
346 | + } else { | |
347 | + mesg += resource.getString("FailMessage"); | |
348 | + icon = tk.getImage(getClass(). | |
349 | + getResource("icon/failed.png")); | |
350 | + } | |
351 | + } else { | |
352 | + if (myoke.isdead() == true) { | |
353 | + mesg = resource.getString("DestroyMessage"); | |
354 | + switch (myoke.get_reason()) { | |
355 | + case Oke.DAMAGE_DESTRUCT: | |
356 | + if (myoke.get_attacker() == myoke) { | |
357 | + mesg | |
358 | + += resource.getString( | |
359 | + "ReasonSelfDestruct"); | |
360 | + } else { | |
361 | + mesg += resource.getString( | |
362 | + "ReasonDestruct"); | |
363 | + } | |
364 | + break; | |
365 | + case Oke.DAMAGE_HEAT: | |
366 | + mesg += resource.getString("ReasonHeat"); | |
367 | + break; | |
368 | + case Oke.DAMAGE_FIGHT: | |
369 | + mesg += resource.getString("ReasonFight"); | |
370 | + break; | |
371 | + case Oke.DAMAGE_ASSALUT: | |
372 | + mesg += resource.getString("ReasonAssalut"); | |
373 | + break; | |
374 | + case Oke.DAMAGE_LASER: | |
375 | + mesg += resource.getString("ReasonLaser"); | |
376 | + break; | |
377 | + case Oke.DAMAGE_SHOTGUN: | |
378 | + mesg += resource.getString("ReasonShotgun"); | |
379 | + break; | |
380 | + case Oke.DAMAGE_MISSILE: | |
381 | + mesg += resource.getString("ReasonMissile"); | |
382 | + break; | |
383 | + case Oke.DAMAGE_ROCKET: | |
384 | + mesg += resource.getString("ReasonRocket"); | |
385 | + break; | |
386 | + default: | |
387 | + mesg += resource.getString("ReasonNone"); | |
388 | + break; | |
389 | + } | |
390 | + mesg += resource.getString("DestroyMessage2") | |
391 | + + (myoke.get_floor() + 1) | |
392 | + + resource.getString("DestroyMessage3"); | |
393 | + } else { | |
394 | + mesg = resource.getString("QuitMessage"); | |
395 | + } | |
396 | + icon = tk.getImage(getClass(). | |
397 | + getResource("icon/tombstone.png")); | |
398 | + } | |
399 | + mesg += resource.getString("OkeScoreMessage1") | |
400 | + + myoke.get_destroycount() | |
401 | + + resource.getString("OkeScoreMessage2"); | |
402 | + if (collected_parts.size() > 0) { | |
403 | + mesg += resource.getString("OkeScoreMessage3") | |
404 | + + collected_parts.size() | |
405 | + + resource.getString("OkeScoreMessage4"); | |
406 | + } | |
407 | + mesg += resource.getString("MaximumFloorMessage") | |
408 | + + dungeon.get_maximum_floor() | |
409 | + + resource.getString("MaximumFloorMessage2"); | |
410 | + //ユーザーがボタンを押したら自動実行を解除 | |
411 | + bauto = CHutil.MessageBox(mesg, resource.getString("ReportTitle"), | |
412 | + icon, false, 10000) != true; | |
413 | + if (collected_parts.size() > 0) { | |
414 | + Timer timer = null; | |
415 | + CHtimerAutoClose ttask = null; | |
416 | + Dialog clist | |
417 | + = new Dialog(frame, resource.getString( | |
418 | + "titlePARTS_LIST"), true); | |
419 | + List list = new List(20); | |
420 | + CHmessageboxEvent msgevent = new CHmessageboxEvent(clist); | |
421 | + int i; | |
422 | + for (i = 0; i < collected_parts.size(); i++) { | |
423 | + list.add((String) collected_parts.get(i)); | |
424 | + } | |
425 | + clist.add(list, BorderLayout.CENTER); | |
426 | + clist.addWindowListener(msgevent); | |
427 | + button = new Button( | |
428 | + CarnageHack.resource.getString("buttonOK")); | |
429 | + button.setActionCommand("OK"); | |
430 | + button.addActionListener(msgevent); | |
431 | + clist.add(button, BorderLayout.SOUTH); | |
432 | + clist.setSize(320, 400); | |
433 | + clist.setLocationRelativeTo(frame); | |
434 | + if (bauto == true) { | |
435 | + timer = new Timer(); | |
436 | + ttask = new CHtimerAutoClose(clist); | |
437 | + ttask.set_button(button, button.getLabel()); | |
438 | + ttask.set_timeout(5000); | |
439 | + timer.schedule(ttask, 0, 1000); | |
440 | + } | |
441 | + clist.setVisible(true); | |
442 | + if (timer != null) { | |
443 | + timer.cancel(); | |
444 | + } | |
445 | + if (ttask != null) { | |
446 | + ttask.cancel(); | |
447 | + } | |
448 | + } | |
449 | + return bauto; | |
450 | + } | |
451 | + | |
305 | 452 | public void actionPerformed(ActionEvent e) { |
306 | 453 | String cmd = e.getActionCommand(); |
307 | 454 | if (cmd.equals("SOFTWARE") == true) { |
@@ -350,148 +497,39 @@ | ||
350 | 497 | if (software != null && software.get(0, 0) != null && hardware |
351 | 498 | != null) { |
352 | 499 | //go to dungeon! |
353 | - if (check_oke_parts() == false) { //check used parts | |
354 | - //don't have parts | |
355 | - CHutil.MessageBox(resource.getString("noParts"), | |
356 | - resource.getString("noPartsTitle"), | |
357 | - null, false); | |
358 | - return; | |
359 | - } | |
360 | - if (CHutil.MessageBox(resource.getString("confirmGoTo"), | |
361 | - resource.getString("confirmGoToTitle"), | |
362 | - null, true) == false) { | |
363 | - return; | |
364 | - } | |
365 | - if (update_parts() == false) { | |
366 | - //huh? | |
367 | - CHutil.MessageBox(resource.getString("noParts"), | |
368 | - resource.getString("noPartsTitle"), | |
369 | - null, false); | |
370 | - return; | |
371 | - } | |
372 | - save_data(); //save data now! :D | |
373 | - collected_parts.clear(); | |
374 | - //process dungeon... | |
375 | - Dialog dialog = new Dialog(frame, resource.getString( | |
376 | - "titleDUNGEON"), true); | |
377 | - Oke myoke = new Oke(Oke.IFF_FRIEND, 1000, hardware, software, | |
378 | - software2); | |
379 | - OkeDungeon dungeon = new OkeDungeon(dialog, myoke); | |
380 | - CarnageHackDialogEvent chevent | |
381 | - = new CarnageHackDialogEvent(dialog, dungeon); | |
382 | - dungeon.start_timer(); | |
383 | - dialog.add(dungeon, BorderLayout.CENTER); | |
384 | - dialog.addWindowListener(chevent); | |
385 | - Button button; | |
386 | - button = new Button(CarnageHack.resource. | |
387 | - getString("buttonDisconnect")); | |
388 | - button.setActionCommand("OK"); | |
389 | - button.addActionListener(chevent); | |
390 | - dialog.add(button, BorderLayout.SOUTH); | |
391 | - dialog.pack(); | |
392 | - dialog.setLocation(dungeonpos); | |
393 | - dialog.setVisible(true); | |
394 | - dialog.getLocation(dungeonpos); | |
395 | - dungeon.close_status(); | |
396 | - //display tombstone or goal screen | |
397 | - Toolkit tk = Toolkit.getDefaultToolkit(); | |
398 | - String mesg; | |
399 | - Image icon; | |
400 | - if (dungeon.get_goalin() == true) { | |
401 | - collect_parts(myoke); | |
402 | - save_data(); //save data again! :D | |
403 | - mesg = resource.getString("RTBmessage"); | |
404 | - if (dungeon.is_havehige() == true) { | |
405 | - mesg += resource.getString("SuccessMessage"); | |
406 | - icon = tk.getImage(getClass(). | |
407 | - getResource("icon/success.png")); | |
408 | - } else { | |
409 | - mesg += resource.getString("FailMessage"); | |
410 | - icon = tk.getImage(getClass(). | |
411 | - getResource("icon/failed.png")); | |
500 | + boolean bauto = false; | |
501 | + do { | |
502 | + if (check_oke_parts() == false) { //check used parts | |
503 | + //don't have parts | |
504 | + CHutil.MessageBox(resource.getString("noParts"), | |
505 | + resource.getString("noPartsTitle"), | |
506 | + null, false); | |
507 | + return; | |
412 | 508 | } |
413 | - } else { | |
414 | - if (myoke.isdead() == true) { | |
415 | - mesg = resource.getString("DestroyMessage"); | |
416 | - switch (myoke.get_reason()) { | |
417 | - case Oke.DAMAGE_DESTRUCT: | |
418 | - if (myoke.get_attacker() == myoke) { | |
419 | - mesg | |
420 | - += resource.getString( | |
421 | - "ReasonSelfDestruct"); | |
422 | - } else { | |
423 | - mesg += resource.getString( | |
424 | - "ReasonDestruct"); | |
425 | - } | |
426 | - break; | |
427 | - case Oke.DAMAGE_HEAT: | |
428 | - mesg += resource.getString("ReasonHeat"); | |
429 | - break; | |
430 | - case Oke.DAMAGE_FIGHT: | |
431 | - mesg += resource.getString("ReasonFight"); | |
432 | - break; | |
433 | - case Oke.DAMAGE_ASSALUT: | |
434 | - mesg += resource.getString("ReasonAssalut"); | |
435 | - break; | |
436 | - case Oke.DAMAGE_LASER: | |
437 | - mesg += resource.getString("ReasonLaser"); | |
438 | - break; | |
439 | - case Oke.DAMAGE_SHOTGUN: | |
440 | - mesg += resource.getString("ReasonShotgun"); | |
441 | - break; | |
442 | - case Oke.DAMAGE_MISSILE: | |
443 | - mesg += resource.getString("ReasonMissile"); | |
444 | - break; | |
445 | - case Oke.DAMAGE_ROCKET: | |
446 | - mesg += resource.getString("ReasonRocket"); | |
447 | - break; | |
448 | - default: | |
449 | - mesg += resource.getString("ReasonNone"); | |
450 | - break; | |
509 | + if (bauto == false) { | |
510 | + if (CHutil.MessageBox(resource.getString("confirmGoTo"), | |
511 | + resource.getString("confirmGoToTitle"), | |
512 | + null, true) == false) { | |
513 | + return; | |
451 | 514 | } |
452 | - mesg += resource.getString("DestroyMessage2") | |
453 | - + (myoke.get_floor() + 1) | |
454 | - + resource.getString("DestroyMessage3"); | |
515 | + bauto = true; | |
455 | 516 | } else { |
456 | - mesg = resource.getString("QuitMessage"); | |
517 | + if (CHutil.MessageBox( | |
518 | + resource.getString("confirmAutoGo"), | |
519 | + resource.getString("confirmGoToTitle"), | |
520 | + null, false, 5000) == true) { | |
521 | + return; | |
522 | + } | |
457 | 523 | } |
458 | - icon = tk.getImage(getClass(). | |
459 | - getResource("icon/tombstone.png")); | |
460 | - } | |
461 | - mesg += resource.getString("OkeScoreMessage1") | |
462 | - + myoke.get_destroycount() | |
463 | - + resource.getString("OkeScoreMessage2"); | |
464 | - if (collected_parts.size() > 0) { | |
465 | - mesg += resource.getString("OkeScoreMessage3") | |
466 | - + collected_parts.size() | |
467 | - + resource.getString("OkeScoreMessage4"); | |
468 | - } | |
469 | - mesg += resource.getString("MaximumFloorMessage") | |
470 | - + dungeon.get_maximum_floor() | |
471 | - + resource.getString("MaximumFloorMessage2"); | |
472 | - CHutil.MessageBox(mesg, resource.getString("ReportTitle"), | |
473 | - icon, false); | |
474 | - if (collected_parts.size() > 0) { | |
475 | - Dialog clist | |
476 | - = new Dialog(frame, resource.getString( | |
477 | - "titlePARTS_LIST"), true); | |
478 | - List list = new List(20); | |
479 | - CHmessageboxEvent msgevent = new CHmessageboxEvent(clist); | |
480 | - int i; | |
481 | - for (i = 0; i < collected_parts.size(); i++) { | |
482 | - list.add((String) collected_parts.get(i)); | |
524 | + if (update_parts() == false) { | |
525 | + //huh? | |
526 | + CHutil.MessageBox(resource.getString("noParts"), | |
527 | + resource.getString("noPartsTitle"), | |
528 | + null, false); | |
529 | + return; | |
483 | 530 | } |
484 | - clist.add(list, BorderLayout.CENTER); | |
485 | - clist.addWindowListener(msgevent); | |
486 | - button = new Button( | |
487 | - CarnageHack.resource.getString("buttonOK")); | |
488 | - button.setActionCommand("OK"); | |
489 | - button.addActionListener(msgevent); | |
490 | - clist.add(button, BorderLayout.SOUTH); | |
491 | - clist.setSize(320, 400); | |
492 | - clist.setLocationRelativeTo(frame); | |
493 | - clist.setVisible(true); | |
494 | - } | |
531 | + bauto = dungeon_go(bauto); | |
532 | + } while (bauto); | |
495 | 533 | } else { |
496 | 534 | CHutil.MessageBox(resource.getString("ngGoTo"), |
497 | 535 | resource.getString("ngGoToTitle"), |
@@ -1,6 +1,7 @@ | ||
1 | 1 | package CarnageHack; |
2 | 2 | |
3 | 3 | import java.awt.*; |
4 | +import java.util.Timer; | |
4 | 5 | |
5 | 6 | /** |
6 | 7 | * ツールクラス |
@@ -252,12 +253,16 @@ | ||
252 | 253 | * @param title タイトル |
253 | 254 | * @param icon アイコン |
254 | 255 | * @param ask trueの時にYES/NO表示、falseの時にOKのみ |
256 | + * @param autotimeout 自動タイムアウト値 0のときに無制限 | |
255 | 257 | * @return OKもしくはYESが押されるとtrue |
256 | 258 | */ |
257 | 259 | public static boolean MessageBox(String message, String title, Image icon, |
258 | - boolean ask) { | |
260 | + boolean ask, long autotimeout) { | |
259 | 261 | Dialog dialog = new Dialog(CarnageHack.getFrame(), title, true); |
260 | 262 | CHmessageboxEvent msgevent = new CHmessageboxEvent(dialog); |
263 | + CHtimerAutoClose closeevent = null; | |
264 | + Button okbutton; | |
265 | + Timer autotimer = null; | |
261 | 266 | if (icon == null) { |
262 | 267 | icon = defaultIcon; |
263 | 268 | } |
@@ -271,6 +276,7 @@ | ||
271 | 276 | button.setActionCommand("OK"); |
272 | 277 | button.addActionListener(msgevent); |
273 | 278 | panel.add(button); |
279 | + okbutton = button; | |
274 | 280 | button = new Button(CarnageHack.resource.getString("buttonNO")); |
275 | 281 | button.setActionCommand("CANCEL"); |
276 | 282 | button.addActionListener(msgevent); |
@@ -283,9 +289,17 @@ | ||
283 | 289 | button.setActionCommand("OK"); |
284 | 290 | button.addActionListener(msgevent); |
285 | 291 | panel.add(button); |
292 | + okbutton = button; | |
286 | 293 | dialog.add(panel, BorderLayout.SOUTH); |
287 | 294 | } |
288 | 295 | dialog.pack(); |
296 | + if (autotimeout > 0) { | |
297 | + closeevent = new CHtimerAutoClose(dialog); | |
298 | + closeevent.set_timeout(autotimeout); | |
299 | + closeevent.set_button(okbutton, okbutton.getLabel()); | |
300 | + autotimer = new Timer(); | |
301 | + autotimer.schedule(closeevent, 0, 1000); | |
302 | + } | |
289 | 303 | Toolkit tk = Toolkit.getDefaultToolkit(); |
290 | 304 | Dimension sz = dialog.getSize(); |
291 | 305 | Dimension scsz = tk.getScreenSize(); |
@@ -292,10 +306,30 @@ | ||
292 | 306 | dialog.setLocation((scsz.width - sz.width) / 2, |
293 | 307 | (scsz.height - sz.height) / 2); |
294 | 308 | dialog.setVisible(true); |
309 | + if (autotimer != null) { | |
310 | + autotimer.cancel(); | |
311 | + } | |
312 | + if (closeevent != null) { | |
313 | + closeevent.cancel(); | |
314 | + } | |
295 | 315 | return msgevent.isok(); |
296 | 316 | } |
297 | 317 | |
298 | 318 | /** |
319 | + * メッセージボックス表示 | |
320 | + * | |
321 | + * @param message 表示メッセージ | |
322 | + * @param title タイトル | |
323 | + * @param icon アイコン | |
324 | + * @param ask trueの時にYES/NO表示、falseの時にOKのみ | |
325 | + * @return OKもしくはYESが押されるとtrue | |
326 | + */ | |
327 | + public static boolean MessageBox(String message, String title, Image icon, | |
328 | + boolean ask) { | |
329 | + return MessageBox(message, title, icon, ask, 0); | |
330 | + } | |
331 | + | |
332 | + /** | |
299 | 333 | * 文字列入力ボックスの表示 |
300 | 334 | * |
301 | 335 | * @param message ガイダンス表示 |