man Games::Cards::Tk () - Package to write Tk ports for Games::Cards card games
NAME
Games::Cards::Tk - Package to write Tk ports for Games::Cards card games
SYNOPSIS
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;
DESCRIPTION
WARNING!!!
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.
Overview
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 (oxymoron@waste.org).
Class Games::Cards::Tk::Game
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.
- card_width
- card_height
- The size of card images
- load_card_images
- Loads the card images and stores them to draw later.
- card_image
- Returns the card image associated with this card.
- get_card_by_tag
- Given a tag, return the Card (on this Games' canvas) that has that tag, if any.
- get_card_by_tag
- Given a tag, return the CardSet (on this Games' canvas) that has that tag, if any.
- get_marked_card
- Is a card marked? If so, return it.
- get_clicked_cardset
- 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.
- canvas
- set_canvas(Canvas)
- Return/set the Tk::Canvas associated with this Game
Class Games::Cards::Tk::Card
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.
- Tk_truename
- 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
- Draw a card for the first time. Note that this draws the front and back rectangle. The card is placed at 0,0.
- mark
- Mark a card. This is currently done by placing a black rectangle around it.
- unmark
- Unmark a card that was marked with the mark method.
- place(X, Y)
- Put a Card's images at X, Y.
- redraw
- Redraw (i.e. raise) the card & make sure you're showing front/back correctly.
Class Games::Cards::Tk::Deck
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.
Class Games::Cards::Tk::CardSet
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:
- delta_x
- 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.
- border_x
- 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.
- attributes(HASHREF)
- 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
- Redraw the Cards in this CardSet. This is the reason you have to set things like delta_y and border_x.