Uhhh,...just for the record meisl..
Quote:
completely deleting posts needs a VERY good reason
Till now, in my so far short career as moderator, I have never deleted any posts.
Here in Norway we have no problems with four letter words, not even
ten-letters, so anyone who curses/swears in desperation will be spared.
Flamers however, will get flushed, along with those that invite to immoral activity,
like cracking licenced software.
I have a few objections to the assignment...
The specs are ok except for one vital detail, the hierachy restrictions.
I'll summarize:
We have a forest (grid) with creatures (grass, tree, deer, hunter) that
inhabitate the cells of the grid. The creatures can be subdivided into two
groups: fixed and moving creatures.
For me the natural approach is to regard the grid as the "world" (applet) and
then create a superclass:
Square: has only position and dimension, and possibly an inhabitant.
A bare implementation of this one is the Grass extension, but not very useful
(its a copy really) so instances of Square is "grass". The thing is that
the inhabitant, as an extension of Square, cannot use the Square's positional
data, - hunters or deers dont drag turfs of grass around....
Tree: a Square extension cannot be moved to (no Squirrels yet)
And here is my twist:
MovingCreature: an abstract Square extension, abstract methods
are move() and doAfterMoveAction(). MovingCreatures are alive or dead,
they can move (if alive), they have a time to reproduce and they die
according to specfic rules.
Deer: a MovingCreature extension, does not eat hunters, doesn't bother
eating (logically). Dies of age if not eaten.
Hunter: a MovingCreature extension, eats Deers, must feed or die
The reason for my approach is this: we have a container of objects, and it will
complicate things if this container (forest) needs to know detailed info
about its creatures. Its should really just tell the moveable creatures to
"do their thing" at each tick. These "things" are moving and creature-
specific actions, like eat, die, feed, reproduce. I have put these actions
into the doAfterMoveAction() method of Deers and Hunters.
Using this approach the forest doesn't need to "know" anything more than
that a creature is a MovingCreature and then tell it to move and do its
specifics afterwards (doAfterMoveAction).
This may seem like an overkill, but it really isn't, try the other (assignment)
approach and I can guarantee that the code will be bloated in ceratin
areas and far less readable.
If we foresee an "enhanced" Forest with lions, cannibals,disease ridden
working girls (that won't plague the gay Hunters) plus some foot&mouth
viruses floating around, - then an abstract approach is a must. :)
I hope this is OK, I havent totally rehashed the assignment specs, all I have
done is inserting the MovingCreature abstract class between the Square
class and the Deers and Hunters, they are still subclasses of Square (and
MovingCreature).
1 Attachment(s)
Here are the preliminaries:
The code is on the brink of 100% functionality..... I just have to tweak
the biotope parameters :) Currently the Deers wont die, or is it that the
hunters are blind ? Hmm, obviously a bug that I must have daylight to hunt
down.
Anyway, I have to run now but check the attatched screenshot.
I'll post the code tomorrow
That looks Great! Thank You!
The screen shot looks great. You are right about the deer not dying. I totally understand about the bug and about you needing daylight to work on it. You can take your time and I will wait until tomorrow. Once again, thank you very much for you help. You have really helped me so much and I really appreciate it much. I will be back tomorrow to check on it. Thanks!