Results 1 to 7 of 7
- 12-18-2014, 10:35 PM #1
Member
- Join Date
- Jun 2014
- Posts
- 10
- Rep Power
- 0
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.
- 12-18-2014, 10:44 PM #2
Member
- Join Date
- Mar 2012
- Posts
- 29
- Rep Power
- 0
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
- 12-18-2014, 10:46 PM #3
Member
- Join Date
- Jun 2014
- Posts
- 10
- Rep Power
- 0
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.
- 12-18-2014, 10:54 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 29
- Rep Power
- 0
- 12-18-2014, 11:07 PM #5
Member
- Join Date
- Jun 2014
- Posts
- 10
- Rep Power
- 0
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.
- 12-18-2014, 11:16 PM #6
Member
- Join Date
- Jun 2014
- Posts
- 10
- Rep Power
- 0
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.
- 12-19-2014, 07:29 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
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,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Help needed with small chat lobby
By fantasm0 in forum New To JavaReplies: 1Last Post: 02-04-2014, 10:51 AM -
Small Java help needed
By Supreme1012 in forum Jobs OfferedReplies: 5Last Post: 05-24-2010, 03:00 AM -
help needed regarding tree building
By invincible_me in forum New To JavaReplies: 2Last Post: 08-12-2008, 02:44 PM -
Building small web application in java for practice.
By Saurabh321 in forum New To JavaReplies: 1Last Post: 02-01-2008, 04:38 PM
Bookmarks