Im practicing my coding by making a simple game. thing is, i don't know how to create a code to allow for the user to store picked up items.
am I going about this correctly? what should i do next?
Janeice DelVecchio wrote:If you use code tags, it's easier to read.....
Right now your inventory is a String.... wouldn't it make more sense if it was a Collection of some sort? Maybe a List?
Then as the user picks stuff up, it can be added to the list using the add() method on List?
The Collections api also provides lots of ways you can interact with the objects in the list.
oh you wonderful man you! thank you thank you. ive only ever used a List in HTML was not aware of java having it. and the api-i'll look those things up . hope it helps ^^
thanks again
hmmm, lists are pretty cool(just researched a bit into them), but what im looking for should be much simpler. its meant to be behind the scenes without the user seeing it.
let me describe my overall goal.
I intend to make a program where the user has to get out of his prison by getting a key. however, he soon finds out that the lock is booby trapped with several traps. so he'll need to pick up a number of items in order to help him bypass the traps (e.g rubber gloves to bypass the electric trap).
I think a simple "if/else" code would do.
something like:
void ExitPrison () {
if (user has key)
if (user has gloves)
do xyz
else
do abc
}
in addition i'll need some sort of Scanner coding to allow for user input/interaction
(e.g when user picks up key, or when user uses key)
my question then becomes this, what kind of coding should I look into if I want the user to "pick up/use" items and to have behind the scenes the program register the item as no longer on the "floor" but in the users possession-without the user having to put in the data manually ?
(p.s feel free to critique my coding, not fully sure its correct)
It really all depends on how complicated you wanna get.
To me, I'd have a list of items that the user has, and a list of items in the room. When the user "picks up" an item, the item gets removed from the room list and added to the user's list.
It helps if you write down in words what you want to do, and work in small chunks.
When you do things right, people won't be sure you've done anything at all.