Now I want to show you what I have written:

row = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
column = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20)
SQUARESIZE = 43

grid = []
for row in range(10):
    row_squares = []
    for column in range(20):
        rect = Rect(12 + column * SQUARESIZE, 10 + row * SQUARESIZE,
SQUARESIZE, SQUARESIZE)
        row_squares.append(rect)
    grid.append(row_squares)

It appears to be working (that is, the program still runs without
crashing). So now, how can I utilize this new grid list? Thank you for the
help so far, I feel like the entire grid is now being worked out.
-Andrew



On Wed, May 15, 2013 at 3:57 PM, Dave Angel <da...@davea.name> wrote:

> On 05/15/2013 02:14 PM, Andrew Bradley wrote:
>
> Please reply on the list, not privately, unless it's something like a
> simple thank-you.  Typically, you'd do a reply-all, then delete the people
> other than the list itself.  Or if you're using Thunderbird, you could just
> reply-list.
>
> > Thank you very much for your response: it seems excellent, but I'm
> afraid I
> > do not understand it fully. Your code here:
>
> >
> > maxrows = 10
> > maxcols = 20
> > grid = []
> > for row in range(maxrows):
> >      rowdata = []
> >      for column in range(maxcols):
> >          arg1 = ...
> >          arg2 = ...
> >          arg3 = ...
> >          arg4 = ...
> >          rowdata.append(pygame.Rect(arg
> > 1, arg2, arg3, arg4)
> >      grid.append(rowdata)
> >
> > Seems very good, but keep in mind I just started programming last week,
> and
> > this is hard for me to wrap my head around. Do I really just write grid =
> > []? or is this like a def grid(): function?
>
> This code was intended to replace the 200 lines you started, A1= pygame...
> A2=  A3=   etc.  I'd have put them inside a function, but this is just one
> of the things I'd have initialized in such a function.  grid is a list of
> lists, not a function.
>
>
> > What do you mean by rowdata = []?
>
> [] is the way you define an empty list.  Another way might be:
>     rowdata = list()
>
>
> > And how exactly would I make the formula for a rect call?
>
> Well, for row==0 and col==0, you say you wanted 10, 12, 43, and 43 for the
> four parameters.   But you never said how you were going to (manually)
> calculate those numbers for other cells.  Only once you've decided that can
> you fill in "formulas" for arg1 and arg2.  I suspect that arg3 and arg4 are
> simply 43 and 43 respectively, since you want all the cells to be the same
> size.
>
> taking my clue from Ian, I might try:
>
>     x_offset = 10
>     y_offset = 12
>     width = height = 43
>     arg1 = column * width + x_offset
>     arg2 = row * height + y_offset
>     arg3 = width
>     arg4 = height
>
> That assumes that there is no gap between cells in this grid.  If you want
> a gap, then the width value used in the arg1 formula would be more than 43
> (width).  Likewise the height value used in the arg2 formula would be more
> than 43 (height).
>
> > If there's a good website for these kind of details, I would appreciate
> that too.
>
> You cannot begin to write a non-trivial program in Python without
> understanding lists pretty thoroughly.  Perhaps you should start with Alan
> Gauld's tutorial, which doesn't assume previous programming experience.
>    http://www.alan-g.me.uk/
>
> I haven't studied it, as Python was about my 35th programming language.
>  But he's very active on Python-tutor, and explains things very well. So
> his website is probably very good as well.
>
> Now, as you can see from Ian's message, writing a game using pygame will
> require quite a bit of other understanding.  He demonstrates with classes
> to represent cells, which is indeed what I'd do.  But I suspect you're not
> nearly ready to consider writing classes.  (You use classes all the time.
>  For example, 5 is an instance of class int.)
>
>
> --
> DaveA
>
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to