Entries:
Comments:
Discussions:

Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Playing Blackjack on your new XBox 360, Windows PC and/or Windows Phone 7.1(5)

Today's project shows how one codebase, one set of source files, can be used on a Windows PC, XBox 360 and Windows Phone 7 all at the same time... Oh and the code is in VB or C#... Smiley

Card Game Starter Kit: Blackjack (C#/VB)

This sample is a fully-functional Blackjack card game for Windows, the Xbox 360 console, and Windows Phone 7, built on top of an easily extensible card game and animation framework that you can use to build your own card games.

SNAGHTMLeb7726

Here's the included readme;

Card Game Starter Kit

This sample is a fully-functional Blackjack card game for Windows, Xbox 360 and Windows Phone 7, built on top of an easily-extensible card game and animation framework you can use to build your own card games.

How the Sample Works

The full game of Blackjack that can be built and played from this sample is built from a number of different underlying components, each of which can be separated out and extended to create new functionality:

  • Classes from the GameStateManagement sample to handle the loading, updating, and transitioning of screens
  • The AnimatedGameComponent class, inherited from DrawableGameComponent, to handle animating the position, scale, and text drawing of in-game objects
  • The Cards Framework, represented primarily by the CardGame, CardPacket, Player, GameTable and GameRule classes, that provide generic card game functionality and are extended by the Blackjack classes to provide the specific game logic.

Upon starting the game, the GameplayScreen creates the BlackjackCardGame, passing in a BlackJackTable and initializing BlackjackPlayers. Per-frame, the BlackjackCardGame handles the input per-frame via the GameScreen.HandleInput method, and passed via the InputState object to all of the other classes it manages.

The various phases of gameplay are handled by a state machine inside BlackjackCardGame, deciding when to start dealing, when to add and resolve rules, and when to start a new round, based primarily on user interactions with the various input buttons, which are AnimatedGameComponent objects.

Drawing is handled by the objects that inherit from AnimatedGameComponent. Each object is responsible for drawing itself and updating its animation states per-frame. Many of the objects, including the GameTable, derive from AnimatedGameComponent.

Extending the Sample

If you are interested in creating a different type of card game, extending the Cards Framework is a good place to start; create a new class that inherits from CardsGame, a new class that inherits from GameTable, a new player class that inherits from Player, and any new GameRule classes you need to judge card values specific to your game. You can then modify the GameplayScreen.Initialize method to call your custom CardsGame.Initialize, add the necessary Player objects and start a round of play.

Here's the Windows project running;

SNAGHTMLecf52b

SNAGHTMLef1a58

And the Windows Phone 7;

SNAGHTMLed4905

SNAGHTMLee98d9

(My son's on the XBox 360 playing Skyrim and won't let me on to show you it running there too... lol)

Let's take a peek at the source (VB);

image

imageimageimage

Three platforms, all using the same code files. How?

SNAGHTMLf4edfb

If you've ever been interested in building a cross platform XNA game, building a card game or just want to play Blackjack, this project is waiting for you...

Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
    Unsubscribing
    Subscribing

Remove this comment

Remove this thread

Close

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.