Games::Cards::Tk - Package to write Tk ports for Games::Cards card games
See Games::Cards for all the non-GUI aspects of writing card games.
use Games::Cards; use Games::Cards::Tk; # Create a canvas and print background etc. $My_Game->set_canvas($c); # my game will use canvas $c # ... do lots of things you do in Games::Cards anyway # Cards' Tk images will be moved automatically! $Stock->give_cards($Waste, 3); # Mark clicked card $card = $My_Game->get_card_by_tag("current"); $card->mark;
This module is doubleplus alpha. It's entirely possible that large parts of it will be changing as I learn more Tk, and if you try to write a game that's much different from the included games, it may break. There's still some stuff that needs to be better modularized, abstracted, and otherwise made into good code. However, the current games seem to be pretty good for a first try, and I'd like to get comments in case I'm doing anything really stupid.
Each class in Games::Cards had a corresponding Games::Cards::Tk class. The classes are meant to be exactly the same, except that the Tk ones also take care of moving actual card images around the screen.
The card images used were created by Oliver Xymoron (firstname.lastname@example.org).
This class ends up holding information - such as the canvas that the game is played on, card images - and methods like finding a card given its tag.
The size of card images
Loads the card images and stores them to draw later.
Returns the card image associated with this card.
Given a tag, return the Card (on this Games' canvas) that has that tag, if any.
Given a tag, return the CardSet (on this Games' canvas) that has that tag, if any.
Is a card marked? If so, return it.
Return the set which was clicked on. Do so by looking for the "current" tag, but note that that tag may apply either to a CardSet or to a Card in that set.
Return/set the Tk::Canvas associated with this Game
A Card is represented in GC::Tk as two rectangles, the front and back, which are always moved around together. The card is "turned over" by raising the front or back rectangle (but the face_up/face_down methods do that automatically for you).
Lots of methods are basically the same as Games::Cards::Card methods. We just have to add some GUI changes. But there are also some Tk-specific methods.
This returns a Tk tag that's guaranteed to belong to just one Card. (However, note this tag will include the card's front and back rectangles.)
Tk_truename_front and Tk_truename_back return tags that will access just the front or back image.
Draw a card for the first time. Note that this draws the front and back rectangle. The card is placed at 0,0.
Mark a card. This is currently done by placing a black rectangle around it.
Unmark a card that was marked with the "mark" method.
Put a Card's images at X, Y.
Redraw (i.e. raise) the card & make sure you're showing front/back correctly.
This class exists but isn't terribly interesting. The main point is that by calling this class' new instead of Games::Cards::Deck::new, you automatically get a deck filled with Games::Cards::Tk::Cards instead of regular cards.
This class has extra methods to do Tk stuff to CardSets, i.e. drawing columns, rows, piles, hands of cards.
There are a few extra fields in the Tk version of the class:
x distance between right side of one card and the next in the Set. 0 if you want the cards to totally overlap, some number of pixels smaller than a card if you want them to overlap some, larger than cardsize if you want them to not overlap at all.
A column may be slightly wider/higher than the cards in it, for example.
Also delta_y and border_y. Fields are changed by the "attributes" method.
This is a copout way of setting a bunch of CardSet attributes in one shot. Settable attributes include: delta_x/y and border_x/y. Hashref's keys are attributes and values are things to set them to.
Redraw the Cards in this CardSet. This is the reason you have to set things like delta_y and border_x.