Archive for October, 2009

Blackjack Web Application

This post will explain how how I created a blackjack simulator web application, in ASP.net.

Here is a demo site which you can try yourself

Look and feel is basic, but the demo remembers your user details and playing history upon registration.

Enjoy playing and feel free to post any feedback via the comments below.

My subversion repository hosts the project files containing the data classes, which build the BlackJackClasses.dll file . This file is referenced by Asp.Net Website Code which can be found here

To build the project from the source you will need Visual Studios 2008 IDE and access to a SQL Server database. As the user data is persisted to a SQL Server database you will need to run this SQL script on your database to create the required tables.

Compile the BlackJackClasses project first as this file handles game logic and database access.
You may wish to run Nunit unit and integration tests that I wrote for this project, which are in my subversion repository

You will need to add the dmbl file to this project to access the database via LINQ. Name this file DBBlackJack.dbml. Connect to your database and add the three new tables to the dbml file.

Once compiled, open the Web project, and add a reference to the dll the BlackJackClasses project has generated. You web project should now open.
The subversion repository can be found here

Data classes: http://www.michaelokarimia.com/examples/Exam/BlackjackClasses/BlackjackClasses/

Website: http://www.michaelokarimia.com/examples/Demos/BlackjackGame/trunk/

No Comments

Command Pattern Tutorial: Part Two

This is part two of a tutorial to create a Home Automation Program, using the Command Pattern.  It assumes you have already read  part one

I have used NUnit to unit test my  classes,  and I have provided the test script I created in my subversion repository

Now that I have created the classes I need, I have coded an ASP.NET web project using those classes.

You can demo the Remote Control Application here (UPDATED: This is now hosted on the Azure cloud)

This version is implemented without using AJAX, and uses traditional postbacks instead. Look and feel is very basic, as an AJAX version of the site will posted in a future blog post.

The source code for this site is available

The left hand panel displays the remote control for the home automation system, and contains seven slots Command Slots. Initially there are no commands set in these slots, so the on and off buttons are disabled. To add a Command to a slot, the user may click the Edit button to select a list of available commands. Once a command is selected, it may be turned on or off by clicking the on or off button for that slot.

To the right hand of the page, the status panel displays the state of the appliances for the house, which are by default, turned off. Once an on or off button is clicked, the status of the appliances will be updated.

The list of available commands is kept in the database, when a new House object is created, it’s list of commands is retrieved and then instantiated.

The Drop Down List is populated as thus:

private void LoadCommandsDropDownMenu(House h)
{
ArrayList array = h.CommandList;
ArrayList DDarray = new ArrayList();
DDarray.Add("Select Command");
foreach (House.command_pair cmds in array)
{
DDarray.Add(cmds.Name.ToString());
}
DDCommandList.DataSource = DDarray;
DDCommandList.DataBind();
}

If we update the Command Objects table in the database we can add new commands. We can even update the list of valid commands without changing existing code. By using the pattern we can change the commands of each command slot at runtime.

My next post will show how to use implement some nice AJAX features using JQuery.

,

2 Comments