<div dir="ltr"><div>ok, now I have tested this more thoroughly, and it seems i can only do the grid[x][y] function up to grid[9][9], when i really should be able to be doing up to grid[10][20].<br></div>What exactly is the function of this row_squares list? <br>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 15, 2013 at 4:35 PM, Andrew Bradley <span dir="ltr"><<a href="mailto:abradley201@gmail.com" target="_blank">abradley201@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>Now I want to show you what I have written:<br>
<br></div>row = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)<br></div>column = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)<br>
</div>SQUARESIZE = 43<br><br></div>grid = []<br></div>for row in range(10):<br></div> row_squares = []<br></div> for column in range(20):<br></div> rect = Rect(12 + column * SQUARESIZE, 10 + row * SQUARESIZE, SQUARESIZE, SQUARESIZE)<br>
</div> row_squares.append(rect)<br></div> grid.append(row_squares)<br><br></div>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.<span class="HOEnZb"><font color="#888888"><br>
</font></span></div><span class="HOEnZb"><font color="#888888">-Andrew<br><div><div><div><div><div><div><div><div><div><div><br></div></div></div></div></div></div></div></div></div></div></font></span></div><div class="HOEnZb">
<div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 15, 2013 at 3:57 PM, Dave Angel <span dir="ltr"><<a href="mailto:davea@davea.name" target="_blank">davea@davea.name</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 05/15/2013 02:14 PM, Andrew Bradley wrote:<br>
<br>
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.<br>
<br>
> Thank you very much for your response: it seems excellent, but I'm afraid I<br>
> do not understand it fully. Your code here:<div><br>
><br>
> maxrows = 10<br>
> maxcols = 20<br>
> grid = []<br>
> for row in range(maxrows):<br>
> rowdata = []<br>
> for column in range(maxcols):<br>
> arg1 = ...<br>
> arg2 = ...<br>
> arg3 = ...<br>
> arg4 = ...<br>
> rowdata.append(pygame.Rect(arg<br>
> 1, arg2, arg3, arg4)<br>
> grid.append(rowdata)<br>
><br></div>
> Seems very good, but keep in mind I just started programming last week, and<br>
> this is hard for me to wrap my head around. Do I really just write grid =<br>
> []? or is this like a def grid(): function?<br>
<br>
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.<br>
<br>
<br>
> What do you mean by rowdata = []?<br>
<br>
[] is the way you define an empty list. Another way might be:<br>
rowdata = list()<br>
<br>
<br>
> And how exactly would I make the formula for a rect call?<br>
<br>
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.<br>
<br>
taking my clue from Ian, I might try:<br>
<br>
x_offset = 10<br>
y_offset = 12<br>
width = height = 43<br>
arg1 = column * width + x_offset<br>
arg2 = row * height + y_offset<br>
arg3 = width<br>
arg4 = height<br>
<br>
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).<br>
<br>
> If there's a good website for these kind of details, I would appreciate that too.<br>
<br>
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.<br>
<a href="http://www.alan-g.me.uk/" target="_blank">http://www.alan-g.me.uk/</a><br>
<br>
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.<br>
<br>
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.)<br>
<br>
<br>
--<br>
DaveA<div><div><br>
<br>
<br>
-- <br>
DaveA<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>