mattkw80
Well-known member
Hi Everybody!
Hoping someone can clear up a great mystery for me….
I'm trying to learn Object Oriented programming, and to do so, I am writing a small Role Playing Game.
I understand why we break Players, Items, and Monsters into Classes… what I don’t “get” is how does the program know which Class object is “in focus”.
For example… if I randomly generate 3 monsters… from within the game… A Zombie, A Wolf, and A Lion… for example, how do my other methods know which of
these is “in play”. If during the game, a Zombie is called new…. How does my attack method reference this ‘new’ zombie? Sorry if that’s confusing.
How I have been handling it…
I have a ‘master’ object called ‘Monster’.
Public templatemonster As New monsterClass
Public mastermonster As New monsterClass
Public zombiemonster As New monsterClass
Public wolfmonster As New monsterClass
Public lionmonster As New monsterClass
I then have to “load” and “unload” them each time I want to use them.
For example…. I will copy “zombiemonster” over top of “mastermonster”.
I will then do all my referencing to “mastermonster”.
Ie:
mastermonster.doDamage
mastermoster.doHealing
Then… to “save” it… I have to copy it back. (Copy mastermonster object to zombiemonster)
Then.. I have to ‘reset’ the mastermonster by copying the templatemonster over top of it.
Then… if a Wolf jumps in.. I have to copy wolfmonster overtop of mastermonster… etc. etc. etc.
This is all because, within the methods of whatever I want to do to these objects (damage, heal, gain xp, etc.) I only know
how to ‘reference’ it by 1 name. “ie: mastermonster”. I have to do this if I am talking to objects as well. This is a key piece I know I am missing.
How do other people handle this?
I’m so sorry if this is too broad of question, or if I’ve made this confusing.
Hoping someone can clear up a great mystery for me….
I'm trying to learn Object Oriented programming, and to do so, I am writing a small Role Playing Game.
I understand why we break Players, Items, and Monsters into Classes… what I don’t “get” is how does the program know which Class object is “in focus”.
For example… if I randomly generate 3 monsters… from within the game… A Zombie, A Wolf, and A Lion… for example, how do my other methods know which of
these is “in play”. If during the game, a Zombie is called new…. How does my attack method reference this ‘new’ zombie? Sorry if that’s confusing.
How I have been handling it…
I have a ‘master’ object called ‘Monster’.
Public templatemonster As New monsterClass
Public mastermonster As New monsterClass
Public zombiemonster As New monsterClass
Public wolfmonster As New monsterClass
Public lionmonster As New monsterClass
I then have to “load” and “unload” them each time I want to use them.
For example…. I will copy “zombiemonster” over top of “mastermonster”.
I will then do all my referencing to “mastermonster”.
Ie:
mastermonster.doDamage
mastermoster.doHealing
Then… to “save” it… I have to copy it back. (Copy mastermonster object to zombiemonster)
Then.. I have to ‘reset’ the mastermonster by copying the templatemonster over top of it.
Then… if a Wolf jumps in.. I have to copy wolfmonster overtop of mastermonster… etc. etc. etc.
This is all because, within the methods of whatever I want to do to these objects (damage, heal, gain xp, etc.) I only know
how to ‘reference’ it by 1 name. “ie: mastermonster”. I have to do this if I am talking to objects as well. This is a key piece I know I am missing.
How do other people handle this?
I’m so sorry if this is too broad of question, or if I’ve made this confusing.