I'm trying to use a randomly constructed two dimensional array as a map for a text based game I'm building. If I define the world space as such:
class WorldSpace(object):
# Map information:
def __init__(self):
self.inner = ['g'] * 60 # Creates 60 'grass' tiles.
self.outer = [[].extend(self.inner) for x in self.inner]
# 'inner' & 'outer' variables define the world space as a 60 x 60 2-D array.
self.userpos = self.outer[0][0] # Tracks player tile in world space.
# The variables below are modifiers for the world space.
self.town = 't'
self.enemy = 'e'
I assume I would use a for loop to access the array data of self.outer -- using maybe the random module to determine what tiles will be replaced -- but how would I go about randomly replacing that data with specific modifier variables, and restricting how much data is being replaced? For example, if I wanted to replace about 25 of the original grass, or 'g', tiles with enemy, or 'e', tiles, how could I do that? Same with maybe 5 randomly placed towns?
Thanks for any replies.
x = shuffle(range(60)); y = shuffle(range(60))and then that gives you a list of non repeating random tiles to replace.