© 2025
gridranger
Project done!
Video games that made me learn
Blaugust: Introduction
Blogger Takeout Viewer
Treasure of the Pirate King
Chimera Squad
About the icons
Family history
Random facts about me
Degoogling
Discovering the web-browser module
`partial` and `partialmethod`
WinRar icon, red, blue and green books strapped together with a leather belt. Archives
A colorful folder icon from Windows XP. Categories
Treasure of the Pirate King - 2025-07-15

The Treasure of the Pirate King

I just found the short blog I wrote while developing this video board game. That's what got me started learning Python development. I had an idea for a board game and wanted to test it on a large scale to see if it was balanced. Learning Python sounded like fun for that purpose. I read Gérard Swinnen's GNU-licensed book about Python programming and learned the basics out of pure curiosity. Back then, I had no idea how much Python would change my life by opening the door to a new passion and profession.

Getting started - 2013-02-26

Now that I have planned the game, the first step is to create the pathfinding algorithm. I created a class that renders the board, as well as a method that calculates the possible target spaces the player can land on. I also added a method that adds a wind modifier to the rolled value. For now, it's just a stub that returns a modifier of 0.

A screenshot where a part of an IDLE (built-in Python editor) window is visible. A Tkinter board with some green spaces on white background is also there.
The debug messages in the Python Shell window says that "I can take 6 steps" to all (W, N, S and E) directions.

Running Python scripts from Notepad++ - 2013-02-28

So far, I've always run my code with Idle, the editor bundled with the Python distributions. But I miss the flexibility of Notepad++ from it. Now, I took a deep breath and configured Np++ to get the script running capability. The steps I took were:

  1. I installed NPPExec plugin under the Plugin manager in the Extensions menu.
  2. In the Extensions menu Execute... option I save the following to commands:
    d:\userapps\Python33\python -u -i

    d:\userapps\Python33\python -u -i $(FULL_CURRENT_PATH)
Screenshot of the Execute... panel of Notepad++

I also set to start the console automatically once NP++ launches and start the Python interpreter inside under Extensions / NPPExec menu / Advanced options... This way I'll always have a Python console to experiment. And I can launch the script I edit by pressing F6.

Screenshot of the game cannon battle.
An example app from the Python book I learned from. It is running under Notepad++

Language module - 2013-03-06

I'm done with the language selector part of the game. Language resources won't be part of the code but are stored in simple XMLs so they can be extended even without any development experience.

I also wrote the settings save/load part to preserve the player's configuration preferences between sessions.

You can see part of the code and the language selector.
Languages to select: English, Pirate dialect and Hungarian. Don't judge me on mixing languages in method and variable names. It was my first project. 😅 I've never done that later.

Porting - 2013-03-10

The language, I use to write the program, has two competing versions. Python 3 is definitely the future, but plenty of packages only support Python 2. For example, I can't find a suitable package to display vector-graphic images in TkInter. If I find only a Python 2 module for the purpose, I'll have to upgrade that for Python 3 myself. It's cool that there 2to3.py exists, but I wonder if a greenhorn like me can use it to convert full packages without breaking them.

Command line screenshot of using 2to3.py

The game board - 2013-03-12

It's done. It seems vector graphic rendering is not supported under TkInter. The solution I've found would have multiplied the game's size tenfold, so I scrapped the idea. It still looks great. The trade-off is that I have to pre-render the graphical assets to the highest resolution and that will cap the game to 1920×1080. Of course, I can reexport them later once the higher resolutions displays are more common. Everything else besides the pngs scales dynamically. For lower resolutions downscaling is easy at game load and on resolution change.

This is the board of a pirate themed desktop board game. It features a map of the Caribbean as the background. Around and across the board there are spaces with different images. Its main colors are the different shades of brown and red to resemble an aged paper map. The images are cartoonish vector drawings.
Image of the planned game board exported from Inkscape. The towns are starting fields but serve also as bases for the players. Many of the fields change the wind direction, or grant extra turn, or make you miss a turn. Others give you treasure or lead you to battle. Outlines to show where the drawing decks and discard piles go. The ships on the sides serves as the battlefield for PvP and PvE encounters.
This is the board of the video game version. Images on all fields are rotated so that the user can see them from their perspective. There are no ships on the sides nor is there a place for the cards.
Screenshot of the board from the game developed in Python (1024×768)

Stubborn error - 2013-03-18

I've found an error. But not in my code this time.

Since I started using a dropdown widget from the Ttk package, my app has been started throwing an exception on exit. I could simply suppress it, but I hate to ignore problems. I recreated the issue in a sample code and uploaded it to Stackowerflow. The community helped me to overcome the issue in properly.

Saving module - 2013-03-25

This is finished too. It will do the writing and reading operations.

As it can be seen in the image below, the test method passes the data of the three players to the class that serializes it, than starts the saving process.

As a next step, we create a new instance of the data manager class, load the data back from the saved XML and print it. The content of the data as well as its structure will remain the same. Using XML helps me during the development because I can easily create saves with corner cases.

A Notepad++ screenshot showing a short Python code snippet.
Developers delight: when they can read back what they wrote.

The last 18 days - 2013-04-12

Since my last update, I progressed with baby steps only. But many small steps together mean a lot of progress:

  • The method for calculating the wind modifier is ready. Wind direction changes and influences the possible movement of ships similarly to real wind. Displaying the current wind speed and direction is also complete.
  • The GUI now shows the player's wealth and crew.
  • The cities are partially complete. You can hire new crew members and buy larger ships.
  • The saving/loading module has been updated to keep track of the changes. It also saves info such as the number of turns left to skip, and the number of sailors that can be hired in the ports. The number of ships sunk by each player is also recorded.
  • The turn skip mechanics have been implemented.
  • All ship types are implemented (schooner, brig and frigate).
  • Fixed some bugs (e.g. a phantom board appearing after starting a second game, then changing the resolution; the player can't stay in the port if roll less than three, etc.)
There is a pop-up message over the game board telling the player that their turn has to be skipped.
The message says: "Helmsman Snouty* skips this turn. He has one more turn to skip." - *His name is an untranslatable pun.

Event cards - 2013-04-24

Once I've finished the cities, it was time to focus on the event and treasure cards. On the board game version players draw cards from these two decks at different times. In the video game version they are pulled and applied automatically. Players are only informed about the cards, and can take actions when decisions must be made.

Now, the cards are shuffled and shown randomly. The next step is to implement saving and loading the state of drawing decks and the discard piles. Then I'll continue with the actual implementation of the events.

A pop-up window appears over the game map, showing an event card. The card is in black and white and features a compass with a large question mark.
A screenshot of the Python implementation. The text on the card is "Broken compass - The islands have not moved, your compass is broken. You miss a turn while use the stars to figure out the right direction."

Battle - 2013-06-01

Over the past month, I haven't had enough time or energy to continue developing the game as much as I would have liked, but I won't give up on the project. I'm working on the battle module, which is the most complex remaining task. The fight mechanics are working, and you can assign sailors to different locations on the ship. You can win or lose. The only pieces missing are the skills that would make battles more tactical and interesting.

The image shows the battle window with the opposing crews on the sides and the greyed out extra abilities on the top.
The extra abilities in order: gun, rifle, caltrop, grenade, grapeshot, greek fire, monkey attack, siren horn, sirens

Memory leak - 2013-07-12

This picture shows a part of the console and the game's UI at the same time.
I become paranoid when there is an issue and log everything. I log the cards in the decks and piles, the available ship upgrades, and the next player.

I'm done with the battle implementation, but there's still much to be done. Progress isn't always visible or exciting. However, small, boring steps are important, too.

I experienced something interesting last week. I noticed in Task Manager that, whenever I load a saved state, the amount of RAM used by the game increases. I ran a quick test and discovered that the increase was caused by the graphical content. The memory claimed by the images is not released until the game uses more than half a GB. Considering that 30-40 MB is required to play a single party, that's way too much.

I went through the code and found no leaks, so I posted the whole situation on Stackoverflow. I was relieved by the answers. It seems it isn't a memory leak, but the way how Python and Windows minimizes the effort of returning and reclaiming the memory once allocated.

Windows - 2013-07-17

I encountered a strange issue. I wanted to prevent players from closing the battle screen. I added a penalty for doing so, as well as a brief warning message. However, when the warning is displayed, the battle window ends up behind the main window. Therefore, even if the player chooses not to leave, they will no longer be able to find the battle.

There are three small TkInter windows over a PowerShell window. The Beta window sank behind the Alpha window when the Gamma window opened.
I've recreated the issue with simpler code.

I couldn't find a solution to this problem on Google because I couldn't come up with the right keywords. So, I wrote a small test app to recreate the issue with Windows Alpha, Beta, and Gamma. While doing so, I found the solution. The warning message's parent was the main window instead of the battle screen. Cleaning up the hierarchy fixed the problem.

Three small TkInter windows over a PowerShell window. Alpha window is in the background, beta is over it and Gamma is on the top.
Window Alpha stays were it should

Past 80% - 2013-08-26

As it says in the title, the game is more than 80% complete. I've reimplemented the classes that display the cards, and half of the card events have been implemented. However, that was the simpler half, as 30 treasure cards and 20 battle cards have the same functionality, differing only in their arguments. It will take a while to complete the full game, but we're getting closer.


I never finished the game. Later, I rewrote the entire game from scratch to simplify it and clean up the code. Through these two development processes, I learned a lot about clean coding. I improved my use of scopes, namespaces, data classes, and states. I also improved my unit testing and project management skills. The second time around, I got further, up to ~95%. But I still haven't finished it. Yet. 😉