Over the weekend there was a rainy weather, so I lighted up the fireplace in the living room, turned on the TV and occupied the couch with my laptop to check, what news we’ve got with Windows Phone 7 development tools.
Just to learn the WP7 programming news I started with a light version of blackjack game for WP7 – even I haven’t one yet, just using emulator. It was surprisingly easy and I had fun. So there is the description how I did it:
After developer tools succeeded just start Microsoft Visual Studio 2010 and create a new Windows Phone Game project:
Let’s call the project BJLight for Blackjack Light. We will learn the WP7 game programming building a light version of the old known card game – Blackjack.
Visual Studio 2010 creates new solution with all the required projects and files for a new WP7 game:
First rename Game1.cs to BJGame.cs as the only game contained in the project: just edit it in Solution Explorer.
You will be asked:
Confirm with “Yes”: you will see the file name changed in Solution Explorer:
… and source code will be updated as well:
Open “BJLite” project properties to set some common and initial configuration parameters of the game:
- Ensure the “Game startup type” is “(Not set)” – this will enforce the only Game derived class to be launched on game start: in our project this is BJLite class. Note: if there are many Game derived classes in the project, you can specify, what class should be launched on game start.
- The thumbnail of the game appears on WP7 display as the control to launch game. Let us fill this thumbnail with appropriate image to identify our game:
The do the same with Game.ico:
The project should be signed – this is a good programming style.
Select “New” key file and enter as follows:
A new key file will be created and added to project:
After initial project configuration is set, let us start with game design.
One of the key methods of the BJLite class instance is Draw(). This method is called each time the game requires the display to be redrawn:
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
Since we design a card game, let us emulate a casino gambling table and repaint it green:
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Green);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
Start the solution with F5: the WP7 emulator appears and shows the newly created game screen - gambling table:
Click on the “Back” button and see the game thumbnail:
Clicking on the thumbnail you start the game.
The WP7 emulator controls allow rotate the emulator to get appropriate screen orientation:
We will design the game for landscape orientation.
(more to come)
No comments:
Post a Comment