Ejemplo n.º 1
0
from ch.aplu.jgamegrid import Location, GGMouseListener, GGMouse
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)
Ejemplo n.º 2
0
        id = ids[i]
        if (id != -1):  # Selected item found
            deck.getSuit(i)
            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))
Ejemplo n.º 3
0
# 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)
Ejemplo n.º 4
0
# Ex03.py

from ch.aplu.jgamegrid import Location, GGMouse, GGMouseTouchListener
from ch.aplu.jcardgame import Deck, CardGame, RowLayout, StackLayout
from ch.aplu.jcardgame.Hand import SortType
from java.awt import Point

Suit = enum("SPADES", "HEARTS", "DIAMONDS", "CLUBS")
Rank = enum("ACE", "KING", "QUEEN", "JACK", "TEN")
deck = Deck(Suit.values(), Rank.values(), "cover")


class MyMouseTouchListener(GGMouseTouchListener):
    def mouseTouched(self, actor, mouse, spot):
        global hotspot
        event = mouse.getEvent()
        if event == GGMouse.lPress:
            hotspot = spot
        if event == GGMouse.lDrag:
            actor.setLocation(
                Location(mouse.getX() - hotspot.x,
                         mouse.getY() - hotspot.y))
            if actor.getLocation().getDistanceTo(handLocation) < 50:
                insertInHand(actor)
        if event == GGMouse.lRelease:
            insertInHand(actor)


def takeFromTalon():
    top = talon.getLast()
    if top == None:  # talon empty
Ejemplo n.º 5
0
    return nbWinner


def showResult():
    text = "Game over. Summary: "
    for i in range(nbPlayers):
        text += "Player # " + str(i) + ": " + str(stocks[i].getScore())
        if i < nbPlayers - 1:
            text += "; "
    cg.setStatusText(text)


# ------------------------ main --------------------------------------------
Suit = enum("SPADES", "HEARTS", "DIAMONDS", "CLUBS")
Rank = enum("ACE", "KING", "QUEEN", "JACK", "TEN")
deck = Deck(Suit.values(), Rank.values(), "cover", MyCardValues())

nbPlayers = 4
handLocations = [
    Location(300, 525),
    Location(75, 300),
    Location(300, 75),
    Location(525, 300),
    Location(300, 300)
]
bidLocations = [
    Location(300, 350),
    Location(250, 300),
    Location(300, 250),
    Location(350, 300)
]
Ejemplo n.º 6
0
    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()