online lostsh.github.io small-games | 2018-2020 rfc 3514: evil bit not set
post 01 2018-11-26 c99 | python3 | php | c++ 3 games

Three small games

c99 | python3 | php | c++ 3 posts merged

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

original post 2018-11-26 c99 | python3 | ascii

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:

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.

Terminal recording of the C99 hangman: the line "you have 10 chances left.", below it a guessed S followed by asterisks for the letters still hidden, and a prompt waiting for the next one. Terminal recording of the Python 3 hangman: the gallows part-drawn in ASCII bars, with a row of dashes underneath standing in for the letters left to guess.

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

original post 2020-02-27 c99 | c++

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:

The Arduboy OLED showing the game's menu: PONG in large pixel letters, and under it two buttons, one reading START, highlighted and marked with a cursor arrow, the other reading SETING.
The menu. The second button says SETING, and it shipped that way
Photograph of the clear-shell Arduboy, board and chip visible through the case, running the game: a paddle at each side of the screen, a dashed centre line, the ball mid-flight and the score reading 0 to 1.
Two-player mode, on the hardware

Source: arduboy_pong-game.

Morpion: tic-tac-toe in PHP

original post 2020-11-20 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.