def step(self): for thing in self.items.itervalues(): thing.act() for pos, thing in self.items.iteritems(): gridpy.plot(thing.color(), pos) gridpy.update()
def main_loop(self): while True: self.game.tick() #print "--- Game Matrix ---" #print self.game for cell, position in self.game.cells(): gridpy.plot(GUI.CELL_COLOR, position) gridpy.update() gridpy.clear()
def move_idk(self): adj = self.world.adjacents(self.pos) if self.goal in adj: return adj = [pos for pos in adj if not (pos in self.bad)] if adj == []: for pos in self.bad: gridpy.remove(pos) self.bad = {} adj = [pos for pos in adj if not (pos in self.bad)] #gridpy._debug(adj) adj.sort(key=lambda pos: self.world.distance(pos, self.goal.pos)) while len(adj) > 0 and adj[0] == self.last_pos: self.bad[adj[0]] = True gridpy.plot(gridpy.YELLOW, adj[0]) del adj[0] if len(adj) > 0: self.last_pos = self.pos self.move_to(adj[0])
def __init__(self, map): self.items = {} self.rows = len(map) self.cols = len(map[0]) gridpy.set_fps(10) for r in xrange(self.rows): for c in xrange(self.cols): square = map[r][c] pos = (c, r) if square == 'A': self.items[pos] = Player(pos, self) elif square == 'B': self.items[pos] = Goal(pos, self) elif square == 'X': self.items[pos] = Rock(pos, self) gridpy.title("Search demo") gridpy.show() for pos, thing in self.items.iteritems(): gridpy.plot(thing.color(), pos)
#gridpy.set_style(gridpy.NONE) gridpy.title("A simple demo") gridpy.show() def cycle(list): while True: for item in list: yield item rainbow = cycle([ gridpy.CYAN, gridpy.YELLOW, gridpy.MAGENTA, gridpy.RED, gridpy.GREEN, gridpy.BLUE, gridpy.WHITE, gridpy.GREY, ]) while True: for c in xrange(gridpy.cols()): color = rainbow.next() for r in xrange(gridpy.rows()): location = (c, r) gridpy.plot(color, location) gridpy.update() gridpy.remove(location) #gridpy.clear()
def add(self, pos, thing): self.items[pos] = thing gridpy.plot(thing.color(), pos)
#gridpy.set_style(gridpy.SINGLE) #gridpy.set_style(gridpy.NONE) gridpy.title("A simple demo") gridpy.show() def cycle(list): while True: for item in list: yield item rainbow = cycle([ gridpy.CYAN, gridpy.YELLOW, gridpy.MAGENTA, gridpy.RED, gridpy.GREEN, gridpy.BLUE, gridpy.WHITE, gridpy.GREY, ]) while True: for c in xrange(gridpy.cols()): color = rainbow.next() for r in xrange(gridpy.rows()): gridpy.plot(color, (c, r)) gridpy.update() #gridpy.remove((c, r)) gridpy.clear()