|
Games::Cards::Tk - Package to write Tk ports for Games::Cards card games |
Games::Cards::Tk - Package to write Tk ports for Games::Cards card games
See the Games::Cards manpage 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 (oxymoron@waste.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.
set_canvas(Canvas)
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_front and Tk_truename_back return tags that will access just the front or back image.
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:
Also delta_y and border_y. Fields are changed by the ``attributes'' method.
attributes(HASHREF)|
Games::Cards::Tk - Package to write Tk ports for Games::Cards card games |