Question re: objects and square grids

Andrew Bradley abradley201 at gmail.com
Wed May 15 12:56:59 EDT 2013


Hello everyone.

I am having a good time programming with Python 3.3 and Pygame. Pygame
seems like the perfect platform for the kind of simple games that I want to
make.

What I have currently programmed is basically a drawn rectangle filled with
200 squares, each side of the squares being 43 pixels. The rectangle is 20
squares by 10 squares.

This grid is what I want to have the entire game on. There will be pieces
that move certain numbers of squares, perform actions that effect pieces on
certain squares, etc. The possibilities are endless.

So what I am now trying to do is organize these squares into objects that I
can easily reference when programming things related to the squares.

So far, I have done this:

A1 = pygame.Rect(10, 12, 43, 43)
A2
A3
A4
B1
B2
etc.

where said integers are the precise location of the top left-most square
for A1, and onward down the line. I would guess that I could continue on in
such a fashion, with appropriate box names for each square. But I'm running
into the problem of confirming that the code above actually does something
useful. For example, I would love to be able to turn A1 a different color,
but how does this work? How do I actually utilize these object variable
names? Are there methods that I am not aware of, because most things I try
tend to do nothing or crash the game. For example, A1.fill(BLUE) does not
work.

Any general advice about how to organize my squares into something that is
easy to program for would be VERY appreciated. Basically all the games I
want to make involve square grids like this, so I want to know as much
about them as possible.

Thank you very much for reading this,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130515/9bbc5b0d/attachment.html>


More information about the Python-list mailing list