Reversi, a Windows Store game in XAML, C#, and C++

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

The Reversi sample shows how to combine several Windows Store app features using XAML and C#. It also shows how a C# app can use C++ for performance-sensitive calculations. Finally, it shows how the Model-View-ViewModel (MVVM) pattern and unit testing can make it easier to manage the development of an app with growing complexity. This topic introduces the sample and provides links to additional documentation.

For a short intro to MVVM, see Use the Model-View-ViewModel (MVVM) pattern.

For info on how the sample uses particular features, see Learn how the Reversi sample uses Windows Store app features. Here you can learn about features that interest you without needing to understand the whole sample.

For info on how the overall sample works, see Understand the Reversi app structure. This topic describes the app layers and the parts in each layer.

The Reversi sample uses XAML and C# for the main app, and includes both C# and C++ versions of the game engine. We created the C# version first, along with its unit tests. Later, we ported the C# code to C++ to get a performance boost, taking full advantage of the existing unit tests to make development faster. For info on the creation of the C++ version, see Learn about the Reversi C++ game engine.

Note  This documentation reflects the current state of the sample at the time of writing. See the following links for the latest code and info about any updates.

 

Download the Reversi sample app or browse the source code.

Introducing the Reversi sample

We created this sample to show how to combine multiple features into a single, real-world app. Multiple features means complexity, however, so another goal is to show how to manage that complexity. We chose to implement a common board game app because it provides a relatively simple domain with features that can range from the simple to the complex.

This sample does not provide general game development guidance, although you can use it as a basis for similar board game apps. For Windows Store apps requiring high-performance graphics, such as computationally intensive games, consider using DirectX with C++ to provide the best user experience on the widest possible array of devices. For more info, see Creating a DirectX game.

Reversi is one of the most common board games implemented on computers. This is because the rules and artificial intelligence (AI) are relatively easy to implement, and the rules are over a hundred years old and are thus not under copyright. It also represents a programming problem that is not too hard but also not too easy.

The Reversi sample app includes features that let a player:

  • Read the rules of the game.
  • Play against other humans or against an AI at several difficulty levels.
  • Pause the clock when the game isn't active.
  • Show and hide the clock.
  • Show and hide visual indications of the legal moves and the spaces affected by the previous move.
  • Undo and redo moves to explore alternate plays.
  • Play the game on different board sizes.

This set of features provides enough complexity to represent a truly "real world" app, but with enough simplicity to keep the app relatively small for learning purposes.

When an app reaches this level of complexity, making changes and adding new features can cause unexpected problems. The Reversi sample manages increasing complexity by using a structure that separates different kinds of code into different layers. These layers can interact only in very specific ways, which helps reduce accidental side effects that can occur even with seemingly small code changes. The main goal of this structure, in fact, is to make it easy to change code and to add features without causing problems. That way, you can figure out the right code design in an environment where mistakes have less impact and are more easily fixed. For more info, see Use the Model-View-ViewModel (MVVM) pattern.

Resources

To get the full benefit of the Reversi sample and documentation, you should first understand XAML, C#, and the basics of Windows Store app development. The following topics provide some of the necessary background info:

For general info on designing and developing Windows Store apps, see:

If you understand C++, you can also benefit from the C++ version of the Reversi game engine, although this is not required to understand the rest of the sample.

Game technologies and app performance

The Reversi sample targets the popular Games category in the Windows Store and provides some reusable code and ideas for others to build on. It implements a familiar, casual board game in order to focus on the basics of real-world, end-to-end app development.

Real-time, arcade-style games often require more advanced techniques than turn-based board games to achieve good performance. Performance is important for every app, and in general you should understand your performance requirements early to make the right technology choices. You should also confirm your choices by testing your app during development on a variety of devices.

Both XAML and HTML/JavaScript are appropriate for many types of casual games, including puzzle and board-game apps. Puzzles and board games are good first "real" apps for those who are new to coding or to the platform, and who are moving beyond the "getting started" level.

If you plan to create a performance-intensive game (such as a graphics-heavy, arcade-style game), consider using Microsoft DirectX, which is considerably more complex and powerful than XAML or HTML/JavaScript. For more info, see Creating a DirectX game and DirectX and XAML interop.

You can also improve performance in XAML and JavaScript apps by implementing specific modules in C++ or by using third-party, performance-optimized libraries. For more info, see Creating Windows Runtime Components, Using a Windows Runtime Component in Reversi feature scenarios, and Learn about the Reversi C++ game engine. To improve the general performance of your code, see Performance best practices for Windows Store apps using C++, C#, and Visual Basic.

Reversi sample app

Use the Model-View-ViewModel (MVVM) pattern

Learn how the Reversi sample uses Windows Store app features

Understand the Reversi app structure

Learn about the Reversi C++ game engine

Developing games

Designing great games for Windows

Create your first Windows Store app using C# or Visual Basic

Roadmap for Windows Runtime apps using C# or Visual Basic

Data binding