0

So I'm doing the 2048 game in python (pygame) and it's already working but I wanted to replace the numbers with some images I made and I can't do it. I would really appreciate if someone would help me. Thanks in advance.

I tried this (where j and k are the line and column of the number ; str(value(game,j,k)) is the value in j,k ; wood is the name of the image I uploaded)

for j in range(1,5):
    for k in range(1,5):
        number=str(value(game,j,k))
        if number==2:
                   number = wood

in this case I wanted to replace the 2's with the wood image

furas
  • 134,197
  • 12
  • 106
  • 148
youknowwho
  • 33
  • 7
  • Take a look at [this answer](https://stackoverflow.com/a/47771881/6220679). If you don't know how classes work, ignore that part of the answer and just blit the loaded images in your while loop. – skrx Dec 27 '17 at 19:21
  • 1
    Please add a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve) and describe more thoroughly what you're trying to do and what's causing problems. Not everybody here knows the game 2048. – skrx Dec 27 '17 at 19:30
  • 1
    If you want to compare the `number` to `2`, you probably shouldn't call the `str` function in the line above. – skrx Dec 27 '17 at 19:33
  • What you need to know is that im trying to replace a '2' that appears in my pygame screen with an image – youknowwho Dec 27 '17 at 19:33
  • 1
    if you use `str()` then `numer` is string `"2"` not integer `2` – furas Dec 27 '17 at 21:53
  • 1
    btw: you could keep images in list or dictionary and then use `list_of_images[number]` – furas Dec 27 '17 at 22:15

0 Answers0