Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'column': 0.07; 'subject:Question': 0.07; 'classes.': 0.09; 'function,': 0.09; 'grid': 0.09; 'try:': 0.09; 'width': 0.09; 'python': 0.11; 'def': 0.12; 'assume': 0.14; 'itself.': 0.14; 'language.': 0.14; 'arg2,': 0.16; 'be:': 0.16; 'call?': 0.16; 'excellent,': 0.16; 'formula': 0.16; 'function?': 0.16; 'likewise': 0.16; 'non-trivial': 0.16; 'pygame': 0.16; 'received:74.208.4.195': 0.16; 'thoroughly.': 0.16; '(you': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'bit': 0.19; 'seems': 0.21; 'programming': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; "haven't": 0.24; 'define': 0.26; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'andrew': 0.30; "i'm": 0.30; 'code': 0.31; 'lines': 0.31; 'too.': 0.31; 'alan': 0.31; 'assumes': 0.31; 'cells': 0.31; 'initialized': 0.31; 'parameters.': 0.31; 'class': 0.32; 'lists': 0.32; 'probably': 0.32; 'another': 0.32; 'quite': 0.32; "i'd": 0.34; 'could': 0.34; 'classes': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'explains': 0.36; "he's": 0.36; 'height': 0.36; 'should': 0.36; 'example,': 0.37; 'list': 0.37; 'list.': 0.37; 'represent': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'previous': 0.38; '12,': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'around.': 0.60; 'numbers': 0.61; 'simply': 0.61; 'simple': 0.61; "you're": 0.61; 'here:': 0.62; "you've": 0.63; 'kind': 0.63; 'such': 0.63; 'decided': 0.64; 'week,': 0.64; 'more': 0.64; 'taking': 0.65; 'afraid': 0.65; 'size.': 0.65; 'reply': 0.66; 'experience.': 0.67; 'between': 0.67; 'details,': 0.68; 'received:74.208': 0.68; 'skip:r 30': 0.69; 'url:me': 0.69; 'demonstrates': 0.84; 'gap': 0.84; 'ian,': 0.84; 'started,': 0.84; 'typically,': 0.84; 'good,': 0.91 Date: Wed, 15 May 2013 15:57:52 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Question re: objects and square grids References: <5193CC16.80304@davea.name> In-Reply-To: <5193CC16.80304@davea.name> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:7C6sTJGl7C3IaNOd5srpXzxz2ZM31ccC3XWcUr+PzDz qmYiDYi+y0kpbjhLOyrHzYTZjgWON7zTs1P5PMHYxW+GBTuYqj CGK8ZpmQ+Prp4SjR/6wHq0dWZ/pEVuKt9pJlK+xcu3XjPVQSe0 u56ORbdzIf4+dSs3UIGJySvpaCZTvwBVoDS+hGtSz+DBUZWSJJ svvZY+zxu3SgYCuSWjsMMenTx0YQDhu4k//waaPfOn20P50knj IKyCrtojcntITZBxRpvuD0qEw6yNZYO7Bxa+GhX9HBEQgqJ+E8 hHCS6uzQhv07tOn1I4NqdmVoXQtjIHnH2mjfbbzW/m8DppcLw= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 91 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368647896 news.xs4all.nl 15952 [2001:888:2000:d::a6]:47569 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45369 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