Browse Source

Implemented treasure

master
Noëlle Anthony 7 years ago
parent
commit
fe815f29b7
1 changed files with 20 additions and 4 deletions
  1. 20
    4
      CellMap.py

+ 20
- 4
CellMap.py View File

class CellMap: class CellMap:
initial = [] initial = []
genmap = [] genmap = []
treasurelist = []


def __init__(self, height=None, width=None, seed=None, death=None, def __init__(self, height=None, width=None, seed=None, death=None,
birth=None, reps=0, out=None, color=None, chunky=None, birth=None, reps=0, out=None, color=None, chunky=None,
for _ in range(self.reps): for _ in range(self.reps):
self.smoothMap() self.smoothMap()
if self.out: if self.out:
if self.treasure:
self.generateTreasure()
self.createImage() self.createImage()
else: else:
self.printScreen() self.printScreen()
# So we make this neighbor count as a wall. # So we make this neighbor count as a wall.
count += 1 count += 1
#pass #pass
elif self.genmap[n_y][n_x]:
elif self.genmap[n_y][n_x] and self.genmap[n_y][n_x] != "Gold":
# This neighbor is on the map and is a wall. # This neighbor is on the map and is a wall.
count += 1 count += 1
return count return count


def generateTreasure(self):
self.treasurelist = []
walledin = False
for j in range(len(self.genmap)):
for i in range(len(self.genmap[j])):
if not self.genmap[j][i]:
walledin = True if self.countWalls(i,j) >= 5 else False
if walledin:
self.genmap[j][i] = "Gold"
walledin = False

def printScreen(self): def printScreen(self):
wall = "II" wall = "II"
path = " " path = " "
gold = "GG"
for line in self.genmap: for line in self.genmap:
print("".join([wall if x else path for x in line]))
print("".join([path if not x else (gold if x == "Gold" else wall) for x in line]))
print() print()


def createImage(self): def createImage(self):
c_wall = [random.randint(0,255), random.randint(0,255), random.randint(0,255)] if self.color else [0,0,0] c_wall = [random.randint(0,255), random.randint(0,255), random.randint(0,255)] if self.color else [0,0,0]
# Paths are white by default # Paths are white by default
c_space = [255-x for x in c_wall] c_space = [255-x for x in c_wall]
c_gold = [(x+64)%255 for x in c_space]
if self.chunky: if self.chunky:
for line in self.genmap: for line in self.genmap:
for _ in range(2): for _ in range(2):
for val in line: for val in line:
for _ in range(2): for _ in range(2):
lst.append(tuple(c_wall) if val else tuple(c_space))
lst.append(tuple(c_space) if not val else (tuple(c_gold) if val == "Gold" else tuple(c_wall)))
else: else:
for line in self.genmap: for line in self.genmap:
for val in line: for val in line:
lst.append(tuple(c_wall) if val else tuple(c_space))
lst.append(tuple(c_space) if not val else (tuple(c_gold) if val == "Gold" else tuple(c_wall)))
img.putdata(lst) img.putdata(lst)
if not os.path.exists("maps"): if not os.path.exists("maps"):
os.makedirs("maps") os.makedirs("maps")

Loading…
Cancel
Save