[Tutor] canvas -> CLASSES

Teresa Stanton tms43 at clearwire.net
Fri May 11 05:53:22 CEST 2007

It seems that all the player does is tell the .gif where to move based on a mouse click event.  I don't understand redrawing or anything like that.  This is begining Tkinter for me.  So, perhaps you could dumb down what you were saying?  I was able to move the .gif from one point to the next, based on the event, but it wasn't updating from the old x (or y) to the new position.  So, it seemed that I needed to change it to a class.  

When I run it now, the .gif shows up on the maze, but I can't get it to move because of the error message that I showed previously.  Would it be possible to look at the code I wrote and point out what I'm doing wrong with it?  Or is it completely wrong and I need to start over? (God Forbid!!)  I was modeling it after some of Greysons code.  But his code isn't moving from one coordinate to another, and that may be the problem.

not giving up!!!

-----Original Message-----
From: ALAN GAULD [mailto:alan.gauld at btinternet.com] 
Sent: Thursday, May 10, 2007 2:27 PM
To: Teresa Stanton
Cc: tutor at python.org
Subject: Re: [Tutor] canvas -> CLASSES
> T's reply:
> The maze is simply the backdrop.  I've attached the new and improved code.
As I said in the last post I think the maze probably needs to 
be quite a bit more than the backdrop. I think it knows about 
the rules of movement within the maze - which routes are blocked, 
where other players are sitting etc.
> > OK, So I'm asssuming these gifs represent something, 
> um... actually, the .gif will be a photo that will be taken as 
> part of the 'game'.  ... the first pic will be the main pic as 
> it goes around the maze.  When the pic 'collides' with items 
> that will be placed another pic will be displayed 
OK, In that case it sounds like the gif is only how the object 
will draw itself. The object is actually some kind of player, 
which has a status which is reflected by the gif displayed?
So the player c;lass will have methods to play the game, 
a status attribute, a collection of gifs to match the status,
a location of some kind and a draw method that displays 
the appropriate gif when requested by the maze.
With those two class definitions in mind I'd suggest an 
architecture where:
A maze is created and populated by players
The maze draws itself and then asks each player to draw itself.
Players then do something (whatever the game requires) and that 
may involve asking the maze to move them to a new location.
The maze will look at their position relative to the layout of the 
maze and the position of other players/objects. If the move can 
be made it moves the player and sets its new location. The maze 
then redaws itself, including asking the players/objects to redraw 
themselves at their new positions. (If you want to get really smart 
you could just redraw the sections of maze that have changed, 
but that's quite tricky to manage reliably)
The whole thing could be controlled by an overall Game object 
which contains the maze and a list of players (some or all of 
which could be in the maze). The game object is responsible 
for ensuring each player makes plays at the appropriate time 
or receives the user events and matches them to a player 
as appropriate.
Does that sound like a workable model?
BTW Have you looked at PyGame (www.pygame.org)
which has things like sprites etc which may make some of 
this stuff easier.
Alan G.
Inbox full of unwanted email? Get leading protection and 1GB storage with
All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070510/54fa6326/attachment.html 

More information about the Tutor mailing list