dimmesdale has asked for the wisdom of the Perl Monks concerning the following question:
I'm planning to work on a quick GUI application with Tk called PerlSol (a solitare program in Perl). I've outlined a basic plan (with some holes, admitingly), and want some input. In particular, it seems to me that using OOP would be the way to go (I'm originally a C/C++ programmer and know a great deal about OOP and how it relates to C/C++, however I'm new to Perl's quirks, so any suggestions as to this would be helpful: I'm planning to read perlboot and perltoot and whatever else may help with this).
The plan (if it can be called that) is presented here, in all its humbleness (its just something quick I want; the program isn't designed to be major, just a small project, but I want some guidance, and a detailed, or not-so-detailed, plan often helps in making code in my opinion).
What I plan to do is make a module that will facilitate the creation of games based on a defined set of rules. For example, for a normal (as I first learnt it) solitare game, you could create seven piles of 1 to 7 cards respectively, only showing the top card, create another pile of cards (the deck), create a waste pile, create four piles to be filled starting with aces, then one could create the 'rules' for these piles (max. number of cards, if there is one, increasing and/or same suit, etc.). The current design plans to facilitate these 'behind the scene' details, so the specific game can be concerned mainly with creating bindings and functions to deal with those bindings. Of course, this is just a projected way of dealing with this (IF ANYTHING BETTER CAN BE DONE, I'D LIKE TO KNOW, I'm posting this so I don't waste too much of my time learning I should be doing something different)
(I make up my own conventions at times, but it should be self-explanatory--it is to me, anyway! I use [something here] to denote that something here is optional. . .I'v seen this various places, the rest follows)
# Don't freak out about not having 'use strict' etc. # :) This is just psuedo code at places my $card = new Card([%attr]); $card->show([x,y]); # displays card on screen, optionally # with the upper-left coordinate # being (x,y) ->suit([val]); # returns (and optionally sets) the # suit to value (data type undecided) ->value([val]); # returns (and optionally sets) the # card number to value (1-13,A,K,Q,J) ->where([pile]); # returns (and optionally sets) the # pile where card is placed ->state([state]); # Sets card to be face up/face down ## "Friend" (from C++, loose usage) functions (designed for ## use with an array of cards (or maybe hash?) IsAlternatingColor(); # e.g., ...black,red,black,red... IsSameColor(); # e.g., ...black,black,black... IsAlternatingSuit(); # e.g., ...diamond,club,heart... IsSameSuit(); # e.g., ...spade,spade,spade... IsIncreasing(); # e.g., 2,3,4,5... IsDecreasing(); # e.g., K,Q,J,10... my $pile = new Pile([%attr]); $pile->maxcards([val]); # returns (and optionally # sets) max. amount of cards # (or NO_LIMIT constant) $pile->nextcard(); # returns suit/value of next # card, beginning at top $pile->get(x); # same thing, but xth card # (0 is top, 1 is second, ...) $pile->rules(rules); # Rules that cards must abide # by (e.g., decreasing) ## A tableau is a 2-d array of piles ## A waste/stock/foundation/etc. is a pile (or a collection ## thereof) ## Terms inspired by some of the free downloadable ## solitare programs, e.g., 1 2 3 Free Solitare ## at: www.123freesolitaire.com/ User-Level notes ---------------- Undo feature Change deck style Change different features of display Deign your own game Next Move AutoPlay (last two use a primitive AI algorithm; of course, I don't plan to do all these things at first, some are just ideas I 'may' choose to implement later -- its just a simple program for someone I know)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PerlSol
by djantzen (Priest) on Jul 02, 2002 at 22:34 UTC | |
|
Re: PerlSol (solitaire in Perl)
by jjohn (Beadle) on Jul 03, 2002 at 01:16 UTC | |
|
Don't forget CPAN is your friend
by jaldhar (Vicar) on Jul 03, 2002 at 19:59 UTC | |
|
Re: PerlSol (solitaire in Perl)
by John M. Dlugosz (Monsignor) on Jul 03, 2002 at 20:21 UTC | |
|
Re: PerlSol (solitaire in Perl)
by mattr (Curate) on Jul 04, 2002 at 14:07 UTC | |
|
Re: PerlSol (solitaire in Perl)
by dimmesdale (Friar) on Jul 04, 2002 at 18:19 UTC | |
|
Re: PerlSol (solitaire in Perl)
by helgi (Hermit) on Jul 05, 2002 at 14:33 UTC |