ensj
ensj

Reputation: 33

Java Simple RPG game(does not run)

This code does not run for some reason. This is a simple RPG game. `
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 {

        }

    }

` Even though i have the public static void main, the code cannot run. Is there a problem? Also, the array and the class Grasslands arent finished yet.

Upvotes: 2

Views: 724

Answers (1)

Kon
Kon

Reputation: 10810

The main method must be inside a public class so that it can be accessed from "outside". See here: What if main method is inside "non public class" of java file?

Note that there can only be one public class per file.

Upvotes: 1

Related Questions