【发布时间】:2013-07-27 13:04:50
【问题描述】:
此代码由于某种原因无法运行。
这是一款简单的角色扮演游戏。
`
导入 java.util.Scanner;
public class My_first_RPG {
double exp;
double attack;
double vitality;
double armor;
double mana;
int skill() {
return (int) (attack*mana);
}
}
class character {
public static void main(String args[])
throws java.io.IOException {
My_first_RPG Mage = new My_first_RPG();
My_first_RPG Warrior = new My_first_RPG();
My_first_RPG Archer = new My_first_RPG();
My_first_RPG Dwarven_Mech = new My_first_RPG();
My_first_RPG Steel_Golem = new My_first_RPG();
int world[][] = new int[10][10];
world[1][1]=2;
Mage.attack = 75;
Mage.vitality = 1;
Mage.armor = 10;
Mage.mana = 200;
Warrior.attack = 100;
Warrior.vitality = 2;
Warrior.armor = 20;
Warrior.mana = 100;
Archer.attack = 65;
Archer.vitality = 1;
Archer.armor = 15;
Archer.mana = 150;
Dwarven_Mech.attack = 125;
Dwarven_Mech.vitality = 0.5;
Dwarven_Mech.armor = 5;
Dwarven_Mech.mana = 75;
Steel_Golem.attack = 50;
Steel_Golem.vitality = 0;
Steel_Golem.armor = 30;
Steel_Golem.mana = 50;
System.out.println("Choose your Hero.");
System.out.println("1. Mage");
System.out.println("2. Warrior");
System.out.println("3. Archer");
System.out.println("4. Dwarven Mech");
System.out.println("5. Steel Golem");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
switch(choice) {
case 1:
System.out.println("You are now a Mage.");
case 2:
System.out.println("You are now a Warrior.");
case 3:
System.out.println("You are now a Archer.");
case 4:
System.out.println("You are now a Dwarven Mech.");
case 5:
System.out.println("You are now a Steel Golem.");
}
}
class Grasslands {
}
}
` 即使我有 public static void main,代码也无法运行。 有问题吗?另外,数组和Grasslands类还没有完成。
【问题讨论】:
-
“代码无法运行”是什么意思。它是尝试运行但遇到错误,还是以没有 IO 结束,或者您的 IDE 有问题? (请注意,您的 main 方法捕获 IOExceptions;如果存在 IOException,则 main 方法将退出而不显示错误消息。这很可能是您的问题。为什么在整个程序生命周期中都捕获该异常?为什么不验证用户输入?)
-
你使用什么命令来启动你的应用程序?
标签: java