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 dealingOut(): global hands global talon cg.setStatusText("Dealing out in batches...") hands = deck.dealingOut(nbPlayers, 0) # All cards in shuffled talon talon = hands[nbPlayers] for i in range(nbPlayers): hands[i].setView(cg, RowLayout(handLocations[i], 300, 90 * i)) hands[i].draw() talonCover = CardCover(cg, talonLocation, deck, 1, 0) while not talon.isEmpty() and not cg.isDisposed(): for i in range(nbPlayers): for k in range(packetSize): hands[i].insert(talon.getLast(), False) talon.removeLast(False) cardCover = CardCover(cg, talonLocation, deck, 1, 0) cardCover.slideToTarget(handLocations[i], 10, True, True) cardCover.removeSelf() if i == 0: hands[i].setVerso(False) hands[i].sort(SortType.RANKPRIORITY, False) else: hands[i].setVerso(True) hands[i].draw() talonCover.removeSelf() hands[0].setTouchEnabled(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)
class MyMouseListener(GGMouseListener): def mouseEvent(self, mouse): Monitor.wakeUp() return 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(900, 615, 30) cg.addMouseListener(MyMouseListener(), GGMouse.lPress) while True: hand = deck.dealingOut(1, 25)[0] hand.setView(cg, RowLayout(Location(450, 80), 890)) hand.sort(SortType.RANKPRIORITY, True) sequence3 = hand.extractSequences(Suit.HEARTS, 3) for i in range(len(sequence3)): sequence3[i].setView(cg, RowLayout(Location(70 + 150 * i, 230), 120)) sequence3[i].draw() sequence4 = hand.extractSequences(Suit.HEARTS, 4) for i in range(len(sequence4)): sequence4[i].setView(cg, RowLayout(Location(70 + 150 * i, 380), 120)) sequence4[i].draw() sequence5 = hand.extractSequences(Suit.HEARTS, 5) for i in range(len(sequence5)): sequence5[i].setView(cg, RowLayout(Location(100 + 200 * i, 530), 150))
deck.getRank(id) card = Card(deck, deck.getSuit(i), deck.getRank(id)) break return card # ------------------------ main -------------------------------------------- Suit = enum("SPADES", "HEARTS", "DIAMONDS", "CLUBS") Rank = enum("ACE", "KING", "QUEEN", "JACK", "TEN", "NINE", "EIGHT", "SEVEN", "SIX", "FIVE", "FOUR", "THREE", "TWO") nbRanks = len(Rank.values()) deck = Deck(Suit.values(), Rank.values(), "cover") hand = Hand(deck) sortBtn = None textItem = ToolBarText("Select Card:", 30) separator0 = ToolBarSeparator(2, 30, X11Color("black")) spades = ToolBarStack("sprites/spades.gif", nbRanks) hearts = ToolBarStack("sprites/hearts.gif", nbRanks) diamonds = ToolBarStack("sprites/diamonds.gif", nbRanks) clubs = ToolBarStack("sprites/clubs.gif", nbRanks) separator1 = ToolBarSeparator(2, 30, X11Color("black")) okBtn = ToolBarItem("sprites/ok30.gif", 2) cg = CardGame(300, 250, 30) cg.setStatusText("Select a card by clicking on the card stacks and press OK.") hand.setView(cg, RowLayout(Location(150, 125), 290)) hand.draw() initToolBar()
# 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 mouseEvent(self, mouse): Monitor.wakeUp() return 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(900, 615, 30) cg.addMouseListener(MyMouseListener(), GGMouse.lPress) while True: hand = deck.dealingOut(1, 25)[0] rowLayout = RowLayout(Location(450, 80), 890) hand.setView(cg, rowLayout) hand.sort(SortType.RANKPRIORITY, True) hand.draw() cg.setStatusText("Click to get pairs, trips and quads") Monitor.putSleep() if cg.isDisposed(): break pairs = hand.extractPairs() for i in range(len(pairs)): pairs[i].setView(cg, RowLayout(Location(70 + 150 * i, 230), 120)) pairs[i].draw() trips = hand.extractTrips() for i in range(len(trips)): trips[i].setView(cg, RowLayout(Location(70 + 150 * i, 380), 120))
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")
toolBar = ToolBar(cg) toolBar.addItem(upBtn, numbers, downBtn) toolBar.show(Location(160, 185)) numbers.show(3) # Default start number toolBar.addToolBarListener(MyToolBarListener()) def sortAndDrawHands(): upperHand.sort(SortType.RANKPRIORITY, True) lowerHand.sort(SortType.RANKPRIORITY, 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") upBtn = None downBtn = None numbers = None cg = CardGame(460, 400) hands = deck.dealingOut(2, 5, True) upperHand = hands[0] upperHand.setView(cg, RowLayout(Location(230, 100), 400)) lowerHand = hands[1] lowerHand.setView(cg, RowLayout(Location(230, 300), 400)) sortAndDrawHands() initToolBar()
# Ex01.py from ch.aplu.jgamegrid import Location from ch.aplu.jcardgame import Deck, CardGame, RowLayout, ColumnLayout, FanLayout # ------------------------ 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(4, 5) rowLayout0 = RowLayout(Location(150, 520), 300) hands[0].setView(cg, rowLayout0) hands[0].draw() rowLayout1 = RowLayout(Location(150, 370), 300) rowLayout1.setStepDelay(10) hands[1].setView(cg, rowLayout1) hands[1].draw() columnLayout0 = ColumnLayout(Location(370, 390), 400) hands[2].setView(cg, columnLayout0) hands[2].draw() columnLayout1 = ColumnLayout(Location(470, 390), 400) columnLayout1.setScaleFactor(0.7) columnLayout1.setStepDelay(10) hands[3].setView(cg, columnLayout1)