{"id":192,"date":"2025-11-06T15:25:06","date_gmt":"2025-11-06T06:25:06","guid":{"rendered":"https:\/\/java.satoshis.jp\/?p=192"},"modified":"2025-11-06T15:26:36","modified_gmt":"2025-11-06T06:26:36","slug":"%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e6%8c%87%e5%90%91%e3%81%a7rpg%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b-%e6%ad%a6%e5%99%a8%e3%81%ae%e7%a8%ae%e9%a1%9e%e3%82%92","status":"publish","type":"post","link":"https:\/\/java.satoshis.jp\/?p=192","title":{"rendered":"\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u3067RPG\u3092\u4f5c\u3063\u3066\u307f\u308b &#8211; \u6b66\u5668\u306e\u7a2e\u985e\u3092\u5897\u3084\u3059"},"content":{"rendered":"<p>\u73fe\u72b6\u3067\u306f\u300c\u3072\u306e\u304d\u306e\u68d2\u300d\u3057\u304b\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u3082\u3063\u3068\u5f37\u3044\u6b66\u5668\u3082\u6b32\u3057\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>\u6b66\u5668\u306e\u7a2e\u985e\u3092\u5897\u3084\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u6b66\u5668\u3092\u62fe\u3046\u3068\u3053\u308d\u3067\u8907\u6570\u306e\u7a2e\u985e\u306b\u5bfe\u5fdc\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>Rpg.java<\/p>\n<pre class=\"brush: java; highlight: [26,27,28,29]; title: ; notranslate\" title=\"\">\r\npackage rpg.model;\r\nimport rpg.model.arms.Arms;\r\nimport rpg.model.arms.ArmsCreator;\r\nimport rpg.model.item.Item;\r\nimport rpg.model.item.ItemCreator;\r\nimport rpg.model.monster.Monster;\r\nimport rpg.model.monster.MonsterCreator;\r\n\r\npublic class Rpg {\r\n  private Brave brave;\r\n  public Rpg() {\r\n    brave = new Brave();\r\n    brave.setName(&quot;\u30e8\u30b7\u30d2\u30b3&quot;);\r\n  }\r\n  public Brave getBrave() {\r\n    return brave;\r\n  }\r\n  public Monster getMonster() {\r\n    MonsterCreator mc = new MonsterCreator();\r\n    return mc.createMonster();\r\n  }\r\n  public Item getItem() {\r\n    ItemCreator ic = new ItemCreator();\r\n    return ic.createItem();\r\n  }\r\n  public Arms getArms() {\r\n    ArmsCreator ac = new ArmsCreator();\r\n    return ac.createArms();\r\n  }\r\n}\r\n<\/pre>\n<p>ArmsCreator\u30af\u30e9\u30b9\u3067\u6b66\u5668\u3092\u751f\u6210\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage rpg.model.arms;\r\n\r\npublic class ArmsCreator {\r\n  public Arms createArms() {\r\n    double v = Math.random();\r\n    Arms arms = null;\r\n    if (v &lt; 0.5) {\r\n      arms = new HinokiRod();\r\n    } else {\r\n      arms = new BambooPole();\r\n    }\r\n    return arms;\r\n  }\r\n}\r\n<\/pre>\n<p>\u305f\u3051\u3056\u304a\u306b\u5bfe\u5fdc\u3059\u308bBambooPole\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage rpg.model.arms;\r\n\r\n  public BambooPole() {\r\n    super(&quot;\u305f\u3051\u3056\u304a&quot;);\r\n  }\r\n  public int getRatio() {\r\n    return 3;\r\n  }\r\n}\r\n<\/pre>\n<p>\u88c5\u5099\u30dc\u30bf\u30f3\u3067\u8d77\u52d5\u3055\u308c\u308bArmsAction\u3067\u306f\u3001\u52c7\u8005\u304c\u6301\u3063\u3066\u3044\u308b\u6b66\u5668\u306e\u4e2d\u304b\u3089\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u3053\u308c\u306fItemAction\u306b\u4f3c\u305f\u3088\u3046\u306b\u5b9f\u88c5\u3059\u308c\u3070\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage rpg.contoller;\r\n\r\nimport java.awt.event.ActionEvent;\r\nimport java.awt.event.ActionListener;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\nimport javax.swing.JOptionPane;\r\n\r\nimport rpg.model.Brave;\r\nimport rpg.model.arms.Arms;\r\nimport rpg.view.BattleFrame;\r\n\r\npublic class ArmsAction implements ActionListener {\r\n  private BattleFrame battleFrame;\r\n  public ArmsAction(BattleFrame bf) {\r\n    battleFrame = bf;\r\n  }\r\n  @Override\r\n  public void actionPerformed(ActionEvent e) {\r\n    System.out.println(&quot;\u88c5\u5099&quot;);\r\n    Brave brave = battleFrame.getBrave();\r\n    List&lt;Arms&gt; list = brave.getArmses();\r\n    if (list.size() == 0) {\r\n      \/\/ \u88c5\u5099\u3092\u6301\u3063\u3066\u306a\u3044\r\n      JOptionPane.showMessageDialog(battleFrame, &quot;\u88c5\u5099\u3092\u6301\u3063\u3066\u307e\u305b\u3093&quot;);\r\n      return;\r\n    }\r\n    Object&#x5B;] armses = createArmsArray();\r\n    Object armsName = JOptionPane.showInputDialog(\r\n      battleFrame, \r\n      &quot;\u88c5\u5099\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044&quot;, \r\n      &quot;\u88c5\u5099&quot;,\r\n      JOptionPane.PLAIN_MESSAGE, \r\n      null, \r\n      armses,\r\n      armses&#x5B;0]);\r\n    if (armsName == null) return;\r\n    if (armsName.equals(armses&#x5B;0])) {\r\n      brave.setArms(null);\r\n    } else {\r\n      Arms arms = brave.getArms((String)armsName);\r\n      brave.setArms(arms);\r\n      String msg = brave.getName() + &quot;\u306f\u3001&quot;\r\n                 + arms.getName() + &quot;\u3092\u88c5\u5099\u3057\u305f\u3002&quot;;\r\n      JOptionPane.showMessageDialog(battleFrame,\r\n      msg,\r\n      &quot;\u88c5\u5099&quot;,\r\n      JOptionPane.INFORMATION_MESSAGE);\r\n    }\r\n  }\r\n  private Object&#x5B;] createArmsArray() {\r\n    Brave brave = battleFrame.getBrave();\r\n    List&lt;Arms&gt; armses = brave.getArmses();\r\n    List&lt;String&gt; list = new ArrayList&lt;&gt;();\r\n    list.add(&quot;\u88c5\u5099\u306a\u3057&quot;);\r\n    for (Arms arms : armses) {\r\n      if (!list.contains(arms.getName())) {\r\n        list.add(arms.getName());\r\n      }\r\n    }\r\n    return list.toArray();\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u72b6\u3067\u306f\u300c\u3072\u306e\u304d\u306e\u68d2\u300d\u3057\u304b\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u3082\u3063\u3068\u5f37\u3044\u6b66\u5668\u3082\u6b32\u3057\u3044\u3068\u3053\u308d\u3067\u3059\u3002 \u6b66\u5668\u306e\u7a2e\u985e\u3092\u5897\u3084\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002 \u307e\u305a\u306f\u6b66\u5668\u3092\u62fe\u3046\u3068\u3053\u308d\u3067\u8907\u6570\u306e\u7a2e\u985e\u306b\u5bfe\u5fdc\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002 Rpg.java package &#8230; <\/p>\n","protected":false},"author":1,"featured_media":11,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[11,17,21,22],"class_list":["post-192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java","tag-rpg","tag-21","tag-22"],"_links":{"self":[{"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=192"}],"version-history":[{"count":3,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions\/195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=\/wp\/v2\/media\/11"}],"wp:attachment":[{"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}