TankWar Online, my JavaScript based cannons game

June 30, 2009 – 5:38 pm Tags:

Back in late 2006 I wrote my most ambitious JavaScript/game project so far: TankWar Online, which as you may guess from the name was about tanks, shooting stuff, and it had a real-time online game mode - as far as I know, the first such ever in a JS based game.

Originally the game was made for an older version of Opera 9, and only worked in it. However, I have now modified the game so it should work in most browsers (tested Firefox, Opera 9, 10).

Click here to play cross-browser version of the game. The game should work for other parts than the online game mode, as the server is no longer functional.

Interested in hearing how the game works, such as terrain, physics and the computer AI? Keep reading!

Read the rest of this entry »

Unit testing 4: Mock objects and testing code which uses the database

June 26, 2009 – 6:13 pm Tags: ,

After learning to write tests and some good testing practices, it’s now time to look at mock objects.

When testing a class which needs an instance of another class to work, you do not want to depend on the other class too much. This is where mock objects come in - a mock object is a “clone” of an object, which we can use to simplify our tests, by having the mock object perform assertions or by replacing some functionality of the mock with our custom functionality.

In this post we’ll first look at how mock objects are created and used with PHPUnit, and then we’ll take a practical example of using mocks to test code which uses the database to fetch some data.

Read the rest of this entry »

Unit testing 3: Writing tests for existing code

June 17, 2009 – 10:30 pm Tags: ,

Now that you know what unit testing is and how to write and run tests, it’s time to look at writing tests in more depth.

Today we’ll take an example class and write tests for it. We’ll also introduce some common testing methodologies.

Read the rest of this entry »

How WidgetCity does a tile-based map using just CSS

June 15, 2009 – 2:38 pm Tags:

My city building game, WidgetCity, displays the city as a table, each cell of a table representing one tile.

The tile map is done purely using just CSS, and CSS classes. The map is also scrollable.

How is this all done?

Read the rest of this entry »

Unit testing part 2: Writing and running tests

June 10, 2009 – 1:44 pm Tags: ,

Continuing from the unit test introduction, we will now continue and take a look at how to write tests and ways to run the tests.

Read the rest of this entry »

Refactoring

June 8, 2009 – 8:14 am Tags: ,

Today I’d like to point out a bunch of good articles about refactoring - the process of improving code without changing the functionality.

Sameer Borate has written four posts about the topic in his blog, and I encourage you to check them out:

Unit testing: Introduction

June 5, 2009 – 8:43 pm Tags:

Due to popular demand, I’ll be writing a bunch of posts on unit testing.

In this post I’ll introduce unit testing: What it is, when it’s a good idea and when it might not be. I’ll also discuss a bit about what makes for a good unit test.

Next week I’ll post a followup to this, which will be more about actually writing unit tests with examples.

Read the rest of this entry »

What would you like to read about on CodeUtopia?

June 2, 2009 – 11:07 pm

I haven’t had much ideas to write about lately, so how about this: You, my dear readers, get to tell me your favorite topic that you’d like to read/learn about.

Is there a specific topic you would like me to write about? As long as it’s somewhat relevant to this blog’s past content, post your idea to the comments! - I just might pick your idea and write about it. I even might pick more than one.

It doesn’t matter if it’s a small thing or a large thing. If it’s interesting, it’s good! It can be a general topic, like Zend Framework or design patterns, or some more specific thing like “how to do X”

Should I try Git if Svn/CVS/other works for me?

June 1, 2009 – 6:22 pm Tags:

I’ve been using Subversion for quite a while, and while it has some minor annoyances like complex merging, it never really bothered me.

Then along comes Git, touting that it’s easy and that you’re stupid if you don’t use it. The technical stuff people said about it were impressing, but not enough to actually warrant trying it for me - Afterall, I was quite happy with svn, as it did what I needed.

After a while, I decided I wanted to try Git anyway - just out of curiosity, to see if it actually was so amazingly much better. And in this post I’ll tell you if it was

Read the rest of this entry »

How to pass variable values to JavaScript

May 22, 2009 – 3:45 pm Tags:

A relatively common task in today’s Web 2.0 apps is passing values from a server-side script (or through a link) to JavaScript, affecting the client-side script execution.

Not surprisingly, there are a few ways to do that. Let’s look at three and their pros and cons:

  • Embedding scripts into templates
  • Passing variables in URLs
  • Using configurable scripts

Read the rest of this entry »