• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting from another class.

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • 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!!
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic