Results 1 to 7 of 7
  1. #1
    CecoI is offline Member
    Join Date
    Jun 2014
    Posts
    10
    Rep Power
    0

    Default A little help needed building a small RPG

    Hi, i'm totally new to Java. I'm still learning and i need help with a little test project i'm working on. I'm making a small text based RPG and this is what i've come up for now.

    Java Code:
    import java.util.Scanner;
    
    class Main {
    public static void main(String args[]){
    
    Scanner input = new Scanner(System.in);
    Player playerObject = new Player();
    
    System.out.println("Welcome to the world of ??????!\n\nWhat is your name adventurer?");
    String name = input.nextLine();
    playerObject.playerName(name);
    
    System.out.println("\nHow old are you?\n");
    String age = input.nextLine();
    playerObject.playerAge(age);
    
    System.out.println("\n\nWhat is your race " + name + " Caucasian, Mongoloid, Australoid, Negroid, Capoid?");
    }
    }
    
    
    public class Player {
    
    public void playerName(String name){
    
    System.out.println("Your name is " + name + ".");
    }
    
    public void playerAge(String age){
    
    int userage = Integer.parseInt(age);
    System.out.println("You are " + userage + (userage == 1 ? " year old, weird..." : " years old."));
    }
    
    public void playerRace(String race){
    
    
    }
    }

    My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it? I tried like 'int Mongoloid = 1; int Caucasian = 2;' and the same with the others, and after that i tried to use them with the Switch Statement but it did not work. Can please somebody help me?
    Last edited by JosAH; 12-19-2014 at 07:27 PM.

  2. #2
    romero4742 is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Default Re: A little help needed building a small RPG

    not sure if this is what you mean but are you looking for a way to store attributes inside of a class object? for example store the "race" of a player inside the player class. If so then look into class members

  3. #3
    CecoI is offline Member
    Join Date
    Jun 2014
    Posts
    10
    Rep Power
    0

    Default Re: A little help needed building a small RPG

    I'll look it up. My goal is the race that the user types in to get saved in/into something in that class, so i can use it later in development.

  4. #4
    romero4742 is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Default Re: A little help needed building a small RPG

    Quote Originally Posted by CecoI View Post
    I'll look it up. My goal is the race that the user types in to get saved in/into something in that class, so i can use it later in development.
    This should definitely be it then. Good luck

  5. #5
    CecoI is offline Member
    Join Date
    Jun 2014
    Posts
    10
    Rep Power
    0

    Default Re: A little help needed building a small RPG

    I don't get it, i can't think of how to use the Scanner input (the player race) when written to execute a command and automatically save itself in something even by reading the article. I need some more help.
    Last edited by CecoI; 12-18-2014 at 11:11 PM.

  6. #6
    CecoI is offline Member
    Join Date
    Jun 2014
    Posts
    10
    Rep Power
    0

    Default Re: A little help needed building a small RPG

    Nevermind, i got it. Not exactly what i wanted but i did something.
    Last edited by CecoI; 12-18-2014 at 11:41 PM.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: A little help needed building a small RPG

    @OP: don't remove your code (or any other part) from your original posting after you're done with your thread; other might stumble upon this thread later (through Google?) and they prefer to find a coherent, understandable text.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Help needed with small chat lobby
    By fantasm0 in forum New To Java
    Replies: 1
    Last Post: 02-04-2014, 10:51 AM
  2. Small Java help needed
    By Supreme1012 in forum Jobs Offered
    Replies: 5
    Last Post: 05-24-2010, 03:00 AM
  3. help needed regarding tree building
    By invincible_me in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 02:44 PM
  4. Building small web application in java for practice.
    By Saurabh321 in forum New To Java
    Replies: 1
    Last Post: 02-01-2008, 04:38 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
  •