0

I have a game in Pygame I'm making called PyTanks. I have a tile sheet for a bottom layer (the grass), a middle layer (walls and tanks), and a top layer (whatever else goes on top). Each layer is 12x12 making a total of 432 names that need to be made, one for each tile. It would take a LONG time to make a separate name for each of those. I also make a class called Tile which contains the properties, so I want it to be similar to this.

class Tile:
    # insert a bunch of properties

a = Tile()
#insert the rest of the 432 class names

I wanted to make a dynamic variable so names can go like aa, ab, ac, ad ... (etc.)

then I can make it so Tile can name each one in a couple of lines rather than 432 lines.

Can anyone help?

  • 4
    You should make a dictionary mapping strings to `Tile`s. `{'aa': Tile(...), ...}` – Patrick Haugh Dec 24 '17 at 02:53
  • 1
    A list sounds most appropriate: `tiles = [Tile() for i in range(0, 432)]`, unless you have some place where you're sourcing names and et cetera. – Ryan Stein Dec 24 '17 at 02:54

0 Answers0