Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Generate the playingfield
"""
#~Imports
import cPickle as pickle
import random
#~Define arena
#5*5 = 25
height_rows=5
width_cols=5
#~Define images
grass = {"tile" : "/gametiles/grass.png", "action" : None, "x" : None, "y": None}
baum1 = {"tile" : "/gametiles/baum1.png", "action" : None, "x" : None, "y": None}
baum2 = {"tile" : "/gametiles/baum2.png", "action" : None, "x" : None, "y": None}
baum3 = {"tile" : "/gametiles/baum3.png", "action" : None, "x" : None, "y": None}
#~Variables
objectlist = []
rows=[]
for y in range(height_rows):
row=[]
for x in range(width_cols):
number = random.randint(1, 10)
if number == 5:
objectlist = baum1
elif number == 1:
objectlist = baum2
elif number == 7:
objectlist = baum3
else:
objectlist = grass
objectlist.update({"x" : x, "y" : y})
row.append(objectlist)
rows.append(row)
for i in rows:
for e in i:
print e
name = raw_input("mapname: ")
pickle.dump(row, open("../maps/" + name + ".sav", "wb" ) )
print "fertig"