generating unintelligent random maps on mouse press

this code generates random maps on mouse press. it is really just a simple 2d array value filling. a modification of this article.

demo

explanations

 

def random_map():
    for r in range(map_length):
        for c in range(map_length):
            game_map[c][r] = random.randint(0,1)

 

here we generated a random map by looping and assigning a random value. randint returns a value betwen 1 and 0. the advantage of a function is that we just need to call it each time a random map is needed

 

def mousePressed():
    random_map()

 

each time the mouse is pressed, random_map() is called

  •  
  •  
  •  
  •  

Lives in Mauritius, cruising python waters for now.