Ich möchte in einen Dictionary zwei Werte updaten.
die normale Ausgabe ist so:
Code: Alles auswählen
0, 0
0, 1
0, 2
0, 3
0, 4
1, 1
.
.
.
Code: Alles auswählen
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum2.png', 'x': 4}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum3.png', 'x': 0}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum2.png', 'x': 4}
Hier ist der Code:
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Generate the playingfield
"""
#~Imports
import cPickle as pickle
import random
#~Define arena
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
row=[]
for y in range(height_rows):
col=[]
for x in range(width_cols):
number = random.randint(1, 10)
if number == 5:
baum1.update({"x" : x, "y" : y})
col.append(baum1)
elif number == 1:
baum2.update({"x" : x, "y" : y})
col.append(baum2)
elif number == 7:
baum3.update({"x" : x, "y" : y})
col.append(baum3)
else:
grass.update({"x" : x, "y" : y})
col.append(grass)
row.append(col)
for i in row:
for i in i:
print i
name = raw_input("mapname: ")
pickle.dump(row, open("../maps/" + name + ".sav", "wb" ) )
print "fertig"