我正在编写一个 Java 程序,它使用 XML 文件作为模板来填充数据结构,然后程序接受用户输入并与之交互。
我想要的是保持这种层次结构的东西:
<CYO>
<node>
<to>
home
</to>
<message>
This is the message that will be displayed to the user.
</message>
<option>
<name>
fun <!-- option that is dispalyed and command to be entered -->
</name>
<goto>
not home <!-- next node to be displayed for this command -->
</goto>
</option>
<option>
<name>
no fun
</name>
<goto>
home <!-- should trigger the reprinting of the same message; goto/home = to/home -->
</goto>
</option>
</node>
<node>
<to>
not home
</to>
<message>
Welcome you have just left home.
What else do you want to do?
</message>
<option>
<name>
back home
</name>
<goto>
home
</goto>
</option>
<option>
<name>
fun
</name>
<goto>
not home <!-- should trigger the reprinting of the same message; goto/not home = to/not home -->
</goto>
</option>
</node>
</CYO>
在Java中,我一直试图对如何从'option/name::goto'调用节点项的逻辑进行排序,然后让程序返回与'option/name::goto'匹配的'node/to' '。真正的问题是我不确定这需要如何在 Java 中表示,以便正确返回这样的调用。这是我到目前为止所做的是Java:
List<Map<String, Object<String, String>>> CYO = new ArrayList();
Map<String, Object> home = new HashMap<String, Object>();
home.put("to", "home");
home.put("message", "This is the message that will be displayed to the user.");
Map<String, String> Option1 = new HashMap<String, String>();
Option1.put("fun", "not home");
Option1.put("no fun", "home");
home.put("option", Option1);
Map<String, Object> not_home = new HashMap<String, Object>();
not_home.put("to", "not home");
not_home.put("message", "Welcome you have just left home.\\nWhat else do you want to do?");
not_home.put("option", "not home");
Map<String, String> Option2 = new HashMap<String, String>();
Option2.put("back home", "home");
Option2.put("fun", "not_home");
not_home.put("option", Option2);
我从 IDE 收到一条错误消息:“类型 Object 不是通用的;它不能用 arguments 参数化。
拉风的咖菲猫
相关分类