• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

formula for items picked up

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Samuel Weston wrote:

oh you wonderful man you! thank you thank you.



WO-man

you're welcome!
 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant woman :P

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)
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
excellent. I kept breaking down the process but I hadn't thought of making separate lists-at all lol
thanks again. I think that should do it.
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic