Ejemplo n.º 1
0
class Bulb(Actor):
    def __init__(self, type):
        Actor.__init__(self, "sprites/bulb" + str(type) + ".gif", 2)


# --------------------- class Switch --------------------------
class Switch(Actor, GGMouseListener):
    def __init__(self, bulb):
        Actor.__init__(self, "sprites/switch.gif", 2)
        self.bulb = bulb

    def mouseEvent(self, mouse):
        location = gg.toLocationInGrid(mouse.getX(), mouse.getY())
        if location.equals(self.getLocation()):
            self.showNextSprite()
        self.bulb.show(self.getIdVisible())
        gg.refresh()
        return False


# --------------------- main ---------------------------------
gg = GameGrid(7, 4, 40, False)
gg.setBgColor(X11Color("lightgray"))
for i in range(3):
    bulb = Bulb(i)
    gg.addActor(bulb, Location(2 * i + 1, 1))
    switch = Switch(bulb)
    gg.addActor(switch, Location(2 * i + 1, 3))
    gg.addMouseListener(switch, GGMouse.lPress)
gg.show()
Ejemplo n.º 2
0
        return 0


# --------------------- main ---------------------------------
gg = GameGrid(400, 300, 1, False)
gg.setTitle("Move dart using mouse left button drag")
gg.setSimulationPeriod(50)
gg.setBgColor(X11Color("lightblue"))
gg.playSound(GGSound.DUMMY)

dart = Dart()
dart.setCollisionSpot(Point(30, 0))
dart.addActorCollisionListener(MyActorCollisionListener())

gg.addActor(dart, Location(50, 50))
gg.addMouseListener(dart, GGMouse.lDrag)

balloon = Actor("sprites/balloon.gif", 2)
gg.addActor(balloon, Location(300, 200))
balloon.setCollisionImage(0)  # Select IMAGE type detection
dart.addCollisionActor(balloon)
gg.show()
gg.doRun()

while True:
    Monitor.putSleep()
    if gg.isDisposed():
        break
    dart.hide()  # Hide dart
    balloon.show(1)  # Show exlode image
    gg.playSound(GGSound.PING)
Ejemplo n.º 3
0
         else:  # at right border
            self.setHorzMirror(True)
            self.turn(90)
            self.move()
            self.turn(90)
      self.tryToEat()

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

# --------------------- class MyMouseListener --------------------------
class MyMouseListener(GGMouseListener):
   def mouseEvent(self, mouse):
      location = gg.toLocationInGrid(mouse.getX(), mouse.getY())
      if gg.isEmpty(location):  # Do not create an actor if cell is occupied
         honey = Honey()
         gg.addActor(honey, location);
         gg.addMouseListener(honey, GGMouse.lPress | GGMouse.lDrag | GGMouse.lRelease)
      return False  # Don't consume the event, other listeners must be notified
 
# --------------------- main ---------------------------------
gg = GameGrid(10, 10, 60, X11Color("green"), False)
gg.setTitle("Click to create a honey pot, press and drag to move it")
gg.addActor(Bear(), Location(0, 0))
gg.addMouseListener(MyMouseListener(), GGMouse.lPress)
gg.show()
gg.doRun()

Ejemplo n.º 4
0
    tcpNode.disconnect()
    gg.dispose()


def deployShips():
    for i in range(nbShips):
        gg.addActor(Ship(), gg.getRandomEmptyLocation())


# ---------- main() ----------------------
sessionPrefix = "ama&19td"
nickname = "captain"
tcpNode = TcpNode(messageReceived=messageReceived,
                  statusReceived=statusReceived)
isMyMove = False
nbShips = 7
loc = None
myScore = 0
enemyScore = 0

GAME_START = 0
SHIP_MISSED = 1
SHIP_HIT = 2

gg = GameGrid(6, 6, 50, X11Color("red"), False, notifyExit=notifyExit)
gg.setTitle("TcpBattleShip")
deployShips()
gg.addMouseListener(MyMouseListener(), GGMouse.lClick)
gg.show()
connect()