c#


I decided to draw a line under the Bouncy game this evening. Then I decided to resurrect it and make it the subject of my base project for Windows games. The education section of XNA Creator’s page yielded my next evenings jaunt through the merry fields of XNA; I am going to use the Game State Management example as the inspiration (basis?) for my template project.

The actual game (GameplayScreen.cs) will be where Bouncy lives on!

Star-128x128 Zara Grace is my youngest daughter. She is a bubbly, smiley six month old who loves sitting at daddy’s computer thumping his keyboard. With the release of the XNA Game Studio 3.0 in the last few weeks, I decided to spend my geek time this weekend putting her together a simple “bash the keyboard game.” And low, Bouncy was born!

Bouncy is a very simple 2d “game” which baby can interact with by hitting keys. It represent my first foray into game development with the XNA Framework and I am quite happy with it considering it is about a days worth of effort. For those who are new to XNA or have not tried it out yet, I hope this project will serve as a “quick start.” It demonstrates the rendering of a texture, sound effects and music, some simple physics and the handling of user input.

The binaries and source are available for download at Magoo Games.

This weekend I have been evaluating  Castle’s ActiveRecord as an object relation mapping solution. It is built upon NHibernate and is an implementation of the active record design pattern.

After browsing the quick start documentation and a couple of trips to Google, I had a simple object mapped to a table and was happily completing operations within my applications controller using Castle’s friendly syntax.

My first thoughts have been very positive. I had much less to do in the way of configuration than when using NHibernate on it’s own. This held true for both the general configuration (Indeed, ActiveRecord did not require any alteration of the web.config at all!) and on an object to object basis as mapping is done by the assigning of ActiveRecord attributes to the properties of the corresponding class (No more XML mapping files to maintain.)

If he is aware of just how number of times I end up on martinfowler.com, I am sure the premier Calgarian geek might think I am virtually stalking him.

Today’s foray was to find out more about fluent interfaces and method chaining. I have been using Phil Haack’s HttpSimulator quite heavily in the last few days and want APIs that I write to be as easy to use and part of such readable code.

For example:

using (HttpSimulator simulator = new HttpSimulator())
{
  simulator
   .SetFormVariable("Test1", "Value1")
   .SetFormVariable("Test2", "Value2")
   .SimulateRequest(new Uri("http://localhost/Test.aspx"));
}

Today whilst writing some tests utilising some legacy code (Legacy code is any code without tests!), I encountered a null reference exception as references to the HttpContext have made it into the business layer I was using. No IIS … No HttpContext … Thanks to Jason Bock and his wonderful article I will be back in business tomorrow!

I was sold after I added the following test to his tests. The cache object in particular was something I wanted to “mock”.


[TestMethod]
public void UseCache()
{
  HttpContext context = (new MockHttpContext(false)).Context;
  context.Cache.Add("test", "test value", null, DateTime.Now.AddMinutes(1),
    TimeSpan.Zero, CacheItemPriority.Normal,null);
  Assert.AreEqual(context.Cache.Get("test").ToString(), "test value");
  Assert.AreEqual(HttpContext.Current.Cache.Get("test").ToString(), "test value");
}

The article is well worth a (re-) read as it is a great “how-to” for using Reflector

My last little while has been spent getting my EeePC configured just as I want it. Being a C# developer, I wanted to make sure there was nothing I would not be able to “try out” on the train journey to and from work. (or any spare 30 minutes or so to be perfectly honest!) That meant I needed Visual Studio 2008, SQL Server and a source control solution.

I have never been a masochist so I waited until I had upgraded the RAM in the EeePC to 2Gb; although SharpDevelop performed admirably with the previous 512 Mb incarnation, the lack of ASP.NET hampered it’s usefulness to me. After adding a 6Gb SD card I was ready to start.

Firstly, XP with all the updates to the solid state hard drive. You must make sure to use NTFS as you will need to mount the SD card to an empty directory inside this drive. Then install VS 2008 as usual with the target as inside the SD cards mounted directory. I then un-installed SQL Server Express and installed it with advanced services to get the Management Studio. I then installed svn1click and presto … my Developer EeePC.

I have been using my EeePC for everything at home this week, including using Terminal Services into work. It has performed wondrously and I have had the opportunity to sit in the living room with my gorgeous wife whilst still getting my geek face on!

Monday rolls around and again I find myself blogging on the train ride home reflecting on my day. The similarity of the words mundane and Monday is never lost on me on Monday mornings. The commute is dreary with seldom a smile to be had from the disgruntled masses. Follow that with the weekly development meeting, updates on the previous week’s support calls and all told lunchtime Monday is the “true” start of my week.

After the midday sustenance it seems motivation levels in my office are at a really good level. Having dispensed with our earlier mentioned administration tasks we are on to the nitty-gritty of our various projects. This weeks is one I hold quite dear; the automation of unit tests for the user interface.

I spent a thoroughly enjoyable afternoon constructing the first of automated tests using WatiN along with the three other members of my team. It was “quad” programming at it’s best! In addition to bringing us all on to the same page regarding the use of the new tool to automate IE, the session yielded an impromptu “style” to the tests and helper methods we intend to create. Hopefully, tomorrow we can apply the lessons of this afternoon to the tasks of scripting the tests for the newest component of our software suite.

WatiN (Web application testing in .NET) is based upon WatiR and is an open source tool for automating the testing of Web applications. It comes with all it’s source code (in C#) , a test recorder and MS Excel importer.

Some WatiN resources:

WatiN Project
Recorder
Adam Esterline’s Blog

Later in the week I shall review how I have found it to use but thus far indications are positive.

I had a phenomenal day today. With a few pointers from a couple of my colleagues (Thanks Tom and Isiah), I wrote some of the best code I have ever written.

Whilst working on some Test Utility Methods, I noticed I had a few methods that were basically duplicate code with the exception of their return type and the type they used inside the method (the same type.) Previously I had only used generics in enumerating collections; Tom mentioned if I could get the conceptual “Penny to drop”, this was another example that lent itself to using generics.

My refactored code looked something similar to this:

public T SomeMethod<T>()
{
T myObject = AnotherMethod(typeof(T));
return myObject;
}

In my new role at Biomni, we use TypeMock as a mocking framework. My experience of mocking is quite limited so I haved embarked on an investigation of what features are afforded within the Community Version of TypeMocks and more poignantly how to go about using them.

Features

  • Simple Mocking
  • Return Values
  • Throw Exceptions
  • Check Sent Arguments

Coming to the realization that I have programming heroes was another of those little epiphanies that I have had over the last little while. One of these cerebral super-heroes is Dave Thomas of Pragmatic programmer fame. His articles on Code Kata inspired me to take up the practice myself. In fact, the second of my exercises is the second in those he sets out, a binary sort. (I must admit I like the martial arts theme he uses in calling it a Karate Chop!) The practice as he set it out is quite a tough one; to find five different implementations over the course of five days.

Specification

Write a binary chop method that takes an integer search target and a sorted array of integers. It should return the integer index of the target in the array, or -1 if the target is not in the array. The signature will logically be:

chop(int, array_of_int) -> int

You can assume that the array has less than 100,000 elements. For the purposes of this Kata, time and memory performance are not issues (assuming the chop terminates before you get bored and kill it, and that you have enough RAM to run it).

Next Page »