此代码由于某种原因无法运行。
这是一款简单的RPG游戏。
`
import 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类还没有完成。
答案 0 :(得分:1)
main方法必须位于公共类中,以便可以从“outside”访问它。见这里:What if main method is inside "non public class" of java file?
请注意,每个文件只能有一个公共类。