Example #1
0
def messageReceived(sender, message):
    print "Got message: " + message
    global isMyMove, enemyScore, myScore, loc

    x = ord(message[0]) - 48  # We get ASCII code of number
    y = ord(message[1]) - 48

    if x == 9:  # Got command
        if y == GAME_START:
            isMyMove = False
            gg.setTitle("Wait! Enemy shoots first.")
        if y == SHIP_HIT:
            gg.addActor(Actor("sprites/checkgreen.gif"), loc)
            myScore += 1
            if myScore == nbShips:
                gameOver(True)
        if y == SHIP_MISSED:
            gg.addActor(Actor("sprites/checkred.gif"), loc)
    else:  # Got coordinates
        loc = Location(x, y)
        actor = gg.getOneActorAt(loc, Ship)
        if actor != None:
            actor.removeSelf()
            gg.addActor(Actor("sprites/explosion.gif"), loc)
            tcpNode.sendMessage("9" + str(SHIP_HIT))
            enemyScore += 1
            if enemyScore == nbShips:
                gameOver(False)
                return
        else:
            tcpNode.sendMessage("9" + str(SHIP_MISSED))

        gg.setTitle("Shoot now! Score: " + str(myScore) + " (" +
                    str(enemyScore) + ")")
        isMyMove = True
Example #2
0
 def move(self, dist):
    pt = gg.toPoint(self.getNextMoveLocation())
    dir = self.getDirection()
    if pt.x < 0 or pt.x > gg.getPgWidth():
       self.setDirection(180 - dir)
       self.setHorzMirror(not self.isHorzMirror())
    if pt.y < 0 or pt.y > gg.getPgHeight():
       self.setDirection(360 - dir)
    Actor.move(self, dist)
Example #3
0
def getTrumpActor(suit):
    if suit == Suit.CLUBS:
        return Actor("sprites/bigclub.gif")
    if suit == Suit.HEARTS:
        return Actor("sprites/bigheart.gif")
    if suit == Suit.DIAMONDS:
        return Actor("sprites/bigdiamond.gif")
    if suit == Suit.SPADES:
        return Actor("sprites/bigspade.gif")
    return None
Example #4
0
def getTrumpActor(suit):
    if suit == Suit.KREUZ:
        return Actor("sprites/bigclub.gif")
    if suit == Suit.HERZ:
        return Actor("sprites/bigheart.gif")
    if suit == Suit.KARO:
        return Actor("sprites/bigdiamond.gif")
    if suit == Suit.PIK:
        return Actor("sprites/bigspade.gif")
    return None
Example #5
0
def gameOver(isWinner):
    global isMyMove
    isMyMove = False
    gg.removeAllActors()
    gg.addActor(Actor("sprites/gameover.gif"), Location(3, 3))
    if isWinner:
        gg.setTitle("You win!")
    else:
        gg.setTitle("You lost!")
Example #6
0
def checkOver(nbPlayer):
    if hands[nbPlayer].isEmpty():
        cg.addActor(Actor("sprites/gameover.gif"), textLocation)
        cg.setStatusText("Game over. Winner is player: " + str(nbPlayer))
        for i in range(nbPlayers):
            hands[i].setVerso(False)  # Show player hands
        cg.refresh()
        cg.setMouseEnabled(False)
        cg.doPause()
        return True
    return False
Example #7
0
def checkTalon():
    # Returns false, if check fails because there are no cards available
    if talon.isEmpty():  # Talon empty, need to shuffle
        if pile.getNumberOfCards() < 2:
            cg.setStatusText("Fatal error: No cards available for talon")
            doPause()
            cg.setMouseEnabled(False)
            return False

        # Show info text
        actor = Actor("sprites/reshuffle.gif")
        cg.addActor(actor, textLocation)

        # Move animated card cover from playing pile to talon
        cardCover = CardCover(cg, pileLocation, deck, 1, 0, False)
        cardCover.slideToTarget(talonLocation, 2, False, True)  # On bottom

        # Save card on pile top and remove it
        topCard = pile.getLast()
        pile.remove(topCard, False)
        # Shuffle cards
        pile.shuffle(False)
        # Hide all pictures
        pile.setVerso(True)
        # Insert into talon
        for card in pile.getCardList():
            talon.insert(card, False)
        #  Cleanup playing pile
        pile.removeAll(False)
        # Insert saved card
        pile.insert(topCard, False)
        # Redraw piles
        pile.draw()
        talon.draw()

        # Remove info text
        cg.delay(1000)
        actor.removeSelf()
    return True
Example #8
0
nbPlayers = 4

if isDebug:
    nbStartCards = 3
else:
    nbStartCards = 5
handWidth = 300
trumpActor = None
trump = None
hands = None
talon = None
thinkingTime = 1200  # ms
pile = Hand(deck)
isPartnerMoves = False
okBtn = GGButton("sprites/done30.gif", True)
toolBarTextActor = Actor("sprites/text_item.png")
spadeItem = ToolBarItem("sprites/spades_item.png", 2)
heartItem = ToolBarItem("sprites/hearts_item.png", 2)
diamondItem = ToolBarItem("sprites/diamonds_item.png", 2)
clubItem = ToolBarItem("sprites/clubs_item.png", 2)
Item = ToolBarItem("sprites/clubs_item.png", 2)

cg = CardGame(600, 600, 30)
cg.setTitle("Mau-Mau (V" + version +
            ") constructed with JGameGrid (www.aplu.ch)")
cg.setStatusText("Initializing...")
initHands()
cg.addActor(okBtn, hideLocation)
okBtn.addButtonListener(MyButtonListener())
toolBarTextActor.hide()
cg.addActor(toolBarTextActor, toolBarTextLocation)
Example #9
0
 def __init__(self):
     Actor.__init__(self, "sprites/hamster.gif")
Example #10
0
 def __init__(self, bulb):
     Actor.__init__(self, "sprites/switch.gif", 2)
     self.bulb = bulb
Example #11
0
 def __init__(self):
    Actor.__init__(self, "sprites/bear.gif")
Example #12
0
 def __init__(self):
     nbSprites = 18
     Actor.__init__(self, "sprites/earth.gif", nbSprites)
     self.setSlowDown(6)
Example #13
0
 def __init__(self):
     Actor.__init__(self, "sprites/rocket.gif")
Example #14
0
 def __init__(self):
     Actor.__init__(self, "sprites/nemo.gif")
Example #15
0
 def __init__(self):
     Actor.__init__(self, "sprites/boat.gif")
Example #16
0
 def __init__(self, sprite, clazz):
    Actor.__init__(self, sprite)
    self.clazz = clazz
Example #17
0
 def __init__(self):
     Actor.__init__(self, "sprites/ghost.gif", 4)
Example #18
0
 def __init__(self):
     Actor.__init__(self, "sprites/leaf.gif")
Example #19
0
#GameGridEx2.py

from ch.aplu.jgamegrid import GameGrid,\
   Actor, Location


# ---------------- class MyGame -------------------
class MyGame(GameGrid):
    def __init__(self):
        GameGrid.__init__(self, 10, 10, 60, GameGrid.RED, "sprites/reef.gif")
        self.addActor(nemo, Location(2, 4))
        self.show()


def act(self):
    nemo.move()
    if not nemo.isMoveValid():
        nemo.turn(180)
        nemo.setHorzMirror(not nemo.isHorzMirror())


# ---------------- main --------------------------
nemo = Actor("sprites/nemo.gif")
MyGame()
Example #20
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)
    # Play ping
    dart.setLocation(dart.getLocationStart())  # Init dart
Example #21
0
 def __init__(self):
    Actor.__init__(self, "sprites/honey.gif")
    self.isDragging = False
Example #22
0
 def __init__(self):
     Actor.__init__(self, True, "sprites/dart.gif")  # Rotatable
     self.oldLocation = Location()
Example #23
0
 def __init__(self, isRotatable, imagePath, nbSprites):
    Actor.__init__(self, isRotatable, imagePath, nbSprites)
Example #24
0
 def __init__(self):
    Actor.__init__(self, "sprites/angelfish.gif")
Example #25
0
 def __init__(self, type):
     Actor.__init__(self, "sprites/bulb" + str(type) + ".gif", 2)
Example #26
0
 def __init__(self):
     Actor.__init__(self, "sprites/hazelnut.gif")