Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Table-like (database-like) object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Snaggy - 11 Jan 2008 20:50 GMT
Hi,

I' trying to write a program (to learn the language) that handles a
deck of cards. Each card has an ID, a string name, a position, an
order (for shuffling) and as many other optional properties we might
want to assign it.

To store the deck's data I'm using right now a string[ , ] array, but
this is proving difficult.
If I want to select the cards in a position I have to do a foreach,
and that's ok. But if I want to sort let's say by positon and subsort
by order, it gets difficult..

I thought I'd me nice to work on this data as I would on a database
table, doing things like select where, order by etc etc

I know it exists a LINQ thing that might serve the purpose, but the
example I found don't quite fit what I need..

any suggestions?
thanks

Luca
Jeroen - 11 Jan 2008 21:05 GMT
Luca,

I mainly work with .NET 2, so for LINQ advice you should count on the
guru's here.

However, concerning the approach your taking: start the same as if you
were architecting a database you'd start with a schema. Similarly for
your code, start with creating interfaces to show relationships
between your objects. For example:

/*****************************************/
interface ICard {
// jack, 2, 3, ace, etc
string name;

// clubs, spades, diamonds, hearts
MyCardColorEnum color;

// object reference to the deck
IDeck deck;
}

interface IDeck {
// cards in the deck, ordered
IDictionary<int, ICard> listOfCards;

// gets a random card
ICard getRandomCard();

// gets card from a specific location
ICard getCard(int location);

// gets the top card of the deck
ICard getCard();
}
/*****************************************/

Good luck with your study!

Regards,
Jeroen
zacks@construction-imaging.com - 11 Jan 2008 21:41 GMT
> Hi,
>
[quoted text clipped - 19 lines]
>
> Luca

Providing you are using .NET 2.0 or later, I would use a generic list
of a class object of a class that defines each card.
Snaggy - 11 Jan 2008 22:25 GMT
On Jan 11, 10:41 pm, za...@construction-imaging.com wrote:

> > Hi,
>
[quoted text clipped - 24 lines]
>
> - Show quoted text -

that's it!! I did it with a List<card> after having defined a card
class, and used linq queries, it works perfectly! It really is an
amazing feature this linq, and quite powerful

bye
j1mb0jay - 11 Jan 2008 22:38 GMT
> On Jan 11, 10:41 pm, za...@construction-imaging.com wrote:
>>
[quoted text clipped - 25 lines]
>
> bye

If you are learning the language I would try and build your own data
structure. A linked list that has pointers to the next and previous
nodes in the list would allow for card games that may contain more than
one pack of cards. Or even a binary tree which in turn when populated
would sort the cards into order for you.

j1mb0jay

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.