Welcome to Snakes and Ladders, a classic boardgame enjoyed by children (and adults) throughout the world.
It's a game of simple logic and chance making it a suitable project to learn Python. I do hope you enjoy this take on the original!
The game's logic was mapped out before coding began using a free version of Lucidchart.
This web based platform is intuitive to use due to it's drag, drop and snap capabilities.
Three additional game rules can be applied for extra complexity.
- Each time a player throws a 6, they are entitled to roll the dice and move again.
- If a player's pawn lands on a square occupied by an opponents pawn, that pawn is removed from the board and they must start again.
- An exact throw is required to reach square 100. If the throw exceeds 100 the player must move backwards. Watch out for the snakes!
The game was developed at 1920 X 1080 pixels. No real responsiveness has been built into the browser due to the backend nature of the project. That being said, I used Dev Tools F12 in Google Chrome to test and position the terminal element to width:115% and height:85vh within the css inline code in layout.html. This ideally positioned the svg background against the terminal.
Despite the frontend being a secondary concern I wanted to engage the user by:
- providing an image that conveys that the game is Snakes and Ladders.
- giving the
buttonelement in the webpage a bespoke title referencing the classicCLICKMEconvention. Since we are programming and snakes do what they do,bitebecomesbyte.
(I know, I hope my code is better than my humor!)
It is customary to give a game a start screen before entering it menus. This was incorporated due to user expectations during the testing phase..
Menu options are color coded and given intuitive titles for the user.
The game rules can be accessed from the main menu.
The user can view the game board from the main menu for an appreciation of how the game board displays at the end of each turn.
The user can select a validated number of players for the game between 2 and 4 with full error handling capabilities.
The user is asked if they want to quit the application. If yes, the application closes down. If no, the main menu is displayed.
Built in error handling accepts all case variations for Yes/No. An invalid input asks the user to retry.
In game, a player can land on a normal square.
Land on a snake and move to the bottom of that the snake.
Land on a ladder and move to the top of that ladder.
Reach or move past 100 therefore win the game. If they win they are asked to return to the main menu.
An addendum was made to the game following user feedback. Users didn't know for how long the game was running and this was confusing/frustrating. A counter was added and displayed for each turn to facilitate their requests.
A few formatting tweaks were also added on request.
The live application can be viewed from this link.
Go to DEPLOYMENT.md for detailed instructions to deploy application to Heroku.
Extensive testing has been undertaken to prevent program crashes or unintended actions. Go to TESTING.md to view known bugs and fixes.
Code in run.py successfully meets pep8 standards using the linked validation tool.
Flowcharts created with Lucidchart.
Web deployment using Heroku.
SVG background in browser generated using Convertio and edited using Boxy. Both were free to use. (Note, this was nothing more than a personal/fun touch but I hope it reinforces to the user as to what game they are playing)
Python version 3.8
Additional Python libraries used:
- os to clear terminal window & center display
- time to produce time delays to user inputs
- random to simulate dice roll
- colorama to beautify display
- termcolor to beautify title
Thank you to my mentor Tim Nelson for his candor. Fantastic as always.
Beyond the Code Institute LMS a few key sources cemented my understanding of how to combine working with loops, dictionaries and classes. In particular, accessing their attributes and using them within loops, lists and dictionary comprehensions.
To repeat the same iteration of a loop depending on a condition.
Error handling for empty and non integer values at the same time.
To replace all occurrences of an element in a nested list
To clear the terminal window.
To center content on the terminal window
To display a more traditional game board layout.
And to provide the board's text/alignment some uniformity.
How to be PEP8 compliant when working with long f-strings
Inspiration to use a SVG background in the browser.
- Matt Bodden. A fellow student at the Code Institute. We have never met though I appreciate the quality of his content.
Emojis from Emojipedia.
- Balloon
- Chequered Flag
- Snake
- Paperclip (analogue was used as ladder unavailable)
Board image courtesy of iStock.
Browser background from Wallpaper Cave. This was converted to an svg format to enable browser display.
SNAKE_HEAD and LADDER_FOOT dictionaries based of a game purchased from Ambassador Games.














