locked
Card Games RRS feed

  • Question

  • Hello, I am new to Silverlight. I wanted to know if it is possible to create a virtual card deck that could be used to play simple games, but in a free environment. No game logic involved. Only virtual compoenents, such as;

     

    a shuffle-able deck; a discard pile that the player may draw from; a place on the table to place cards; and the ability for a player to view his cards and have any number of cards in his hand without other people seeing him. 

     

    The idea is that we want to play card games that may involve multiple decks, and also not be restricted by turn-based programs. (i.e. any one can play cards at any moment, or draw from the deck or discard pile etc. at any time just in case the rules would allow them to do so.

     

    The click and drag approach with a simple solitaire program is where I would like to start, but I am new to silverlight and I don't know what the functions and capabilities are yet. I have a lot of work to do on my own, but I was wondering if anyone out there in the Silverlight world had anything that could help get me started. 

     

    Thanks a million!

     

    -Adam

    Sunday, January 24, 2010 5:32 PM

All replies

  • I think it's probably harder to create a freeform card simulator than to create a card game with rules. You would need to have a way to figure out if the player is meaning to put a card in their hand or on the table, if they take from the deck whether it goes in their hand, on the table face up in a pile, or whatever. I can't imagine the user interface for something like this. If you figure out that part, the actual displaying of card etc shouldn't be too hard.

    One thing that helps with card games that became available in Silverlight 3 is that you can render to a bitmap. This means that you could have a vector graphic for each of the suits, for the numbers and letters, etc. and render the cards to bitmaps as you need them or at the beginning. This allows you to get the benefits of vector graphics like handling multiple resolutions and combine those with the performance benefits of animating bitmaps instead of complex vector graphics.

    Sunday, January 24, 2010 11:02 PM
  • Silverlight 3 is that you can render to a bitmap. This means that you could have a vector graphic for each of the suits, for the numbers and letters, etc. and render the cards to bitmaps as you need them or at the beginning.

    As a side note to this, if you were to "BitmapCache" the Path (or more likely a collection of them within a higher level control), conversion to a bitmap and then hardware acceleration will be handled automatically. Hopefully, Silverlight 4 will allow PathGeometries to be used as resources, i.e.:

    <Grid>
    <Grid.Resources>
    <PathGeometry x:key="heart" data="yadayadayada />
    </Grid.Resources>
    <Path Data="{Static heart}" RenderTransform="top left" />
    <Path Data="{Static heart}" RenderTransform="top middle" />
    </Grid>

     
    Monday, January 25, 2010 5:16 AM
  • "Hello, I am new to Silverlight. I wanted to know if it is possible to create a virtual card deck that could be used to play simple games, but in a free environment. No game logic involved. Only virtual compoenents, such as;"

    Yes it is, until a certain extent.

    Your "virtual card deck" would be a class which holds the cards in the deck. Implement:

    public interface IDeck {

      void Add(Card card);
      void Delete(Card card);
      Card[] Cards { get; }
      void Shuffle();
      Canvas Display();
    }

    Maybe you can think of more functions. Except for the display function, all functions are non-logical. A class implementation would be something like:
    public class MyDeck : IDeck {

      IDeckRenderer renderer;

      public MyDeck(IDeckRenderer renderer){

        this.renderer = renderer;

        ..
      }

      ..

    }

    And in the Display() function you combine the renderer with the Deck's content. You can think of different renderers to implement:

    class BackfaceStack : IDeck

    class ShowHand : IDeck

    class ShowTable : IDeck

    In other words, with a model such as this, you have seperated the container (MyDeck) from display (IDeckRenderer). You can reuse these basics each time you want to add logic. Actually in this model, the deck just is a collection of cards with some simple operations (add, remove). You can use this collection for anything you like.

     

    Monday, January 25, 2010 2:47 PM
  • it isnt so much the AI in card playing that is difficult to handle... no it is space on screen that is the obstical, though admittedly the AI is hard to program as well....   here is my game> Spectral Influences.. house of cards http://hoc.grumm.square7.ch so as you can see i am not talking through my hat on the subject of difficulty in programming a card game :)

     

    Friday, April 8, 2011 1:09 PM
  • I missed this when it was orginally posted but this...

    public interface IDeck {

      void Add(Card card);
      void Delete(Card card);
      Card[] Cards { get; }
      void Shuffle();
      Canvas Display();
    }

    is horrific. There's no way an IDeck interface should contain a reference to a Canvas. That's a ui component, and a pretty bad one at that, that doesn't belong anywhere near a deck's algorithms.

    Friday, April 8, 2011 1:18 PM
  • Hi jackbond,

    It was only an example. And my experience is that in game writing, sometimes the dirty method can be the best way. We've learned lots of seperation techniques, but these apply mostly for situations where multiple people work on the same project, while in game writing, it is usually only one person who does the work. Anyway, in the end it is your own choice, ofcourse.

    Saturday, April 9, 2011 6:33 PM
  • It was only an example.

    Why provide a bad one if he's looking to learn?

    And my experience is that in game writing, sometimes the dirty method can be the best way.

    No, the dirty way is the dirty way, but it could hardly be the best way. Silverlight provides so many ways to separate the levels, why go with the dirty way when there isn't even the slightest short term benefit. Now if this was an optimization to deal with a performance issue, that might be justification, but this is a card game, so that's just truly horrific.

    it is usually only one person who does the work.

    I have several apps where I'm the only author, and I've never regretted doing it the right way the first time. When I've seen code like that, it's usually because it was written for archaic platforms like Java or C, where there was no support for things like events or binding, so the coder did the best they could to get data from A to B.

    Anyway, in the end it is your own choice

    You can choose from phantom fears and kindness that can kill
    I will choose a path that's clear- I will choose good code

    Monday, April 11, 2011 12:37 PM