4 Home
tompaana редактировал(а) эту страницу 2014-11-12 05:20:40 -08:00

Solitaire XNA example application demonstrates how to develop the well-known card game with 2D card textures for Windows Phone using XNA Game Studio. This game example has been implemented with several different technologies, the last of these being this XNA version. The example was initially implemented with Symbian C++ in March 2009. This Windows Phone implementation has been rewritten based on the Qt implementation of the example.

Screenshot

See the game in action here: http://www.youtube.com/watch?v=igvCgCTQNW8

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 this version of Solitaire is implemented with 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.

Class diagram

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.