Exemple #1
0
            if self.isHorzMirror():
                self.setHorzMirror(False)
                self.turn(270)
                self.move()
                self.turn(270)
            else:
                self.setHorzMirror(True)
                self.turn(90)
                self.move()
                self.turn(90)
        self.tryToEat()

    def tryToEat(self):
        actor = gg.getOneActorAt(self.getLocation(), Leaf)
        if actor != None:
            actor.hide()


# --------------------- class Leaf ---------------------------
class Leaf(Actor):
    def __init__(self):
        Actor.__init__(self, "sprites/leaf.gif")


# ----------------- main -----------------------------
gg = GameGrid(10, 10, 60, X11Color("red"))
gg.addActor(Bear(), Location(0, 0))
for i in range(10):
    gg.addActor(Leaf(), gg.getRandomEmptyLocation())
gg.show()
Exemple #2
0
class Rock(Actor):
    def __init__(self):
        Actor.__init__(self, "sprites/rock.gif")


# --------------------- class Hazelnut -----------------------
class Hazelnut(Actor):
    def __init__(self):
        Actor.__init__(self, "sprites/hazelnut.gif")


# --------------------- class MyButtonListener ----------------
class MyButtonListener(GGButtonListener):
    def buttonClicked(self, button):
        gg.dispose()


# ----------------- main -----------------------------
exitButton = GGButton("sprites/ggExitButtonA.gif")
gg = GameGrid(10, 10, 50, X11Color("green"), None, False, True)  # undecorated
gg.setBgColor(X11Color("darkGray"))
gg.addActor(exitButton, Location(9, 9))
exitButton.addButtonListener(MyButtonListener())
for i in range(10):
    gg.addActor(Rock(), gg.getRandomEmptyLocation())
for i in range(20):
    gg.addActor(Hazelnut(), gg.getRandomEmptyLocation())
gg.addActor(Hamster(), gg.getRandomEmptyLocation())
gg.show()
gg.doRun()