[Tutor] canvas -> CLASSES
alan.gauld at btinternet.com
Thu May 10 20:04:36 CEST 2007
"Teresa Stanton" <tms43 at clearwire.net> wrote
> Would it be ... er... uh... 'proper'... to put the maze in a module,
It doesn't really matter except thatr putting it in a module
makes it easier to reuse in another program later.
> make the actual movement of the .gif's in a class in a seperate file
Yes that works too.
> I find the code required to build the maze to be quite large,
> even with the refinenements.
What do you see the maze as doing? What methods will it have?
I would expect it to know about
- its layout and geometry
- objects within the maze(their location)
- How to draw itself - possibly be delegating some of that
to the contained objects.
> For now, at least, I can't figure out how to do the maze in
> a class,
If you only have a single instance of maze then you may not
need a class and a set of plain old functions may be just as
> and I want to get the .gif moving in a class because
> that makes sense.
OK, So I'm asssuming these gifs represent something, not actual gif
So the class should probably represent that something.
> But I'm not sure how to put the .gif ON the maze if they
> are seperate files.
I'm not sure whjat you are finding hard hgere. If they are in
separate modules just import the modules as needed?
> I will, of course import the maze, but then, how do I put
> the gif on the maze from the class?
Pass the instances of the gif class (ie the objects) into
the maze. Presumably you have some kinde of method
for controlling these gif objects? Either you move the
gif object or you ask the maze to move them. Given
that only the maze knows its own geometry I'd suggest
getting the maze to move them. It should either return
a success code, the new location of the gif or an error
code if the piece couldn't be moved - either because
another gif blocks it or the geometry has no path in
You also need to decide what movement method you
will use - coordinates(x,y) or vectors(direction+magnitude)
These are all design decision oinly you can make and
any of the technioques can be made to work.
Author of the Learn to Program web site
More information about the Tutor