Universal Windows Platform – Tutorial Insider – Deal Or Not

Standard

Overview

comentsys.wordpress.com today features a Universal Windows Platform tutorial showing how to create a box-opening game where every so often there is a Deal and you can choose Not to accept it and Continue but risk winning a smaller amount – the last box at the end will be the winning amount or the Deal if you took that.

Details

Within the game there are the box values as a double[] – this contains all the possible amounts that a box can contain, each of those amounts has a corresponding colour which is in the string[] of box colours then there’s the names of the boxes as another string[]. The box colours are stored as hexadecimal colour values and these are converted using the ConvertHexToColor to a colour that can be used in the code. There’s a good use of the ContentDialog to show different content with different Primary and Secondary buttons which is made use of to display any amounts of opened boxes and any Deals too. There’s a Shuffle method combined with a random number generator which is used to randomise the contents of the boxes. The amount is obtained with the GetAmount method which also displays the passed in background colour and displays the amount as currency – you can change the CultureInfo to your own region e.g. “en-US” to display a different currency symbol.

In the game there are Offers and these are calculated with the GetOffer method which uses a simple algorithm to work out what the offer should be, there’s also a GetBackground method to get the correct background colour for an amount. The Pick method is the core part of the game – when each box is selected it will display the Amount in that box, after every five turns there will be a message to Deal or Not – if you deal the game is over and you win the amount that was offered or you can Continue. The layout of the game is formed from the AddBox method which creates the look of a box with colours and a label on the front, the Boxes method creates the full layout of boxes to be displayed and is called from the Layout method. You can start a New game which will reset everything to start again.

Behind the Scenes

Deal Or Not is quite a fun game and contains many elements of a certain game show and shows off how something like that can be encapsulated in a game you can play on a computer – it features a fun look and feel with the boxes displayed and amounts shown in a more pleasing visual manner, it was important for each amount to show as closely to the game show as possible and demonstrates the flexability of dialogs to display quite sophisticated content and hopefully is as fun a game to write as it is to play, and was a fun example to create.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s