gpt4 book ai didi

Java简单RPG游戏(不运行)

转载 作者:行者123 更新时间:2023-11-30 11:30:14 25 4
gpt4 key购买 nike

这段代码由于某种原因没有运行。这是一款简单的角色扮演游戏。`
导入 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 尚未完成。

最佳答案

main 方法必须在公共(public)类中,以便可以从“外部”访问它。看这里:What if main method is inside "non public class" of java file?

请注意,每个文件只能有一个公共(public)类。

关于Java简单RPG游戏(不运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17895271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com