Results 1 to 10 of 10
  1. #1
    MastaChief11 is offline Member
    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0

    Default Text RPG Problem

    So, I'm making a Mini RPG (just with text) and what I'm wondering is, at the beginning of the game, it asks what type of class you want to be, Mage, Samurai, and Knight. I want the program to remember the class you picked, and to save aspects of a certain class to that class. So if you want to be a Mage, it will save the attributes of the Mage class, and remember the class that you are. This is my code:

    Java Code:
    
    import java.util.Scanner;
    public class adventure {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		//str = strength
    		//def = defense
    		//mmagic = defense
    		
    		int character;
    		Scanner input = new Scanner (System.in);
    		
    		//Mage attributes
    		int m_str = 10;
    		int m_def = 15;
    		int m_magic = 30;
    		int m_speed = 27;
    		int m_health = 95;
    		
    		//Samurai attributes
    		int s_str = 33;
    		int s_def = 20;
    		int s_magic = 5;
    		int s_speed = 20;
    		int s_health = 85;
    		
    		//Knight attributes
    		int k_str = 40;
    		int k_def = 20;
    		int k_magic = 2;
    		int k_speed = 15;
    		int k_health = 70;
    		
    		System.out.println("Hello, and welcome to Craig's Mini RPG. \nPre-alpha 0.1 \nPlease pick a class: \n \n<1> Mage: \n \nStrength: " + m_str + "\nDefense: " + m_def + "\nMagic: " + m_magic + "\nSpeed: " + m_speed + "\nHealth: " + m_health + "\n \n<2> Samurai: \n \nStrength: " + s_str + "\nDefense: " + s_def + "\nMagic: " + s_magic + "\nSpeed: " + s_speed + "\nHealth: " + s_health + "\n \n<3> Knight: \n \nStrength: " + k_str + "\nDefense: " + k_def + "\nMagic: " + k_magic + "\nSpeed: " + k_speed + "\nHealth: " + k_health);
    		character = input.nextInt();
    		
    		if(character == 1){
    			
    		}
    
    	}
    
    }
    Last edited by MastaChief11; 08-04-2012 at 07:36 PM.

  2. #2
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: Text RPG Problem

    What is your question?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  3. #3
    MastaChief11 is offline Member
    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0

    Default Re: Text RPG Problem

    Quote Originally Posted by awinston View Post
    What is your question?
    I want to know how to do this:

    "I want the program to remember the class you picked, and to save aspects of a certain class to that class. So if you want to be a Mage, it will save the attributes of the Mage class, and remember the class that you are." The same goes for the others too.
    Last edited by MastaChief11; 08-04-2012 at 07:43 PM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: Text RPG Problem

    Programs typically remember things by saving some data in a collection. For example a String in an ArrayList.
    Decide what you want to save, perhaps define a class to contain the data and decide where you want to save that class so you can retrieve it later.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Text RPG Problem

    Your program is limited right now because it is nothing more than a single static main method. If you want to create something as complex as an adventure game, even a simple adventure game, you might as well leverage Java to its strengths -- by creating object-oriented valid classes and having them interact. I suggest advancing through the tutorials and read up on how to create and use classes first.

  6. #6
    MastaChief11 is offline Member
    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0

    Default Re: Text RPG Problem

    Quote Originally Posted by Fubarable View Post
    Your program is limited right now because it is nothing more than a single static main method. If you want to create something as complex as an adventure game, even a simple adventure game, you might as well leverage Java to its strengths -- by creating object-oriented valid classes and having them interact. I suggest advancing through the tutorials and read up on how to create and use classes first.
    I'll do that then, because I don't know how to create object-oriented valid classes.

  7. #7
    MastaChief11 is offline Member
    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0

    Default Re: Text RPG Problem

    (Sorry for double-posting)

    I have an idea for the program where, depending on the class you pick, it would change the str, def, magic, etc integers at the top to the values of the class you picked. However,, I don't know how to change an integer's value when something happens.

    Java Code:
    
    import java.util.Scanner;
    public class adventure {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		//str = strength
    		//def = defense
    		//mmagic = defense
    		
    		int character;
    		Scanner input = new Scanner (System.in);
    		
    		int str = 1;
    		int def = 2;
    		int magic = 3;
    		int speed = 4;
    		int health = 5;
    		
    		//Mage attributes
    		int m_str = 10;
    		int m_def = 15;
    		int m_magic = 30;
    		int m_speed = 27;
    		int m_health = 95;
    		
    		//Samurai attributes
    		int s_str = 33;
    		int s_def = 20;
    		int s_magic = 5;
    		int s_speed = 20;
    		int s_health = 85;
    		
    		//Knight attributes
    		int k_str = 40;
    		int k_def = 20;
    		int k_magic = 2;
    		int k_speed = 15;
    		int k_health = 70;
    		
    		System.out.println("Hello, and welcome to Craig's Mini RPG. \nPre-alpha 0.1 \nPlease pick a class: \n \n<1> Mage: \n \nStrength: " + m_str + "\nDefense: " + m_def + "\nMagic: " + m_magic + "\nSpeed: " + m_speed + "\nHealth: " + m_health + "\n \n<2> Samurai: \n \nStrength: " + s_str + "\nDefense: " + s_def + "\nMagic: " + s_magic + "\nSpeed: " + s_speed + "\nHealth: " + s_health + "\n \n<3> Knight: \n \nStrength: " + k_str + "\nDefense: " + k_def + "\nMagic: " + k_magic + "\nSpeed: " + k_speed + "\nHealth: " + k_health);
    		character = input.nextInt();
    		
    		if(character == 1){
    			System.out.println("You have chosen the Mage class. ");
    		}
    
    	}
    
    }

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: Text RPG Problem

    how to change an integer's value when something happens.
    Use an assignment statement to change a variable's value.
    How do you define "something happens"? If a variable's value is changed, save the old value and use an if statement to detect that change.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    MastaChief11 is offline Member
    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0

    Default Re: Text RPG Problem

    How do I use an assignment statement? I haven't done that yet.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: Text RPG Problem

    How do I use an assignment statement? I haven't done that yet.
    You have. Your posted code is full of them. They use the = operator to "assign" a value to a variable. An example:
    int k_health = 70; // assign the value 70 to the variable: k_health
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Gui text problem
    By Arr in forum AWT / Swing
    Replies: 11
    Last Post: 04-27-2012, 06:56 PM
  2. Simple Text Problem
    By shodai in forum Java Applets
    Replies: 5
    Last Post: 04-25-2012, 12:09 AM
  3. problem in spliting a text
    By vipinvijay in forum New To Java
    Replies: 3
    Last Post: 01-10-2011, 10:09 PM
  4. Problem With Text Fields!
    By freshoreo in forum AWT / Swing
    Replies: 3
    Last Post: 08-04-2008, 09:52 PM
  5. Text Area problem
    By mcal in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •