🎥Video Demo: Video Demo
Description: This is a simple Python CLI game. All you do is just move the player to push a box through a grid of obstacles, like a simpler version of Sokoban.
Using the WASD keys, you have to push the player. Do note that it is not possible to pull the box towards you, so if the box is next to a wall, it may not be possible to move it away.
⚙️Techincal details
For those who want to know more in-depth about the code.The game code, in my opinion, could have been simpler. In essence, the game randomly generates three different coordinates, the player's initial position, the spot you have to move the box to to complete the level, and the object's initial position. Then, this is put onto a grid.
I wanted to make it easier to do the input, so that you dont need to press enter every time you input a character, so by converting the terminal to a raw state, input is gotten as soon as you type it, without need to press anything else. The terminal is then switched back to allow for proper display of grid
As a anti-fan of functions, my friend forced persuaded me to use more functions to make the code look cleaner.
In some of the text printed, I used ANSI escape codes, while slightly cryptic, do make the text on the terminal ever so slightly better. They also help improve the visibility of the player, the box and the goal spot. The obstacles were intentionally made to be white, just to make visibility slightly harder, especially in later levels, adding an element of challenge (or i was too lazy to color them)
I still have not found a fix to the slight flickering on terminal refresh, but that was set quite low on list of priorities
Initially I had some really stupid ideas to prevent softlocks, none of them worked/ are actually foolproof. I wont detail them to spare myself, and possibly you reading this, but the eventual solution was to do a slightly complex version of Depth-First Search from the box to the winning position. This version takes into account the fact that the player has to push the box, which was not too hard surprisingly. The main pain however was the error checking. Since this was my first time doing Depth-First Search, I kept getting recursion errors. I caved and used AI to help me find the errors, but that proved to only be partially helpful. In the end, I had to convert some of the values into tuples bcos python needs it to be the same data type for comparison to hold true
As any game developer knows, you must have the most complicated foru=mula for calculating score (/j). Mine is just overy complicated for how simple it is, but it works. Since time and moves play such a huge factor, most of the points are gotten in the first few levels. Generally, in the later levels, scoring triple digit points are very hard, mostly you get 2 digit points or even one digit.
I do have plans to possibly add more features, but we'll see