• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing and Extending. Am I doing it right?  RSS feed

 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to fully understand is the ability to Extend and Implement.

I like to think I understand programming concepts better when applied to video game concepts.

So to better understand the use of both I made a very small program showing the use of both Implement and Extends using concepts like: Zombie, NPC, and Enemy.


Here are my files.

InterfacePrac.java


NPC.java


Enemy.java


Zombie.java


NormalZombie.java


The way I have it, I could add more types of Zombie classes like FastZombie, PoisonZombie, ScreamerZombie, and they can all have something like this



Am I on the right track, or am I doing things all wrong... Terribly wrong??? I am open to suggestions.

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's an NPC ? Perhaps a more descriptive name would help.
Is an NPC a Zombie?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a major error, I am afraid. The frequent use of the keyword static. I haven't gone through the code properly, but having a class with all its members static looks wrong.
Minor point: remove the public modifier from all methods in your interfaces, because it is unnecessary.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:What's an NPC ? Perhaps a more descriptive name would help.
Is an NPC a Zombie?


Assuming this is some form of roleplaying game, then it stands for Non-Player Character.
It's a common abbreviation.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:What's an NPC ? Perhaps a more descriptive name would help.
Is an NPC a Zombie?


NPC is Non-Player-Character. Basically, it refers to everyone in the game but you. This doesnt include people such as your friends. Here are some examples

Farmer
Shop Keeper
Guard
Zombie
Orc
Dragon
Chicken
Cow
Beggar
Child

Here is a description found using a Google search
A non-player character (NPC) is a video game character that is controlled by the game's artificial intelligence (AI) rather than by a gamer. Non-player characters serve a number of purposes in video games, including: As plot device: NPCs can be used to advance the storyline.


It is my understanding that since these things are all NPCs, there should be an NPC class. A Farmer may not be killed, and may not attack the player, but He will still have some basic template information, like his level, his name, etc.

I don't play Runescape anymore, but if I remember correctly, it basically followed a format just like this.

An NPC isnt a Zombie, but a Zombie is an NPC. As for a more descriptive name, is gaming, NPC is a standardized term.


Campbell Ritchie wrote:There is a major error, I am afraid. The frequent use of the keyword static. I haven't gone through the code properly, but having a class with all its members static looks wrong.
Minor point: remove the public modifier from all methods in your interfaces, because it is unnecessary.


Thanks for this information
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell is correct. All the statics are wrong; why are they there?

Here is Bear's Rule of statics: If you can't justify why the static keyword is there with a single, simple sentence, remove it. The following sentence is not a justification (it's an excuse): "Because it did not compile without it."
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Campbell is correct. All the statics are wrong; why are they there?

Here is Bear's Rule of statics: If you can't justify why the static keyword is there with a single, simple sentence, remove it. The following sentence is not a justification (it's an excuse): "Because it did not compile without it."


Yeah, I am sorry about that. It's ignorance on my part
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Campbell is correct. . . .
static . . .  The following sentence is not a justification (it's an excuse): "Because it did not compile without it."
Thank you for the first part. I think I use the same rule of thumb, with hardly any differences.

The compiler error message, “Non‑static variable xyz cannot be accessed from static context” is not at all helpful and probably even confusing. It is true that you cannot access instance members of the class from a static method, but it makes it look as if static were the normal state. It makes it look as though the correction is to make xyz static, but the real way to correct the code is to move the call out of the static method.
In this instance, all your NPC instances will have the same name at any one time, and changing the name for one instance will change that same name for all instances.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose Kreif wrote:Yeah, I am sorry about that. It's ignorance on my part

That's fine. Is this not exactly the type of thing that you are here to learn? 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!