我的家庭作业是,如果需要更多的上下文-我会解释它,但它是相当长的解释,如果人们需要查看,网站上提供了文本文件:http://www.cis.upenn.edu/~cis110/hw/hw06/index.html
现在我在第二步,从与宝藏类相关的三个项目中随机选择,检查它们是否以"tc“开头。我可以从monster.txt文件中提取宝藏类,然后我就得到了怪物。这是我查找宝藏类的方法:
public static void getTreasureClass(Monster monGet)
throws FileNotFoundException{
Random rand = new Random();
String tc=monGet.getTreasureClass();
Scanner file=new Scanner(new File ("TreasureClassEx.txt"));
System.out.println(tc);
while(!file.next().equals(tc)){
file.next();
}
tc=file.next();
if (tc.startsWith("tc:")){
}
else {
System.out.println("test");
}
}它非常不完整,但是如果我的代码不好,或者我的代码不好,我将非常感谢一些关于从这三个项目中随机选择下一步的技巧。提前感谢!
发布于 2011-11-07 09:22:54
所以“Hell_Bovine”有一个"tc:Cow_(H)“的珍宝类。
所以您要在TreasureClassEx.txt中查找这一行
tc:Cow_(H) tc:Act_5_(H)_Equip_B tc:armo3 tc:armo3然后,您将从三个选项中随机选择一个。
您将继续阅读TreasureClassEx,找到正确的行,并进行随机选择,直到您要查找的“宝藏类”以"tc:“开头。
例如,对于"tc:Cow_(H)“,您可以选择"tc:armo3”。对于"tc:armo3",您可以选择"Quilted_Armor“。然后你就会停在这里。
至少这就是我正在读指令的方式。I‘m’s the instructions。;->
发布于 2011-11-07 06:21:14
确保您导入我添加的内容,因为您不显示导入我不会添加它们
public static void getTreasureClass(Monster monGet)
throws FileNotFoundException{
Random rand = new Random();
String tc=monGet.getTreasureClass();
Scanner file=new Scanner(new File ("TreasureClassEx.txt"));
System.out.println(tc);
List<String> list = new LinkedList<String>();
while(!file.next().equals(tc)){
file.next();
}
tc=file.next();
if (tc.startsWith("tc:")){
list.add(tc);
}
String treasure = list.get(rand.nextInt(list.size()));
else {
System.out.println("test");
}
}所以在这里我将这个例子保存在字符串值‘宝藏’中。
我觉得帮你做作业很不舒服--
https://stackoverflow.com/questions/8030751
复制相似问题