lundi 13 juin 2016

How to change the values of multiple indexes?

worldArray = [["." for i in range(5)] for i in range(5)]

This produces a map that I can use for my game. It should look something like:

[['.', '.', '.', '.', '.'],
 ['.', '.', '.', '.', '.'],
 ['.', '.', '.', '.', '.'],
 ['.', '.', '.', '.', '.'],
 ['.', '.', '.', '.', '.']]

Let's say the '.' represents a grass tile. If I wanted to replace a specific number of indexes to '~' instead to represent a water tile, what would be the easiest way of doing so? I want the map to look a bit like:

[['.', '.', '.', '.', '.'],
 ['.', '.', '.', '.', '.'],
 ['.', '.', '.', '.', '.'],
 ['~', '~', '.', '.', '.'],
 ['~', '~', '~', '.', '.']]

I know I can manually go through and change each specific index to show the '~' tile, but the real in-game map I use is 40 x 40 instead -- which would make the job of individually replacing each index a bit tedious and redundant. I would like to be able to define which tiles I want replaced, i.e. row 4, columns 1 - 2; row 5, columns 1 - 3. how could I go about doing that?

Aucun commentaire:

Enregistrer un commentaire