def initHands(): global talon global hands hands = deck.dealingOut(nbPlayers, nbStartCards, not isDebug) talon = hands[nbPlayers] top = talon.getLast() talon.remove(top, True) pile.insert(top, True) hands[0].sort(SortType.SUITPRIORITY, True) layouts = [0] * nbPlayers for i in range(nbPlayers): layouts[i] = RowLayout(handLocations[i], handWidth) layouts[i].setRotationAngle(90 * i) hands[i].setView(cg, layouts[i]) hands[i].setTargetArea(TargetArea(pileLocation)) if i == 0: layouts[i].setStepDelay(10) hands[i].draw() layouts[0].setStepDelay(0) for i in range(1, nbPlayers + 1): hands[i].setVerso(True) talon.setView(cg, StackLayout(talonLocation)) talon.draw() pile.setView(cg, StackLayout(pileLocation)) pile.draw() hands[0].addCardListener(MyHandsCardListener()) talon.addCardListener( MyTalonCardListener()) # Player 0 reclaims card from talon setMyMove()
def initBids(): for i in range(nbPlayers): bids[i] = Hand(deck) bids[i].setView(cg, StackLayout(bidLocations[i])) bids[i].addCardListener(BitsCardListener()) hands[i].setTargetArea(TargetArea(bidLocations[i])) hands[i].addCardListener(HandsCardListener(i))
def initStocks(): for i in range(nbPlayers): stocks[i] = Hand(deck) if i == 0 or i == 2: rotationAngle = 0 else: rotationAngle = 90 stocks[i].setView(cg, StackLayout(stockLocations[i], rotationAngle))
def dealingOut(): global hands global talon cg.setStatusText("Dealing out...") hands = deck.dealingOut(nbPlayers, 0) # All cards in talon talon = hands[nbPlayers] talon.setVerso(True) for i in range(nbPlayers): hands[i].setView(cg, StackLayout(handLocations[i], 90 * i)) hands[i].draw() talon.setView(cg, StackLayout(handLocations[nbPlayers])) talon.draw() while not talon.isEmpty(): for i in range(nbPlayers): top = talon.getLast() if i == 0: top.setVerso(False) else: top.setVerso(True) talon.transfer(top, hands[i], True)
def dealingOut(): cg.setStatusText("Dealing Out...") hands = deck.dealingOut(nbPlayers, 0) # All cards in talon talon = hands[nbPlayers] for i in range(nbPlayers): hands[i].setView(cg, RowLayout(handLocations[i], 300, 90 * i)) hands[i].draw() hands[i].setTouchEnabled(True) talon.setView(cg, StackLayout(handLocations[nbPlayers])) talon.draw() while not talon.isEmpty() and not cg.isDisposed(): for i in range(nbPlayers): top = talon.getLast() talon.transfer(top, hands[i], False) hands[i].sort(SortType.RANKPRIORITY, True)
# Ex02.py from ch.aplu.jgamegrid import Location from ch.aplu.jcardgame import Deck, CardGame, RowLayout, StackLayout, CardListener from ch.aplu.jcardgame.Hand import SortType # ------------------ class MyCardListener ---------------------------------- class MyCardListener(CardListener): def leftDoubleClicked(self, card): card.transfer(stock, True) # ------------------------ main -------------------------------------------- Suit = enum("SPADES", "HEARTS", "DIAMONDS", "CLUBS") Rank = enum("ACE", "KING", "QUEEN", "JACK", "TEN", "NINE", "EIGHT", "SEVEN", "SIX") deck = Deck(Suit.values(), Rank.values(), "cover"); cg = CardGame(600, 600) hands = deck.dealingOut(1, 9) stock = hands[1] stock.setView(cg, StackLayout(Location(300, 150))) stock.draw() hands[0].setView(cg, RowLayout(Location(300, 400), 500)) hands[0].sort(SortType.SUITPRIORITY, False) hands[0].draw() hands[0].addCardListener(MyCardListener()) hands[0].setTouchEnabled(True) cg.setDoubleClickDelay(300)
def insertInHand(actor): actor.removeSelf() card = actor.getCard() hand.insert(card, False) hand.sort(SortType.RANKPRIORITY, True) takeFromTalon() def addActor(cardActor): cg.addActor(cardActor, Location(talonLocation)) cardActor.addMouseTouchListener( MyMouseTouchListener(), GGMouse.lPress | GGMouse.lDrag | GGMouse.lRelease, True) # ------------------------ main -------------------------------------------- handLocation = Location(250, 100) talonLocation = Location(250, 300) hotSpot = Point(0, 0) cg = CardGame(500, 400, 30) hands = deck.dealingOut(1, 2) # only two cards in hand hand = hands[0] hand.setView(cg, RowLayout(handLocation, 400)) talon = hands[1] talon.setView(cg, StackLayout(talonLocation)) hand.draw() talon.draw() takeFromTalon() cg.setStatusText("Drag cards from card talon to the hand")