Three small games
Between 2018 and 2020 I wrote three small games (a hangman, a tic-tac-toe and a Pong) and put each one up as its own page. Each page was about as long as a README. They are one page now, in the order they were posted.
A game is a good thing to learn on because it has to be finished. It needs a start, a loop, an input, a win condition and an end, and you cannot leave the win condition as a TODO and still call it a game. That is the whole of what these were for. None of it is clever: they are student projects, the code is ugly, and the only thing any of them had to do was run.
Hangman in C99 and Python 3
The same game twice, once in C99 and once in Python 3, both played in a terminal. The code is particularly ugly, but whatever, it's funny. I would take the time to do something clean when I have a few minutes to spend on a hangman game.
Both versions keep their word list in the laziest place that works:
- C99: words go in
dico.txt, and they have to be UPPERCASE. - Python 3: to add words, go to line 14 and add them to the list. Not a file. Line 14.
What I wrote at the time was that the published version was the minimum version of the game and the next one would be cleaner. The next one never came. What did come, in 2020, was an issue from someone else pointing out that the random word picker repeats itself. Which is fair, and still open.
Those two captures are shown at their original size, 204 and 96 pixels wide. Scaling them up would only make the ugliness bigger.
Source: HangMan for the C99 version, Pendu_py3 for the Python 3 one.
Pong on an Arduboy
Fifteen months later, the same exercise on hardware. The Arduboy is a handheld with a clear shell, a monochrome OLED, a D-pad and two buttons, and the board visible through the case. The game is C99 and C++, and it is only the first version of the code, so it is very ugly.
The old post was a README with a table of screenshots, and there is not much more to it than that. The README part, unchanged:
- Player 1 moves with the up and down arrows.
- Player 2 moves with the A and B buttons.
- One player is the default. For two, open the settings and tick the Player 2 box.
- There is no mute. The post said the function "is not yet available", which was a generous way of saying I had not written it.
Source: arduboy_pong-game.
Morpion: tic-tac-toe in PHP
Morpion is tic-tac-toe. Vanilla PHP, no framework, two players on one screen, and a theme selector, the kind of feature you add when the game itself took an afternoon.
That post had exactly one call to action: a PLAY button pointing at a Heroku app. Heroku ended its free dynos in November 2022 and took the app with it, so the button is dead and I am not going to leave a dead button on a page. The source is still up: more-pion.
The other thing that post had was this, which is the part worth keeping:
morpion.html | 2020-11-20┌─────────────────────────────┐ │ ╔═════════╗ ┏┅┅┅┅┅┅┓ │▒ │ ║ MORPION ║ ┇ GAME ┇ │▒ │ ╚════╦════╝ ┗┅┅┅┅┅┅┛ │▒ ╞═╤═════╩═════╤═══════════════╡▒ │ ├───┬───┬───┤ │▒ │ │ X │ │ O │ ╭╴ ╶╮ │▒ │ ├───┼───┼───┤ │ BY │ │▒ │ │ │ X │ O │ │ │ │▒ │ ├───┼───┼───┤ │ LOSTSH │ │▒ │ │ │ │ X │ ╰╴ ╶╯ │▒ │ └───┴───┴───┘ │▒ └─────────────────────────────┘▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
What they were good for
Not C, not PHP, not C++. What they were good for was the habit of finishing something small (a win condition, a reset, a menu) and then leaving it up where I can still see it. The details I remember writing are the ugly ones: line 14, a dictionary that only reads capitals, and a button that says SETING.