Chess unit builder

As I haven’t added much to my most recent project just yet I wanted to add another example of a different project I’ve worked on. We were working in a group of 5 people and had to make a multiplayer digital boardgame inspired by chess or checkers. For the last sprint I had to prove that I understood how to send and receive data packages to and from the server using the given code. To show this skill I wanted to create a unit builder. The players would be able to draw their own unit’s, give them some stats and be able to save and load those units from a database.

As stated above this was never meant to be part of the game as a feature. This was closer to a passion project within our school project to prove I had developed certain skills.

I started by looking up ways to save pictures to the database, but the best way to do this seemed to involve storing the images to a file system storage. We did not have this at our disposal, so I had to come with a solution. The solution I came up with was translating the images to a string. This was possible because the units only required a 16 * 16 grid of pixels. this meant saving 256 pixels.

This however created a new problem. We were limited to saving 64 characters in a single row. To solve this I wrote a translator that would combine every possible combination of 4 pixels into a letter. This can be seen in the image below.

I had to also add a translation the other way around so the old units could be loaded into the game. To send data to the database we had to make datapackets and send them to the server through the established connection. Afterwards we have to subscribe to a datapacket to receive information from the database. The image below shows the datapacket for the custom units.

The image below this paragraph shows the method that gets called once a custom unit datapacket is received. My teammate implemented a function to make sure we don’t change all sorts of things during an update cycle, which could cause crashes, by adding actions to a queue. At the start of the next frame all actions in this queue get invoked and dequeued

The information is used in a translator that does the opposite of the other translator(this one translates the letters back to numbers). The translation results in an image that is saved as a 2 dimensional array of booleans to see if a pixel should be colored or not.

Lastly the booleans are drawn and saved to an image file, by setting a rendertarget on the image and using a stream to open write to the image file as shown below.

Besides the above I have added a grid that allowed the player to click the blocks to create pixel art and a smaller preview grid, to show what it would look like in the game, that mimicked the large grid. The buttons to give stats to the unit were added, however these smaller features weren’t anything special.