Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45362
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'column': 0.07; 'subject:Question': 0.07; 'advice.': 0.09; 'arguments': 0.09; 'grid': 0.09; 'python': 0.11; 'suggest': 0.14; 'arg2,': 0.16; 'numbered': 0.16; 'pygame': 0.16; 'pygame.': 0.16; 'variables,': 0.16; 'zero,': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'seems': 0.21; 'programming': 0.22; 'separate': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; "haven't": 0.24; 'looks': 0.24; '(or': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'andrew': 0.30; 'code': 0.31; 'testing.': 0.31; 'maybe': 0.34; "i'd": 0.34; "can't": 0.35; 'something': 0.35; 'one,': 0.35; 'but': 0.35; 'everyone.': 0.36; 'shorter': 0.36; 'done': 0.36; 'list': 0.37; 'follows:': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'called': 0.40; 'how': 0.40; 'lower': 0.61; 'entire': 0.61; 'simple': 0.61; "you're": 0.61; 'you.': 0.62; 'address': 0.63; 'kind': 0.63; 'received:74.208': 0.68; 'skip:r 30': 0.69; 'clearer': 0.84; 'received:74.208.4.194': 0.84 |
| Date | Wed, 15 May 2013 13:55:34 -0400 |
| From | Dave Angel <davea@davea.name> |
| 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 | <CAPp_YbVwiK1RBk_fLP32Kzv56GjYUf4TL=Ogzo5qsOKtrd8kGg@mail.gmail.com> |
| In-Reply-To | <CAPp_YbVwiK1RBk_fLP32Kzv56GjYUf4TL=Ogzo5qsOKtrd8kGg@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:92NpD10MMwtnukoGDmHLFs13Deu4Zkx8ErHT8kdRSNf QdFRwxZAC37ipCXK5E3GaGs71HPTqvEA/jCfrGxxdQH/H+dKkh xI5Vk7dC3rNjyu6uRk4sArk6kWhOBV15bYlUh2fxoL2yDJKt3C 9o4OVY17pEDyMwVEXDA2UyKi0dt0iH46fSPN2wSXWeK/pf2Jdy DW9LWQj3MgGoXvgxqAMwcROR+2S1om22MqivHqj/rGULD+HSoa ZTHBrTO14fihO+5SJCsVfpC1YQVPec+goCZ96Jyd+fzVRAbw84 FB4Y6SfiSYO2y9IckhAQvLS0GvifPtbFCaKOkAwgkfUCms2mg= = |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1713.1368640551.3114.python-list@python.org> (permalink) |
| Lines | 70 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1368640551 news.xs4all.nl 15891 [2001:888:2000:d::a6]:39510 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45362 |
Show key headers only | View raw
On 05/15/2013 12:56 PM, Andrew Bradley wrote:
> 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.
>
Pygame indeed looks pretty good to me as well. But I haven't done
anything with it, so I can't give you specific Pygame advice.
> <SNNIP>
>
> So far, I have done this:
>
> A1 = pygame.Rect(10, 12, 43, 43)
> A2
> A3
> A4
> B1
> B2
> etc.
>
This is a code smell in Python (or any reasonable language). I'd
suggest that instead of trying to have 200 separate global variables,
you have one, maybe called grid, as follows:
maxrows = 10
maxcols = 20
grid = []
for row in range(maxrows):
rowdata = []
for column in range(maxcols):
arg1 = ...
arg2 = ...
arg3 = ...
arg4 = ...
rowdata.append(pygame.Rect(arg1, arg2, arg3, arg4)
grid.append(rowdata)
Now, this can be done shorter with list comprehensions, but I figured
this would be clearer for you. I also may have the 10 and 20 reversed,
but you can work that out.
You'd need to make four formulae to get the four arguments to the Rect
call, using row and column respectively. Remember that row and column
will be numbered from zero, not from one.
But now, you can either address a single rect by
grid[4][8]
or you can do something to all of them, or to an entire row, or to an
entire column, pretty easily.
While you're testing your formulae, you might want to replace the
rowdata.append line with something like:
rowdata.append( (arg1, arg2, arg3, arg4) )
And perhaps your maxrows, maxcols might be lower while you're testing.
And you can just print grid to see how those arguments are looking.
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Question re: objects and square grids Dave Angel <davea@davea.name> - 2013-05-15 13:55 -0400
csiph-web