Exploring an End-to-End Sample for a SmartGlass Experience: Snake Battle Arena

To develop a SmartGlass experience, you create multiple pieces of code that run in different places. Some of the code runs on the Xbox One console, and some of the code runs on the SmartGlass-enabled devices that one or more players are using to interact with the Xbox One console.

One way to understand how to create and integrate these different pieces of code is to examine some of the existing samples that are available for SmartGlass. The Snake Battle Arena sample is a particularly useful sample to use for this purpose.

To get the Snake Battle Arena sample, install the SmartGlass Hosted Companion SDK. The sample is in the Samples\SBA folder in the folder to which you extract the .zip file for the SDK. To view a video that features the Snake Battle Arena sample, see Snake Battle Arena for SmartGlass.

Overview of the Snake Battle Arena Game

In the Snake Battle Arena game, each player guides the movement of a snake across a playing area in pursuit of food, so that their snake can grow longer. If a snake collides with the walls at the edge of the playing area or with another snake, the snake dies and the player has to start over.

With Snake Battle Arena sample for SmartGlass, the players can use their SmartGlass-enabled devices to control the movement of their snakes. If a player has a SmartGlass-enabled device that has acclerometer support, the player can tilt their device towards the top, bottom, left, or right to instruct the snake to make the corresponding turn in the game. The sample uses a device-side SmartGlass API to take the accelerometer readings on the SmartGlass-enabled device and send those readings to the Xbox One console, where the sample uses a console-side SmartGlass API to receive those readings and then processes them as appropriate for the game.

To deploy and run the Snake Battle Arena

Before you can deploy and run the Snake Battle Arena sample, you need to perform the following prerequisite tasks:

If you performed the prerequisite tasks, you can build and deploy the Snake Battle Arena game to your dev kit from Visual Studio, and open the Snake Battle Arena companion in SmartGlass Studio on your SmartGlass-enabled device to start playing the game.

To build and deploy the Snake Battle Arena game to your dev kit

  1. Go to the folder to which you downloaded the Snake Battle Arena sample, and double-click SBASample.sln to open the sample in Visual Studio.
  2. On the Solution Explorer tab in the right navigation pane, right-click SBA and click Build.
  3. When the messages in the Output pane indicate that the build succeeded, right-click SBA again, point to Debug, and click Start new instance.
    The Snake Battle Arena game should appear on the monitor for your dev kit, ready for players to join the game.

To start the Snake Battle Arena companion on your SmartGlass-enabled device

  1. On the Login screen in SmartGlass Studio, tap Log in.
  2. On the Sign in page, enter the address and password for your Microsoft account in the Microsoft account and Password boxes, and click Sign in.
  3. On the Connect screen, tap the name of your dev kit, if SmartGlass automatically discovered your dev kit.
    or
    Tap Local console, enter the IP address for your dev kit, and click Connect.
  4. In the Companion section on the Launch screen, enter either http://sgsamples.azurewebsites.net/sba/ or https://sgsamples.azurewebsites.net/sba/, and click Launch Companion.
  5. On the SBA Companion page, optionally change the default name for your snake in the top box and the color in the bottom box, and click Join the Arena.
    A snake of the specified color appears in the Snake Battle Arena on the monitor for your dev kit, and you can tilt your SmartGlass-enabled device to control the movement of the snake in the game. You are ready to play.

Code in the Snake Battle Arena Sample

As an example of a SmartGlass experience, the Snake Battle Arena sample includes both code that runs on the Xbox One console and code that runs on a SmartGlass-enabled device. The code in these locations communicate with each other using messages, and that communication provides the means for the Xbox One console and SmartGlass-enabled device to interact.

The Snake Battle Arena sample is a Visual Studio solution that contains the following projects:

See also

Overview of the SmartGlass Platform