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()
from ch.aplu.jcardgame import Deck, CardGame, RowLayout, Hand from ch.aplu.jcardgame.Hand import SortType from ch.aplu.util import Monitor # ------------------ class MyMouseListener --------------------------------- 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))
# 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)
# ------------------ global functions -------------------------------------- def initToolBar(): global cutBtn global numbers numbers = ToolBarStack("sprites/number30.gif", 10) separator = ToolBarSeparator(2, 30, X11Color("black")) cutBtn = ToolBarItem("sprites/cutBtn.gif", 3) toolBar = ToolBar(cg) toolBar.addItem(numbers, separator, cutBtn) toolBar.show(Location(7, 160)) toolBar.addToolBarListener(MyToolBarListener()) # ------------------------ 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") hand = deck.dealingOut(1, 5, True)[0] cutBtn = None numbers = None cg = CardGame(300, 200) hand.setView(cg, RowLayout(Location(150, 80), 290)) hand.draw() initToolBar()
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) toolBar = ToolBar(cg) toolBar.addItem(spadeItem, heartItem, diamondItem, clubItem) toolBar.show(hideLocation) toolBar.addToolBarListener(MyToolBarListener()) while not cg.isDisposed(): isGameOver = False
# ------------------ class MyMouseListener --------------------------------- 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] 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()
Location(525, 300), Location(300, 300) ] bidLocations = [ Location(300, 350), Location(250, 300), Location(300, 250), Location(350, 300) ] stockLocations = [ Location(400, 500), Location(100, 400), Location(200, 100), Location(500, 200) ] hands = None bids = [0] * nbPlayers stocks = [0] * nbPlayers talon = None currentPlayer = 0 nbMovesInRound = 0 targetCount = 0 cg = CardGame(600, 600, 30) dealingOut() cg.setStatusText("Dealing out...done. Double click to play.") initBids() initStocks() hands[0].setTouchEnabled(True)
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")
hands[i].sort(SortType.RANKPRIORITY, False) else: hands[i].setVerso(True) hands[i].draw() talonCover.removeSelf() hands[0].setTouchEnabled(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") hands = None talon = None nbPlayers = 4 handLocations = [ Location(300, 525), Location(75, 300), Location(300, 75), Location(525, 300) ] talonLocation = Location(300, 300) packetSize = 3 cg = CardGame(600, 600, 30) dealingOut() cg.setStatusText("Dealing Out...done")
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)