Saturday, November 28, 2009

Windows user name in C#

Problem:
How do I get the Windows user name in a C# application?

Solution:
It's located in Environment.UserName, this will show you a dialog box with your Windows user name.
MessageBox.Show(Environment.UserName);

Maze: Movement and scoring updated

After some play testing I decided that the movement algorithm needed some update. Previous version simply queued all my waypoints, so if a monster arrived so could do nothing. Now each click will replace the current route, making it possible to turn immediately. To make the goal of the game something more then just collect all coins, I also introduced a cost for each movement click. So now your total score will be the coins you collected minus number of movement clicks you performed.

For the visual aspect I added a rectangle on each square that is included in your current route. I think this needs some more polishing, rectangles are quite ugly. There is also a need to show the path that will be selected if you click the mouse, otherwise you will sometimes get an unwanted path.

Status: Game is playable, although visuals could be greatly improved.
Fun level: Low
Sticky factor: 30 sec

Friday, November 27, 2009

Unfinished projects

I have an long record of unfinished game projects. I wrote my first C++ back in ´92, since then a lot of projects has been started, although very few of them has reached the goal. So lately I have focused on actually creating small working games.

Current project is a collection of small games in different genres. Its mainly to learn different types of mechanics and finding the fun. Both in the game and in the developing!

Maze: Heavy influenced by Pac-man.
Being used to create turn based games I wanted to explore the real-time genre. As a bonus I get to do some basic AI for enemies as well. Also pondering on the steering, currently using the mouse to set way points. You can find source code to this game here.
Screenshot on the status of 2009-11-27.

Thursday, November 26, 2009

Syntax highlighting

Problem:
How do I get a nice Syntax highlighting for source code on this blog?

Solution:
Google pointed me in this direction. Here is also some nice examples of how to implement it for Blogger users.
This is the result:
public void Test()
{
Console.WriteLine("Hello World");
}

Display information in Visual Studio Error List

Problem:
I want to display information in Visual Studios Error List. So when I build my solution I'll get compilation issues and unit test information on the same place.

Solution:
Googled for a while and it turned out that this is actually pretty easy!
So now I have a this piece of code in my unit test framework:
public static string CreateErrorMessage(string message)
{
StringBuilder builder = new StringBuilder();
StackTrace trace = new StackTrace(true);
StackFrame frame = trace.GetFrame(3);

builder.Append(frame.GetFileName());
builder.Append("(");
builder.Append(frame.GetFileLineNumber());
builder.Append("): error MUNIT001: ");
builder.Append(message);

return builder.ToString();
}

Unit testing in Visual Studio Express

I try to use a test driven approach when I develop. During the years I have gained a lot of positive feelings from unit tested code. Using it in small hobby projects sometimes add a lot of work without the benefit of having unit tests in place for later changes. Although I have decided to use it whenever I code, just to keep learning the practice of test driven development.

Reporter: But Magnus, why did you implement your own unit test framework? There are a lot of them out there!
- Good question. I checked out two of the options for .NET
NUnit, the mother of all unit test frameworks on .NET platform.
I have used this for quite a long time with an postbuild option to run tests as command line. Although with express edition you get a separate test runner and there is a twist to get debug to work with your unit tests.

ExpressUnit, a newcomer for the express edition.
It looked promising and it might probably have solved my problems, but I didn't fall for it and when the GUI test runner showed up I decided to try out my own way.

Reporter: And...
- Being a long time NUnit user I felt that it was time to find a easier way to do unit testing in express edition. ExpressUnit gave me some ideas on that it should be possible. My developer brain then turned into action and it didn't last long before I found myself in a really interesting project of creating my own framework.

Reporter: So, what is the result?
- As every good unit test names are already used it became grimmyunit. Main feature is that it's very integrated into my own development process. I create two projects, one for the unit tests and another one for my production code. Then I write tests and implement code, to run the tests I simply rebuild the test project. The output is displayed in Visual Studios Error output as clickable information. So if I have a failing unit test I can simply click on the error and the code is shown.

First revision.

Hi there,

Welcome to this little corner of the digital universe. This is my place and here I will collect all my thoughts regarding my own development projects. As a hobby game developer I need somewhere to put my state of mind.

So what content will end up here?
  • Development problems and hopefully solutions.
  • Game design issues.
svn commit -m "First entry for the blog."