[Tutor] A row of cards, but they're all red

->Terry<- tvbare at socket.net
Mon Jan 30 07:47:38 CET 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Slackware 10.1
Python 2.4.1
Pygame 1.6

The images (if needed) can be found at:

<URL:http://members.socket.net/~tvbare/images/>

Could someone help me understand the output I'm getting from
the snippet below? I thought I would get a nice row of cards,
13 reds, 13 blues, etc. But what I get is a row of all red
cards. The rank is correct on the cards, but they are all red.

If the commented out lines near the bottom are uncommented
and the preceding 3 lines are commented out, the output is
correct. This tells me 'images' is ok, the right images are
being loaded. The problem occurs when 'cards' is built. Can
the image objects not be assembled in a list?

Apologies if this is off-topic for tutor and would be better
directed to a Pygame-specific list.

Here's the code:
- --------------------------
#!/usr/bin/env python

import pygame
pygame.init()  # Initialize pygame
screen = pygame.display.set_mode((640, 140))

suits = ["red ", "blue", "green", "yellow"]
ranks = ["ace", "two", "three", "four", "five",  "six", "seven",
          "EIGHT", "nine", "ten", "jack", "queen", "king"]
value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
images = []
cards = []

for z in range(52):
     fname = "images/" + str(z) + ".png"
     print("loading %s" % fname)
     img = pygame.image.load(fname).convert()
     images.append(img)

for suit in suits:
     for x, rank in enumerate(ranks):
         cards.append([suit, rank, value[x], images[x]])

x = 10
y = 10

for crd in cards:
     screen.blit(crd[3], (x, y))
     print("Should be a %s %s" % (crd[0], crd[1]))
#for image in images:
#    screen.blit(image, (x, y))
     pygame.display.update()
     pygame.time.wait(250)
     x += 10

- ---------------------------
End of code.

Thanks much,
- -- 
     Terry

      ,-~~-.___.       Terry Randall <tvbareATsocketDOTnet>
     / |  '     \  http://members.socket.net/~tvbare/index.html
    <   )        0
     \_/, ,-----'
        ====          //   Linux Counter Project User# 98233
       /  \-'~;    /~~~(0)
      /  __/~|   /      |    If only Snoopy had Slackware!
    =( ______| (________|

"He is your friend, your partner, your defender, your dog.
You are his life, his love, his leader. He will be yours,
faithful and true, to the last beat of his heart. You owe
it to him to be worthy of such devotion."    -- Unknown
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFD3baOQvSnsfFzkV0RAhfUAJ4qrjQSty9iFLH8yFc8zw+qOfO5RACfbetI
wgXLuy5wYkL598gH2ZlXQqA=
=2T6i
-----END PGP SIGNATURE-----



More information about the Tutor mailing list