Amazingly Raku

Part 6: The Second Game

by Arne Sommer

Amazingly Raku - Part 6: The Second Game

[94.6] Published 9. December 2020.

See also: The Introduction | Part 1: The Maze | Part 2: The Path | Part 3: The Wall | Part 4: The Class | Part 5: The First Game.

This part focuses more on the functionality («how to play the game») than the actual code, but some code snippets have found their way here.

GTK Revisited

The «GTK::Simple» module does not support keyboard interrupts, as described in the previous part. But the «Gnome::Gtk3» family of modules do.

So naturally I had a go at it. It was a lot of work, as the library (or libraries, rather) is large, pretty low level, and it is the first time I have looked into Gtk.

amazing-gtk

The program mimics the Termbox version as much as possible, but the coding structure is slightly different. The supported options differ, as a graphical user interface gives better ways of doing some of them (i.e. Buttons).

The game will generate a random maze for you, unless you specify a maze file on the command line. The generated mazes will always be traversable. The default size is 25 rows and columns, but this can be changed with the «-b» (box), «-c» (columns) and «-r» (rows) command line options - in the same way as with the «mazemaker» (and «amazing-termbox») program.

$ ./amazing-gtk -b=10 -c=25

You start out in the upper left corner (the entrance), and the goal is to reach the lower right corner (the exit). The current position is shown in yellow, initially at the entrance. (Note that it is not shown before the first move. This is a bug.)

You can restart the game with the «F1» (smaller), «F2» (same size) and «F3» (larger) keys, but only when you are at the entrance or the exit. use Control-C to exit the program at any time.

You can change the zoom level with the «+» (plus) and «-» minus keys (on the main part of the keyboard, not the numeric addition). The lowest value is 1, and the highest is 5. The program start at zoom 1, unless changed with the «-z» command line option.

$ ./amazing-gtk -z=4

Navigate with the arrow keys on the keyboard. You can (obviously) only follow existing paths.

The path that you have taken is highlighted in blue, to make it easier to navigate (but this can be disabled with the «-n» command line option).

You get a summary on the message line when you have finished the game (traversed the maze).

You can also save the maze for later with the «Save» button, but only after the game is finished.

Note the filename. The maze size (rows and columns) are included in the filename.

Click on the «Path» button to highlight the shortest path. Note that the path you took through the maze (the blue symbols) are lost when corresponding with the shortest path. (This is not optimal, and is subject to change.)

The game is fully playable.

Note that installing the «Gnome::GTK» module will probably fail on Windows.

The description above tells only part of the story. You can get the full list of options by running the program with the «-h» (or «--help») command line option:

$ ./amazing-gtk -h
…

Part 7: The Editor

See the next part; Part 7: The Editor where I present a maze editor.