Question re: objects and square grids

Discussion in 'Python' started by Andrew Bradley, May 15, 2013.

  1. 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
     
    Andrew Bradley, May 15, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Angel
    Replies:
    0
    Views:
    88
    Dave Angel
    May 15, 2013
  2. Ian Kelly
    Replies:
    0
    Views:
    112
    Ian Kelly
    May 15, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    106
    Dave Angel
    May 15, 2013
  4. Dave Angel
    Replies:
    0
    Views:
    83
    Dave Angel
    May 16, 2013
  5. Andrew Bradley

    Re: Question re: objects and square grids

    Andrew Bradley, May 16, 2013, in forum: Python
    Replies:
    0
    Views:
    82
    Andrew Bradley
    May 16, 2013
Loading...

Share This Page