• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Getting from another class.

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the easiest way to get something from another class in the project and using it in the class you want. For example: currentRoom is an object of Room in the Game class. There is another class called Player... and the player object has to store the currentRoom in the Game class. And... this has to be done in the Player class... its necessary. Whats the easiest way to do this? Even Pseudo code will help as long as the keyword used is in it because chances are, I don't know it. Thanks!!
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a method in the Game class called getCurrentRoom() that returns a Room. If you are in Player, then you need a reference to the Game class. if you are in some other code, you could write a putCurrentRoom() in the Player class, then do

Room tempRoom = myGame.GetCurrentRoom();
currentPlayer.putCurrentRoom(tempRoom);
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic