When submitting to Heroku by following the steps below, after the receiving the message "Your app was successfully deployed". The "RUN PROGRAM" button returned this error message: "pygame.error: No available video device".
This was the same error message that I received when first creating the game in GitPod. Hence, my decision to use Replit, another program recommended by Code Institute. They advised me to create an account when signing up to the course.
Below this section is a join link to the Replit file used to create and test the game. The GitHub repository containing the run.py file is an exact copy.
Unfortunately, I was never told that Pygame was incompatible with Heroku until the 15th January 2022 via a tutor support call view log. No concerns were ever mentioned in my mentor meetings throughout the project.
For the Replit join link, click here.
Welcome to Python in Python. Based on the mobile game Snake. It was extremely popular when mobile phone had physical buttons rather than the modern touchscreens we see today. The aim of the game is to move the "snake" around the screen, collecting the "food" and not hitting the walls or crossing through yourself. Every time the food is collected, the snake grows, along with your score.
- As a first time visitor, I want a clear understanding as to the objective of the game.
- As a first time visitor, I want the controls to be as simple as possible.
- As a first time visitor, I want to have live scoring.
- As a first time visitor, I want to enjoy the game and come back again and again.
- As a returning visitor, I want to enjoy the game as much as I did the first time.
-
- The snake board is set on a dark chequered background #202937 - RGB (38,52,69) #263445 - RGB (32,41,55).
- A bright green is used to show the snake - #009f00 - RGB (0, 159, 0)
- A dark red is used to represent the apple - #c80000 - RGB (200, 0, 0)
- White is used to show the live score.
- Game over interface is a simple black screen and white text.
-
- One typeface is used to show the scoreboard (Courier). This is used as it brings an arcade like feel but is clear to read, especially when in white on the dark chequered background.
- The "play again" message shown when the game is over is displayed in Helvetica.
- Lucidchart - View
Below is a brief overview showing the main features of the game.
- The use of the dark chequered grid background makes the game more appealing than a boring black and white design. The snake and apple size matching the grid size (20px) shows a clear indication of where the snake and apple are and when to use the direction arrows on the keyboard.
- This is a stereotypical feature of the game Snake and works in the exact same way. As the snake collects and eats the apple, the snake body increases by one square, making each level more and more challenging in terms of the player avoiding crashing into any part of the snake.
- The normal mobile features continue and not only does the snake increase in size but the speed of which the snake moves around the board increases too.
- When the snake has eaten the apple, the score increases by 10 points.
- Whilst playing the game, multiple print statements are used, including:
- "Press any direction key to start the game." - This is displayed as the game loads and prompts the user to start using the correct keys.
- "Unrecognised command." - This is printed if anything but an arrow key is used during the game.
- "Well done! You ate the apple." - Prints every time the snake and apple position are an exact match.
- "Game over! You hit the wall." - If the snake exceeds the screen width or height, it's game over and this is printed in the console.
- "Game over! You hit yourself." - This is printed if the snake head is in contact with any part of the snake. This is also displayed if the snake reverses into its self (over 3 squares in length).
- "Final score: ..." - At game over, the final score is printed to the console using the f-string of snake_score.
- Eventually, when your turn is over, you have the option to play again or quit. If the user selects play again (Y) the score is reset to 0 and the snake size and speed is back to the default.
- "Mirror walls" - Instead of the game ended when you hit any of the four walls, the snake would appear from the opposite wall and back into the grid. This was a feature that was created for Snake II.
- Python
- Replit
- Replit was used instead of GitPod due to the functionality issue with the Pygame module. All coding and testing was created in Replit.
- GitPod
- GitPod was used via the terminal to push changes to GitHub.
- GitHub:
- GitHub was used to embed the site and store all imagery.
- Heroku
- Heroku was used to share the app online.
- Lucidchart
- Lucidchart was used to create the step by step workflow to visualise the game.
The PEP8 Python linter was used to ensure there were no syntax errors in the project. On the first use my code produced over 45 warnings and/or errors including:
- "blank line contains whitespace"
- "indentation is not a multiple of four"
- "line too long (93 > 79 characters)"
These have now all be rectified and the link to the results text document is below.
Q1. As a first time visitor, I want a clear understanding as to the objective of the game.
- Since Snake was created in the late 90s, it has appeared on over 400 million mobile phones. There were no hesitation from the users playing this game.
Q2. As a first time visitor, I want the controls to be as simple as possible.
- It doesn't get much easier than up, down, left and right.
Q3. As a first time visitor, I want to have live scoring.
- The way the scoreboard is presented is easy to read even while concentrating on the game. The white makes it stands out from the grid and the Courier typeface give it a more game like feel rather than uses something standard like Arial for example.
- Keeping the score on the screen when the game is over is important, as it's not always possible to look at the score while playing the game, especially as the speed increases.
Q4. As a first time visitor, I want to enjoy the game and come back again and again.
- It's a classic game recreated and brought up to date. It was really addictive, just like the mobile version was years ago.
- Friends and family members were asked to review the game and documentation to point out any bugs and/or user experience issues.
- Gitpod and Heroku not displaying the game ("pygame.error: No available video device")
- End game message "\n" (new line) not working on display.
Heroku was the program used to share the game, it was accomplished by using the following steps:
-
Log in to Heroku. On your dashboard, click "New" and then click "Create new app".
-
Fill in the field for App name - It must be a unique name to Heroku.
- Then select the region of Europe and click "Create app"
- In the "Settings" tab, scroll down to "Buildpacks" and click "Add buildpack".
- Select "python" and click "Save changes"
- Select "node.js" and click "Save changes"
- Scroll back and click the tab "Deploy"
- Choose "GitHub" as the Deployment method
- Enter the GitHub repository name and click "Search"
- The repository should appear below, then click "Connect"
- Then click the "Deploy Branch" button in the "Manual deploy" section. This way you can see the code being written.
- Once that is complete, a message will appear with "Your app was successfully deployed" and a "View" button. This will take you to the app directly.
-
Title in Pygame window. Stack Overflow
-
Chessboard grid Stack Overflow
-
Pygame.rect - Draw rectangle pygame.org
-
Blit - Show score on grid Stack Overflow
-
Increasing snake length CodeWithHarry
- All content was written by the developer.
-
Pygame Module - "a set of Python modules designed for writing video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language." pygame.org
-
Random Module - "The random module is a built-in module to generate the pseudo-random variables. It can be used to perform some action randomly such as to get a random number, selecting a random element from a list, shuffle elements randomly, etc." Tutorials Teacher
-
My Mentor for answering my questions throughout.
-
Slack users for constructive feedback, suggestions for improvements and video calls.