Since several years, I give a free project to my students as last assignment in C and shell. They have to come up with .. something. I encourage them to fix bugs in some free software, or write a little game, possibly inspired from one of the many flash games around. Most of them choose the second solution, some of them implement some non-fun (but also instructive) project like a constraint solver or mini-matlab.

This assignment turns out to be rather difficult for the students, maybe because it comes at the end of their first year of programming, so that's a bit early. That's their first big C project (and for most of them, last one too), and they are quite unprepared to this.

To improve this, I wrote a while ago this lab about writing games using the Allegro library. When doing so, I hesitated a bit because the version 5 of the library, which somehow redesigns completely the lib, is underway. Some say that it may be ready by the end of the summer, but as usual in free software, there is no guaranty.

So, I had to choose between writing a lab on something soon out-of-date (allegro v4) or write a lab on using some not-beta-yet software (allegro v5). I took the second way :) I think that such tutorial is a good thing since there is not too many about it from what I've seen. That is why I wrote this in English instead of French as the other labs I usually write, actually.

The game to code is a 7-colors (even if I discovered this afterward). The board is split along a rectangular grid. Each of the 2 players start by owning a cell in one corner and choose one color at each round. He wins every cell of the board adjacent to its zone and being of this color. Well, that's a bit hard to explain, you'd better test it: download the binary (statically compiled for linux). You also need the used font.

The source of the game is naturally not provided since the students actually have to write it. But if you're a teacher yourself and are interested in the code to improve it or simply use it in your course, just drop me an email, I'd be glad to share it with you.

Welcome screen Playing against an AI
A match between AIs The same match a bit later. Spider is really deceiving.

I choose this game because it's simple, and there is no sprite to deal with. The lab is very authoritative because it targets beginners. I tried to insist on how to write good C code (naming convention, modular design) coming from what I've found working in SimGrid. Also, I enforce a MVC approach for the graphical interface. As a justification of this, it allows to have several instances of the game represented as (ugly) icons to choose between the differing possible game parameters. I also request the students to write several AI for this game, using multiple implementation of an interface (using function pointers).

I plan to do some other such labs. Another area where my students have difficulties is collision detection. I saw awful solutions to this problem this year.

I was thinking of a chain-reaction game like Polygonal Fury. That's a good one because there is some sprite (that should get introduced at some point), and because what you are looking at is 'all the elements within this radius'. I'm still unsure of how you should implement this (I'm quite lame in geometrical algorithms), and I'll eagerly test several solution on my path when implementing it to write the lab file.

Another interesting game would be Snipes!. First of all, I spend an incredible amount of time on this little game when I was kid (and my kid love to play it in dosbox), and then, I guess that the collision must be solved completely differently here. I'd do a bit grid of positions (one for each displayed char) and put a pointer to each cell pointing to the element currently in this cell. This makes the collision detection quite trivial, but this is not adapted to the chain reaction game because there is no real cell. Also, this promises to be a big mess of pointer handling, which is exactly what the students need to get acquainted to this beast.

But as usual, I'm not quite sure of when I'll find the time to implement these things and write the associated lab. For the record, contamine took me more than three days.