Games-Cards-1.45 > Games::Cards::Tk
Games-Cards-1.45

名前

Games::Cards::Tk - Package to write Tk ports for Games::Cards card games

Games::Cards::Tk - Games::CardsのTk用パッケージ

概要

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.

このモジュールはアルファ版++である。このモジュールの大部分は私がTkを学ぶにつれ変更されていく可能性が高い。そしてもしあなたがこのパッケージに含まれているのとは全然違ったゲームを書こうとするなら、このモジュールは破綻するかもしれない。よりよいモジュール化、抽象化、そして、よりよいコードへとする必要のあることはまだ残っている。だが、現在のゲームは、最初の試みとしては非常にうまくいっているようにみえる。私が本当に馬鹿なことをしているようなら、ぜひコメントを頂きたい。

概観

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.

Games::Cardsの全てのクラスは、対応するGames::Cards::Tkクラスを持っている。 クラスは、Tkのクラスを除いて正確に同じものを意味し、画面上を移動するカードの画像も扱う。

The card images used were created by Oliver Xymoron (oxymoron@waste.org).

利用したカード画像は、Oliver Xymoron (oxymoron@waste.org)によって作成された。

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.

タグを与えると、そのタグを持っている(このGameのキャンバス上にある)Cardを返す。

get_card_by_tag

Given a tag, return the CardSet (on this Games' canvas) that has that tag, if any.

タグを与えると、そのタグを持っている(このGameのキャンバス上にある)CardSetを返す。 [訳補足:get_cardset_by_tagが正しい]

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

このゲームに関連付けられたTk::Canvasを返す。あるいはセットする。

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).

CardはGC::Tkにおいて二つの矩形、すなわち前側と後ろ側を表す。これは常に一緒に移動する。前側、あるいは後ろ側の矩形を起こすことによってカードを「ひっくり返す」ことができる(face_up/face_downメソッドはこれを自動でやってくれる)。

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.

メソッドの多くは基本的にGames::Cards::Cardのメソッドと同じものである。我々はいくつかのGUI用の変更を付け加えるだけでいい。しかしまた、Tkに特化したメソッドもある。

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.)

このメソッドはひとつのCardに属することを保証するTkタグを返す(しかし、このタグはそのカードの前後の矩形を含むことに注意)。

Tk_truename_front and Tk_truename_back return tags that will access just the front or back image.

Tk_truename_frontとTk_truename_backはそれぞれ前側・後ろ側の画像にアクセスするタグを返す。

draw

Draw a card for the first time. Note that this draws the front and back rectangle. The card is placed at 0,0.

最初にカードを描画する。このメソッドは前川と後ろ側の矩形を描画することに注意すること。カードは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.

"mark"メソッドでマークされたカードを解除する。

place(X, Y)

Put a Card's images at X, Y.

Card画像をX,Yに置く。

redraw

Redraw (i.e. raise) the card & make sure you're showing front/back correctly.

カードを再描画(つまりraise)し、正しく前後を表示してることを確認する。

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.

このクラスはそれほど興味深いものではない。主要なポイントは、Games::Cards::Deck::newの代わりにこのクラスのnewを呼ぶことによって、通常のカードではなくGames::Cards::Tk::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.

このクラスはTk用CardSetを扱うための追加メソッドを用意している。すなわち、カードの列・行・山・手持ちを描画する。

There are a few extra fields in the Tk version of the class:

Tk用の追加メソッド:

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.

CardSet内における、カードの右側とその隣のカードの右側との距離x。カードを完全に重ねたいなら値は0になる。ある程度重ねたいならカードサイズよりピクセルを小さく。全く重ねたくないならカードサイズより大きな値を。

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.

delta_yとborder_yもある。"attributes"メソッドを使ってフィールドの値は変更される。

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.

これは一発でCardSetの属性をセットするうまいやり方だ。セット可能な属性:delta_x/yとborder_x/y。ハッシュリファレンスのキーは属性名で、値はセットするべきもの。

redraw

Redraw the Cards in this CardSet. This is the reason you have to set things like delta_y and border_x.

このCardSetにあるCardの再描写。これがdelta_yとborder_xのようなものをセットしなければならない理由だ。

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 340:

=over without closing =back