【发布时间】:2012-10-18 04:54:31
【问题描述】:
我已经开始用 Java 编写一个类似于武器商店的游戏。我试图让用户能够在控制台中选择打印在 HashMap 中的项目。一旦用户选择并突出显示该项目,用户就会购买该项目。是否有内置的实用程序 Java 支持这一点?这是我所拥有的:
public static int purchaseMedicine(int goldAmount) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
map.put("Jewel of Open", 500);
map.put("Potion", 800);
map.put("Hi-Potion", 2000);
map.put("Elixir", 8000);
map.put("Manna Prism", 4000);
map.put("Antivenom", 200);
map.put("Hammer", 200);
map.put("Library Card", 500);
int index = 0;
for(Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
System.out.printf("\n\tGold %d\n\n", goldAmount);
return index; // Returns the instances of medicineList
}
【问题讨论】:
标签: java console highlighting