1 |
=head1 名前 |
2 |
|
3 |
Games::Cards -- Perl module for writing and playing card games |
4 |
|
5 |
Games::Cards -- カードゲームを描画し、遊ぶためのPerlモジュール |
6 |
|
7 |
=head1 概要 |
8 |
|
9 |
use Games::Cards; |
10 |
my $Rummy = new Games::Cards::Game; |
11 |
|
12 |
# ラミーのための正しいデッキを生成 |
13 |
my $Deck = new Games::Cards::Deck ($Rummy, "Deck"); |
14 |
|
15 |
# デッキをシャッフルし、札捨て場を生成 |
16 |
$Deck->shuffle; |
17 |
my $Discard = new Games::Cards::Queue "Discard Pile"; |
18 |
|
19 |
# カードを配る |
20 |
foreach my $i (1 .. 3) { |
21 |
my $hand = new Games::Cards::Hand "Player $i" ; |
22 |
$Deck->give_cards($hand, 7); |
23 |
$hand->sort_by_value; |
24 |
push @Hands, $hand; |
25 |
} |
26 |
|
27 |
# 手札の表示 (例: "Player 1: AS 2C 3C 3H 10D QS KH") |
28 |
foreach (@Hands) { print ($_->print("short"), "\n") } |
29 |
|
30 |
$Hands[1]->give_a_card ($Discard, "8D"); # ダイヤの8を捨てる |
31 |
|
32 |
=head1 解説 |
33 |
|
34 |
This module creates objects and methods to allow easier programming of card |
35 |
games in Perl. It allows you to do things like create decks of cards, |
36 |
have piles of cards, hands, and other sets of cards, turn cards face-up |
37 |
or face-down, and move cards from one set to another. Which is pretty much |
38 |
all you need for most card games. |
39 |
|
40 |
このモジュールは、Perlでカードゲームのプログラミングを容易にしてくれる |
41 |
オブジェクトとメソッドを生成する。このモジュールを使えば、カード一揃いの生成、 |
42 |
カードのやま・手札・その他のカードの組を持つこと、カードをめくること、 |
43 |
一方から他方の組へとカードを移すことなどが可能になる。これは、大概の |
44 |
カードゲームであなたが必要とすることだ。 |
45 |
|
46 |
Sub-packages include: |
47 |
|
48 |
サブパッケージには以下のものが含まれる: |
49 |
|
50 |
=over 4 |
51 |
|
52 |
=item Games::Cards::Undo |
53 |
|
54 |
This package handles undoing and redoing moves (important for solitaire). |
55 |
|
56 |
このパッケージはやり直し操作と繰り返し操作を行う(ソリティアには重要だ)。 |
57 |
|
58 |
=item Games::Cards::Tk |
59 |
|
60 |
This package allows you to write games that use a Tk graphical interface. |
61 |
It's designed so that it will be relatively easy to write a game that uses |
62 |
i<either> a GUI or a simple text interface, depending on the player's |
63 |
circumstances (availability of Tk, suspicious boss, etc.). See |
64 |
L<Games::Cards::Tk> for more details on writing Tk games. |
65 |
|
66 |
このパッケージを使うとTkインターフェースを利用してゲームを描画することができる。 |
67 |
プレーヤーの環境(Tkが利用できるか、疑い深い上司がいるか、等々)に応じて、 |
68 |
GUIあるいは単純なテキストインターフェースのI<どちらかを>使って比較的簡単に |
69 |
ゲームを描画できるように設計されている。Tkゲームの描画に関する詳細は |
70 |
L<Games::Cards::Tk>を参照して欲しい。 |
71 |
|
72 |
|
73 |
=back |
74 |
|
75 |
=head2 クラスの概観 |
76 |
|
77 |
A GC::Game stores information like what cards are in the starting deck, |
78 |
plus pointers to the various Cards and CardSets. |
79 |
|
80 |
GC::Game(Games::Cards::Game)は開始時のデッキにどんなカードが含まれているのか |
81 |
といった情報を保持し、様々なCardとCardSetへのポインタを付け加える。 |
82 |
|
83 |
A GC::Card represents one playing card. Every Card must belong to one |
84 |
(and only one) CardSet at every point during the game. |
85 |
|
86 |
GC::Cardは一枚のプレイ中のカードを表す。全てのCardはゲーム通じて |
87 |
一組の(そして唯一の)CardSetに属さねばならない。 |
88 |
|
89 |
A GC::CardSet is mostly just a set of GC::Cards. A CardSet has a unique |
90 |
name. Many also have short nicknames, which make it easier to write games |
91 |
that move cards between the sets. (See Klondike or FreeCell, for example.) |
92 |
|
93 |
GC::CardSetはGC::Cardの一組だ。CardSetは一意の名前を持つ。多くは短い |
94 |
ニックネームも持っている。カードの組をまたいで移動するゲームをつくる |
95 |
のを簡単にしてくれる(例えば、クロンダイクやフリーセルをみよ)。 |
96 |
|
97 |
|
98 |
There are many sorts of CardSet. The basic differentiation is Piles, |
99 |
for which you only access the top or bottom card (or cards) and Hands, |
100 |
where you might access any one of the cards in the Hand. Piles are |
101 |
broken up into Stacks and Queues, and every game starts with a Deck of |
102 |
cards (or more than one). |
103 |
|
104 |
たくさんの種類のCardSetがある。基本的な違いは、一番上あるいは下からカードを |
105 |
とるための「やま」(Pile)と、任意のカードを一枚引くための「手札」(Hand)だ。 |
106 |
PilesはStacksとQueuesに分かれる。そしてあらゆるゲームは(一枚以上の)カードの |
107 |
一揃い(Deck)から始まる。 |
108 |
|
109 |
=head2 Games::Cards::Game |
110 |
|
111 |
This class represents a certain game, like War, or Solitaire. This is |
112 |
necessary to store the various rules for a given game, like the ranking |
113 |
of the cards. (Or, for more exotic games, how many cards of what type are |
114 |
in the deck.) Methods: |
115 |
|
116 |
このクラスは戦争(War)とかソリティア(Solitaire)といった、ある一つのゲームを |
117 |
表す。これはゲームのための様々なルールを保持するのに必要である(あるいは、 |
118 |
よりエキゾチックなゲームの場合には、そのデックの中にどんな種類のカードが |
119 |
何枚入っているのかなど)。メソッド: |
120 |
|
121 |
=over 4 |
122 |
|
123 |
=item current_game |
124 |
|
125 |
Returns the current Game object. In almost every case, you'll only be |
126 |
working with one at a time. |
127 |
|
128 |
現在のGameオブジェクトを返す。ほとんど全ての場合において、一度に |
129 |
ひとつだけ動作させるだろう。 |
130 |
|
131 |
=item set_current_game(GAME) |
132 |
|
133 |
In theory, these subs let you handle multiple Games at once, as long |
134 |
as you set_current_game to the right one. Note that Game->new automatically |
135 |
sets the current Game to be that game, so in 99% of cases, you won't have to |
136 |
call set_current_game. |
137 |
|
138 |
理論的には、set_current_gameを正しく使う限り、このサブルーチンは一度に |
139 |
複数のGamesを操作できる。だが注意して欲しいのは、Game->newは自動的に |
140 |
そのゲームを現在のGameにセットするということだ。 |
141 |
だから九分九厘、あなたがset_current_gameを呼ぶことはないだろう。 |
142 |
|
143 |
|
144 |
=item new(HASHREF) |
145 |
|
146 |
creates a new game. HASHREF is a reference to a hash containing zero or more |
147 |
of the keys "suits" and "cards_in_suit". "suits" is a list of the suits in a |
148 |
deck, "cards_in_suit" is a reference to a hash whose keys are the names |
149 |
of the cards in one suit and whose values are the values (or ranks) of those |
150 |
cards. If "suits" is not given, the default suits (Clubs, Diamonds, Hearts, |
151 |
Spades) are used. If "cards_in_suit" is not given, the default cards |
152 |
(Ace, 2..10, Jack, Queen, King with values 1..13) are used. |
153 |
For example, war would require "Ace"=>14. |
154 |
|
155 |
新しいゲームを生成。HASHREFは0個以上のキー"suits"と"cards_in_suit"を含んだ |
156 |
ハッシュへのリファレンスだ。"suits"はデッキに含まれるスート(種類)のリスト。 |
157 |
"cards_in_suit"はスートに属するカードの名前がキーとなるハッシュへの |
158 |
リファレンスで、ハッシュの値はカードの値(ランク)である。 |
159 |
もし"suit"が与えられない場合、デフォルトのスート(Clubs、 Diamonds、 |
160 |
Hearts、Spades)が利用される。もし"cards_in_suit"が与えられない場合は、 |
161 |
デフォルトのカードは(Ace、2..10、Jack、Queen、Kingでその値は1〜13)が |
162 |
使われる。例えば、戦争というゲームは"Ace"=>14が必要となる。 |
163 |
|
164 |
=item get_cardset_by_name(NAME) |
165 |
|
166 |
Returns the CardSet with name NAME |
167 |
|
168 |
NAMEという名前を持ったCardSetを返す。 |
169 |
|
170 |
=item get_cardset_by_nickname(NAME) |
171 |
|
172 |
Returns the CardSet with nickname NAME |
173 |
|
174 |
NAMEという名前のnicknameを持ったCardSetを返す。 |
175 |
|
176 |
=item get_card_by_truename(NAME) |
177 |
|
178 |
Returns the Card with truename NAME |
179 |
|
180 |
NAMEという真の名前(truename)をもったCardを返す。 |
181 |
|
182 |
=back |
183 |
|
184 |
=head2 Games::Cards::Deck |
185 |
|
186 |
A deck is a deck of cards. The number of cards and identities of the cards in |
187 |
the deck depend on the particular Game for which the deck is used. |
188 |
|
189 |
デッキはカードの一揃いのことだ。デッキ中のカードの枚数とカードの特徴は、その |
190 |
デッキが利用されるゲームに依存する。 |
191 |
|
192 |
=over 4 |
193 |
|
194 |
=item new (GAME, NAME) |
195 |
|
196 |
creates an I<unshuffled> deck of cards. For each card in the deck it creates |
197 |
a name, suit, value, and suit value. GAME is the GC::Game this deck |
198 |
belongs to, and it stipulates the number of cards in the deck, etc. NAME is the |
199 |
name to give the deck, e.g. "Deck". |
200 |
|
201 |
I<シャッフルされていない>デッキを生成。デッキの中のそれぞれのカードのために、 |
202 |
名前、スート、値、そしてスートの値が生成される。GAMEはこのデッキが属する |
203 |
GC::Gameであり、その中に含まれるカードの番号その他を規定する。NAMEは与えられた |
204 |
デッキの名前だ。例えば、"Deck"。 |
205 |
|
206 |
=back |
207 |
|
208 |
=head2 Games::Cards::Queue |
209 |
|
210 |
A Queue (cf. computer science terminology, or the C++ stdlib) is a first-in |
211 |
first-out pile of cards. Cards are removed from the top of the pile, but new |
212 |
cards are added to the bottom of the pile. This might represent, say, a pile |
213 |
of face-down cards, like the player's hand in War. |
214 |
|
215 |
Queue(cf. コンピュータサイエンス、C++ stdlib)は先入先出型のカードの山だ。 |
216 |
カードは山の上から取り除かれ、新しいカードは山の下に付け加えられる。これは |
217 |
つまり、裏向きのカードの山で、Warでのプレーヤーの手札のようなものだ。 |
218 |
|
219 |
=head2 Class Games::Cards::Stack |
220 |
|
221 |
A stack (cf. computer science terminology, or the C++ stdlib) is a last-in |
222 |
first-out pile of cards. Cards are removed from the top of the pile, and new |
223 |
cards are also added to the top of the pile. This would usually represent a |
224 |
pile of cards with its top card (and perhaps all cards) face up. |
225 |
|
226 |
Stack(cf. コンピュータサイエンス、C++ stdlib)は後入先出型のカードの山だ。 |
227 |
カードは山の上から取り除かれ、新しいカードも山の上に付け加えられる。これは通常、 |
228 |
一番上のカードが(そしてたぶん全部のカードが)表向きになっている山を表すだろう。 |
229 |
|
230 |
=head2 Games::Cards::Pile |
231 |
|
232 |
A Pile is a pile of cards. That is, it is a CardSet where we will only access |
233 |
the beginning or end of the set. (This may include the first N cards in the |
234 |
set, but we will never reference the 17'th card.) This is a super class of |
235 |
Queue and Stack, and those classes should be used instead, so that we know |
236 |
whether the cards in the pile are FIFO or LIFO. Methods: |
237 |
|
238 |
Pileはカードの山だ。それはつまり、カードの組の最初と最後にだけアクセスするで |
239 |
あろうCardSetということだ(組の最初のN枚のカードも含むかもしれない。だが17番目 |
240 |
のカード、というような参照はしない)。これはQueueとStackのスーパークラスであり、 |
241 |
むしろそちらのクラスを使うべきである。だから、山になっているカードが |
242 |
FIFO(先入先出)なのかLIFO(後入先出)なのかを知るべきだ。 |
243 |
|
244 |
=over 4 |
245 |
|
246 |
=item give_cards(RECEIVER, NUMBER) |
247 |
|
248 |
Transfers NUMBER cards from the donor (the object on which this method was |
249 |
called) to the CardSet RECEIVER. This method can used for dealing cards from |
250 |
a deck, giving cards to another player (Go Fish), putting cards on the table |
251 |
(War), or transferring a card or cards between piles in solitaire. |
252 |
|
253 |
NUMBER枚のカードを、渡し手(このメソッドを呼び出すオブジェクト)からCardSet |
254 |
オブジェクトRECEIVERへ移動する。このメソッドはデッキからカードを配ったり、 |
255 |
別のプレーヤーにカードを渡したり(魚釣り)、カードをテーブルに置いたり(戦争)、 |
256 |
あるいはソリティア系で札置き場から札置き場へとカードを移動させたりするのに |
257 |
利用できる。 |
258 |
|
259 |
If NUMBER is "all", then the donor gives all of its cards. |
260 |
|
261 |
もしNUMBERが"all"だったら、渡し手は持っている全てのカードを渡す。 |
262 |
|
263 |
Returns 1 usually. If the donor has too few cards, it returns 0 and does not |
264 |
transfer any cards. |
265 |
|
266 |
通常は1を返す。もし渡し手が十分なカードを持っていない場合は、0を返し、 |
267 |
カードの移動は行われない。 |
268 |
|
269 |
=item top_card |
270 |
|
271 |
Returns the top Card in the CardSet (or 0 if CardSet is empty) |
272 |
|
273 |
CardSetの一番上のCardを返す(CardSetが空のときは0)。 |
274 |
|
275 |
|
276 |
=back |
277 |
|
278 |
=head2 Games::Cards::Hand |
279 |
|
280 |
A Hand represents a player's hand. Most significantly, it's a CardSet which |
281 |
is different from a Pile because the Cards in it are unordered. We may |
282 |
reference any part of the CardSet, not just the top or bottom. |
283 |
Methods: |
284 |
|
285 |
Handはプレーヤーの手を表す。最も重要なのはPileとは違うCardSetであるという |
286 |
ことだ。なぜなら、この中のCardは順番づけられていないからだ。一番上や一番下だけ |
287 |
でなく、CardSetのどの部分でも参照することができる。メソッド: |
288 |
|
289 |
=over 4 |
290 |
|
291 |
=item give_a_card(RECEIVER, DESCRIPTION) |
292 |
|
293 |
Transfers Card described by DESCRIPTION from the donor (the Hand on which |
294 |
this method was called) to the CardSet RECEIVER. This method can used for |
295 |
discarding a card from a hand, e.g. |
296 |
|
297 |
DESCRIPTIONで説明されるCardを、渡し手(このメソッドを呼び出すHand)から |
298 |
RECEIVERという名のCardSetへ移動する。 |
299 |
|
300 |
If DESCRIPTION matches /^-?\d+$/, then it is the index in the cards array of the |
301 |
Card to give. Otherwise, DESCRIPTION is passed to Hand::index. |
302 |
|
303 |
DESCRIPTIONが正規表現 /^-?\d+$/ にマッチした時は、与えられたCardの配列の |
304 |
インデックスになる。さもなければ、DESCRIPTIONはHand::indexに渡される。 |
305 |
|
306 |
Returns 1 usually. If the donor does not have the card, it returns 0 and does |
307 |
not transfer anything. |
308 |
|
309 |
通常は1を返す。もし渡し手がカードを持っていない場合は0を返し、移動は行われない。 |
310 |
|
311 |
=item move_card(DESCRIPTION, INDEX) |
312 |
|
313 |
Rearrange a Hand by putting Card described by DESCRIPTION at index INDEX. |
314 |
|
315 |
DESCRIPTIONで説明されたカードをINDEXという名のインデックスに置いてHandを |
316 |
再配置する。 |
317 |
|
318 |
If DESCRIPTION matches /^-?\d+$/, then it is the index in the cards array of the |
319 |
Card to give. Otherwise, DESCRIPTION is passed to Hand::index. |
320 |
|
321 |
DESCRIPTIONが正規表現 /^-?\d+$/ にマッチした時は、与えられたCardの配列の |
322 |
インデックスになる。さもなければ、DESCRIPTIONはHand::indexに渡される。 |
323 |
|
324 |
Returns 1 usually. If the donor does not have the card, it returns 0 and does |
325 |
not transfer anything. |
326 |
|
327 |
通常は1を返す。もし渡し手がカードを持っていない場合は0を返し、移動は行われない。 |
328 |
|
329 |
|
330 |
=item index(DESCRIPTION) |
331 |
|
332 |
Given a card description DESCRIPTION return the index of that Card |
333 |
in the Hand, or undef if it was not found. DESCRIPTION may be a Card or |
334 |
a string (like "8H" or "KC"). |
335 |
|
336 |
カードの説明DESCRIPTIONを与えるとHandにあるCardのインデックスを返す。カードが |
337 |
見つからないときはundefを返す。DESCRIPTIONはCardか、文字("8H"とか"KC")。 |
338 |
|
339 |
=back |
340 |
|
341 |
=head2 Games::Cards::CardSet |
342 |
|
343 |
A CardSet is just an array of cards (stored in the "cards" field). It could be |
344 |
a player's hand, a deck, or a discard pile, for instance. This is a super class |
345 |
of a number of other classes, and those subclasses should be used instead. |
346 |
|
347 |
CardSetは単なるカードの配列だ("cards"フィールドに収められている)。CardSetは |
348 |
例えば、プレーヤーの手札、デッキ、札捨て場などにすることができる。これは、 |
349 |
他の多くのクラスのスーパークラスであるので、代わりにそれらサブクラスを |
350 |
利用するべきだ。 |
351 |
|
352 |
=over 4 |
353 |
|
354 |
=item new(GAME, NAME, NICKNAME) |
355 |
|
356 |
create a new (empty) CardSet. GAME is the Game object that this set belongs |
357 |
to. NAME is a unique string that e.g. can be output when you print the CardSet. |
358 |
Optionally, NICKNAME is a (unique!) short name that will be used to reference |
359 |
the set. |
360 |
|
361 |
新規の(空)CardSetを生成。GAMEはこのセットが属すGameオブジェクト。NAMEは一意な |
362 |
文字列であり、例えばCardSetをプリントする際のアウトプットになりうる。オプション |
363 |
として、NICKNAMEはセットを参照するために用いられる(一意な!)短い名前である。 |
364 |
|
365 |
=item shuffle |
366 |
|
367 |
shuffles the cards in the CardSet. Shuffling is not undoable. |
368 |
|
369 |
CardSetのカードを切る。シャッフルはやり直し(undo)できない。 |
370 |
|
371 |
=item sort_by_value |
372 |
|
373 |
Sorts the Set by value. This and other sort routines will probably be used |
374 |
mostly on Hands, which are "ordered sets", but you might want to reorder a deck |
375 |
or something. Sorting is not undoable. |
376 |
|
377 |
CardSetを値でソートする。おそらく、これや他のソートルーチンを順序付け |
378 |
られているCardSetであるHandに対して用いることがあるだろう。しかしあなたは |
379 |
デッキや何かを再度順序付けたいかもしれない。ソートはやり直しできない。 |
380 |
|
381 |
=item sort_by_suit |
382 |
|
383 |
Sorts the Set by suit, but not by value within the suit. |
384 |
|
385 |
CardSetをスートでソートする。スート内の値でではない。 |
386 |
|
387 |
=item sort_by_suit_and_value |
388 |
|
389 |
Sorts the Set by suit, then by value within the suit. |
390 |
|
391 |
CardSetをまずスートで、その後にスート内の値でソートする。 |
392 |
|
393 |
=item clone(GAME, NAME, NICKNAME) |
394 |
|
395 |
Create a copy of this CardSet. That is, create an object with the same class |
396 |
as arg0. Then make a copy of each Card in the CardSet (true copy, not a |
397 |
reference). arg1 is the Game that the set belongs to. arg2 is the name to give |
398 |
the new CardSet. arg3 (optional) is the nickname. |
399 |
|
400 |
CardSetのコピーを生成する。つまり、arg0[訳補足:暗黙で渡される引数]と同じ |
401 |
クラスのオブジェクトを生成する。それからCardSetに含まれる全てのCardのコピーを |
402 |
つくる(本当のコピーであって、リファレンスではない)。arg1はセットが属する |
403 |
Game。arg2は新しいCardSetに与える名前。arg3(省略可)はニックネーム。 |
404 |
|
405 |
=item face_down |
406 |
|
407 |
Makes a whole CardSet face down |
408 |
|
409 |
CardSet全体を裏にする。 |
410 |
|
411 |
=item face_up |
412 |
|
413 |
Makes a whole CardSet face up |
414 |
|
415 |
CardSet全体を表にする。 |
416 |
|
417 |
=item print(LENGTH) |
418 |
|
419 |
Returns a string containing a printout of the Cards in the CardSet. Prints |
420 |
a long printout if LENGTH is "long", short if "short" (or nothing). |
421 |
The CardSet is printed out in reverse order, so that the top card of the set is |
422 |
printed first. |
423 |
|
424 |
CardSetに含まれるCardの出力情報を含む文字列を返す。もしLENGTHが"long"なら長い |
425 |
出力情報で、"short"(あるいは指定無し)なら短い。CardSetは逆順でプリントアウト |
426 |
される。つまりCardSetの一番上のカードからプリントされる。 |
427 |
|
428 |
=item name |
429 |
|
430 |
Returns the name of the Set |
431 |
|
432 |
CardSetの名前を返す。 |
433 |
|
434 |
=item nickname |
435 |
|
436 |
Returns the nickname of the Set (or undef if there is none) |
437 |
|
438 |
CardSetのニックネームを返す(名前がなければundefを返す)。 |
439 |
|
440 |
=item cards |
441 |
|
442 |
Returns a reference to the array of Cards in the set |
443 |
|
444 |
CardSet内にあるCardの配列リファレンスを返す。 |
445 |
|
446 |
=item size |
447 |
|
448 |
Tells how many cards are in the set |
449 |
|
450 |
CardSetの中に何枚カードがあるかを教える。 |
451 |
|
452 |
=back |
453 |
|
454 |
=head2 Games::Cards::Card |
455 |
|
456 |
A Card is a playing card. Methods: |
457 |
|
458 |
Cardはゲーム中に使われるカードだ。メソッド: |
459 |
|
460 |
=over 4 |
461 |
|
462 |
=item new(GAME, HASHREF) |
463 |
|
464 |
creates a new card. GAME is the Game this card is being created in. HASHREF |
465 |
references a hash with keys "suit" and "name". |
466 |
|
467 |
新しいカードを生成。GAMEはこのカードがつくられるGame。HASHREFは"suit"と"name" |
468 |
というキーを持ったハッシュを参照する。 |
469 |
|
470 |
=item clone(GAME) |
471 |
|
472 |
makes a copy of the Card (not just a reference to it). |
473 |
|
474 |
Cardのコピーを作る(Cardへのリファレンスだけではない)。 |
475 |
|
476 |
=item print(LENGTH) |
477 |
|
478 |
returns a string with the whole card name ("King of Hearts") if LENGTH is |
479 |
"long", otherwise a short version ("KH"). |
480 |
|
481 |
LENGTHが"long"ならカード全体の名前(例えば"King of Hearts")を持つ文字列を |
482 |
返す。それ以外なら短い名前("KH")を返す。 |
483 |
|
484 |
=item truename |
485 |
|
486 |
Gives a unique description of this card, i.e., you're guaranteed that no |
487 |
other card in the Game will have the same description. |
488 |
|
489 |
このカードの一意な説明を与える。つまり、Game内のどのカードも同じ説明を持た |
490 |
ないことが保証される。 |
491 |
|
492 |
=item name(LENGTH) |
493 |
|
494 |
prints the name of the card. The full name ("King") if LENGTH is "long"; |
495 |
otherwise a short version ("K"); |
496 |
|
497 |
そのカードの名前を出力する。LENGTHが"long"ならフルネーム("King")が、 |
498 |
そうでなければ短縮形("K")が出力される。 |
499 |
|
500 |
=item suit(LENGTH) |
501 |
|
502 |
Returns the suit of the card. Returns the long version ("Diamonds") if LENGTH |
503 |
is "long", else a short version ("D"). |
504 |
|
505 |
カードのスートを返す。LENGTHが"long"なら長い形("Diamonds")で、それ以外は |
506 |
短縮形("D")が返される。 |
507 |
|
508 |
=item color |
509 |
|
510 |
Is the card "red" or "black"? Returns the color or undef for unknown color. |
511 |
|
512 |
カードは赤か黒か?その色を返す。不明な色はundefが返る。 |
513 |
|
514 |
=item value |
515 |
|
516 |
Calculates the value of a card |
517 |
|
518 |
カードの値を計算。 |
519 |
|
520 |
=item suit_value |
521 |
|
522 |
Returns the suit_value of a card (1..number of suits) |
523 |
|
524 |
カードのsuit_value(スートの1..number)を返す。 |
525 |
|
526 |
=item is_face_up |
527 |
|
528 |
Returns true if a card is face up |
529 |
|
530 |
カードが表向きなら真を返す。 |
531 |
|
532 |
=item is_face_down |
533 |
|
534 |
Returns true if a card is face down |
535 |
|
536 |
カードが裏向きなら真を返す。 |
537 |
|
538 |
=item face_up |
539 |
|
540 |
Makes a card face up |
541 |
|
542 |
カードを表向きにする。 |
543 |
|
544 |
=item face_down |
545 |
|
546 |
Makes a card face down |
547 |
|
548 |
カードを裏向きにする。 |
549 |
|
550 |
=item owning_cardset |
551 |
|
552 |
Returns the CardSet which this Card is a part of |
553 |
|
554 |
このCardが含まれるCardSetを返す。 |
555 |
|
556 |
=item set_owning_cardset(SET_OR_NAME) |
557 |
|
558 |
Makes the Card a part of a CardSet. Arg0 is either an actual CardSet ref, or |
559 |
the name of a CardSet. |
560 |
|
561 |
そのCardをCardSetの一部に含める。arg0は実際のCardSetのリファレンスか、 |
562 |
CardSetの名前。 |
563 |
|
564 |
=back |
565 |
|
566 |
=head1 例 |
567 |
|
568 |
An implementation of Klondike (aka standard solitaire) demonstrates how to use |
569 |
this module in a simple game. Other card game examples are included as well. |
570 |
The Games::Cards README should list them all. |
571 |
|
572 |
クロンダイク(標準的なソリティアとも呼ばれる)の実装を使って、 |
573 |
簡単なゲームでどのようにこのモジュールを使うかのデモンストレーションを行う。 |
574 |
他のカードゲームの例も含まれている。Games::CardsモジュールのREADMEにそれらの |
575 |
一覧がある。 |
576 |
|
577 |
[訳補足:CPANモジュールやPPMでインストールした場合、 |
578 |
Tkを利用する例は含まれていないようです。tarballには含まれています。 |
579 |
L<http://search.cpan.org/src/AKARGER/Games-Cards-1.45/script/freecell.tk> |
580 |
L<http://search.cpan.org/src/AKARGER/Games-Cards-1.45/script/klondike.tk> |
581 |
] |
582 |
|
583 |
=head1 注意 |
584 |
|
585 |
=head2 いかにしてゲームを描画するか |
586 |
|
587 |
So you want to write a card game using Games::Cards (or even |
588 |
Games::Cards::Tk)? Great! That's what the module is for. |
589 |
Here are some tips about how to write a game. |
590 |
|
591 |
さて、Cames::Cards(あるいはGames::Cards::Tk)を使ってカードゲームを |
592 |
描写したいって?素晴らしい!これはそのためのモジュールだ。 |
593 |
どうやってゲームを描画するかについていくつかの小技を示そう。 |
594 |
|
595 |
=over 4 |
596 |
|
597 |
=item コードを盗む |
598 |
|
599 |
Laziness applies in Games::Cards just like in the rest of Perl. It will |
600 |
be much easier if you start with an existing game. |
601 |
|
602 |
Perlがそうであるように、[訳補足:三大美徳の一つ]怠惰をGames::Cardsにも |
603 |
適用しよう。既存のゲームを持っているなら簡単だ。 |
604 |
|
605 |
=item Stack 対 Queue |
606 |
|
607 |
Think carefully about whether the Piles in your game are Stacks (LIFO) |
608 |
or Queues (FIFO). As a general rule, piles of cards that are usually face |
609 |
down will be Stacks; face up will be Queues. CardSets where you want to |
610 |
access specific cards (i.e., not just the first or last) will be Hands. |
611 |
|
612 |
あなたのゲームに登場するカードの山(Pile)がスタック(LIFO)なのか |
613 |
キュー(FIFO)なのか、慎重に考えてみよう。一般的なルールとして、いつも裏向きに |
614 |
なっているカードの山はスタックであるだろう。表向きならキューだ。特定のカード |
615 |
(つまり一番最初か最後だけじゃなく)にアクセスするようなCardSetならHandだ。 |
616 |
|
617 |
=item GUIゲーム |
618 |
|
619 |
I've tried to design Games::Cards::Tk and the games that use it so that |
620 |
the Tk game is very similar to the text game. This allows the most code |
621 |
reuse. GUI games may involve clicking, dragging, and a different way to |
622 |
display the game; but the underlying game is still the same. Also note |
623 |
that serious timewasters may prefer to use the keyboard to play GUI |
624 |
games. See L<Games::Cards::Tk> for more details. |
625 |
|
626 |
私はGames::Cards::Tkの設計を試みてきた。そしてこれを使ったTkゲームは |
627 |
テキスト版のゲームと非常によく似ている。だからほとんどのコードは再利用が |
628 |
できる。GUIゲームはクリックやドラッグ、そしてゲームの表示の違いといったことを |
629 |
伴う。だが基礎にあるゲームはまだ同じだ。また、キーボードを使って遊ぶGUIゲーム |
630 |
の方が極度のゲーム好きには好まれることにも注意して欲しい。詳細は |
631 |
L<Games::Cards::Tk>を参照のこと。 |
632 |
|
633 |
=back |
634 |
|
635 |
=head2 PublicとPrivate |
636 |
|
637 |
This module contains a bunch of methods. The public methods are documented |
638 |
here. That means any method I<not> documented here is probably private, which |
639 |
means you shouldn't call it directly. |
640 |
|
641 |
このモジュールには一群のメソッドが含まれている。パブリックメソッドについては |
642 |
この文書で取り上げた。ということは、ここであげられてI<いない>メソッドは、 |
643 |
プライベートメソッドであるかもしれないということだ。これはあなたが |
644 |
直接呼び出すべきものではない。 |
645 |
|
646 |
There are also a bunch of classes. Most private classes are not documented |
647 |
here. A couple private classes are mentioned, since they have methods which |
648 |
public classes inherit. In that case, the privateness is mentioned. |
649 |
|
650 |
クラスも多くある。ほとんどのプライベートクラスはドキュメントに含めていない。 |
651 |
二つのプライベートクラスには言及している。なぜならそれらのメソッドは |
652 |
パブリッククラスから継承しているからだ。そういう場合はプライベートであることに |
653 |
言及してある。 |
654 |
|
655 |
=head2 TODO |
656 |
|
657 |
See the TODO file in the distribution |
658 |
|
659 |
配布物のTODOファイルを見よ。 |
660 |
|
661 |
=head2 Not TODO |
662 |
|
663 |
Computer AI and GUI display were left as exercises for the reader. Then |
664 |
Michael Houghton wrote a Tk card game, so I guess the readers are doing their |
665 |
exercises. |
666 |
|
667 |
コンピューターAIとGUIディスプレイは読者への課題として残した。Michael Houghtonが |
668 |
Tkカードゲームを書いたので、私は読者が課題に取り組むのではないかと思っている。 |
669 |
|
670 |
=head1 バグ |
671 |
|
672 |
You betcha. It's still alpha. |
673 |
|
674 |
そりゃもちろん。これはまだアルファ版だし。 |
675 |
|
676 |
test.pl doesn't work with MacPerl, because it uses backticks. However, |
677 |
(as far as I know) the games released with Games::Cards do work. |
678 |
|
679 |
test.plはMacPerlでは動かない。これはバックスラッシュを使っているためだ。 |
680 |
だが(私の知る限り)Games::Cardsを使ったゲームは動作している。 |
681 |
|
682 |
=head1 AUTHORS |
683 |
|
684 |
Amir Karger |
685 |
|
686 |
Andy Bach wrote a Free Cell port, and gets points for the first submitted |
687 |
game, plus some neat ideas like CardSet::clone. |
688 |
|
689 |
Andy Bachはフリーセルの報告を書き、最初に実行されたゲームの得点を得た。 |
690 |
それからCardSet::cloneのような巧いアイディアを付け加えてくれた。 |
691 |
|
692 |
Michael Houghton herveus@Radix.Net wrote the initial Tk Free Cell (two |
693 |
days after Andy submitted his Free Cell!) I changed almost all of the code |
694 |
eventually, to fit in with Games::Cards::Tk, but he gave me the initial push |
695 |
(and code to steal). |
696 |
|
697 |
Michael Houghton herveus@Radix.Net は最初のTk版フリーセルを書いた(二日後に |
698 |
Andyが彼のフリーセルを実行した!)。結局、Games::Cards::Tkに合うように私は |
699 |
コードのほとんど全てを変更した。だが彼は私に最初の励まし |
700 |
(と盗むためのコード)を与えてくれた。 |
701 |
|
702 |
=head1 COPYRIGHT |
703 |
|
704 |
Copyright (c) 1999-2000 Amir Karger |
705 |
|
706 |
=head1 LICENSE |
707 |
|
708 |
This program is free software; you can redistribute it and/or modify it |
709 |
under the same terms as Perl itself. |
710 |
|
711 |
=head1 SEE ALSO |
712 |
|
713 |
perl(1), Tk(1) |
714 |
|