Solitaire XNA

Rewriting Story

The Solitaire game example has published before on the Symbian C++ and Qt platforms. Now it was time to implement the game on the Windows Phone.

C Sharp is like Java or Qt. It is easy for a Qt developer to get into. You can find Windows Phone tutorials here: http://msdn.microsoft.com/en-us/ff380145

The Solitaire game logic is quite simple, it only has one method that must be ported into C Sharp.

General high level functionality that must be implemented on all platforms:

The biggest difference between platforms is that XNASolitaire is made on Windows Phone XNA Game Studio. With XNA Game Studio you can create games for Windows, Xbox 360, and Windows Phone 7. The XNA application runs on a game loop that runs at about 30 FPS. You have to handle all drawing and detect touch positions in that game loop.

Class diagram

Cards are shuffled to different decks. The deck class is the base class for the other decks, which have some specific functionality. For example, the cards in the TargetDeck are positioned accurately on top of each other.

Tombstoning

Windows Phone 7 executes one application at a time. When switching to another application, the current application is tombstoned = terminated. The application state must be saved before termination to enable the user to later continue the game from the same position. Solitaire stores deck data on termination. When the user navigates back to a tombstoned application, the application is recreated and the current state is restored. Read more about Windows Phone Execution Model.

When an application is to be tombstoned, a Deactivated event is sent. An Activated event is sent when an application is restored from tombstoned state back to running state.

Solitaire decks are stored in the application's private Isolated Storage using XMLSerializer. The serialised data class and member variables must be public.

Optional changes

The base class for game components in the XNA framework is GameComponent, which provides a modular way of adding functionality to a game. If a component loads and draws graphics, the content derives from DrawableGameComponent. It is good design to derive your game views from DrawableGameComponent.

A card in Solitaire XNA example is more like a struct that only contains card position and texture. The card could be derived from DrawableGameComponent if wanted.

Project information

Downloads

Attachments

Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2011 All rights reserved