java - Passing/storing info from a class? -
i'm beginner java , i'm making simple text rpg , want store character information in class such name, job, age, etc. example:
class mychar { string name = ""; string job = ""; int age = 0; //set, get, etc... }
and want user able asked name, job, etc. , pass class can pulled later on. understand how ints quite well, example have stats class hp, attack power, etc. stored:
class stats // demonstrates class { int hp = 10; //set, get, etc... public int hit() // player hit { hp --; return hp; } }
so see have small grasp on i'm not quite sure how player can enter information , have stored. understand usage:
stats mystats = new stats("john", "warrior", 30);
when comes identifying info, not how let player choose themselves. i'm sorry if sound vague, i'll update post needed!
edit: have main public class contains different "rooms" , such. it's pretty lengthy, , know how user input. instance, have command window allows user "look", "use", "get", etc. understand user input quite well. don't how have user enter info , store info in outside class called upon later.
as understand, want have kind of user input, , pass information class.
you this:
import java.io.reader; //receive input system.in - console bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); system.out.print("enter character's name!"); string name = br.readline(); //read line input system.out.print("enter job want!"); string job = br.readline(); system.out.print("what's character's age?"); int age = integer.parseint(br.readline()); mychar character = new mychar(name, type, age);
Comments
Post a Comment