The Snake game is one of the oldest and most popular mobile games that first appeared on a Nokia phone or something. So I set out to recreate that game in Python just for the joke.
I used Spyder.
Modules needed: i) Pygame
ii) Everything else is built-in.
Because I'm bad at initiating stuff, this program was also based on ( read as 'copied from') a YouTube video:
The basic code is the same, I've only made cosmetic changes.
Because this project was basically copy-pasted, I felt a bit guilty ( just a little bit). So I decided to try to add a rudimentary self-playing algorithm.
Basically, I tried to remove the 'game' part of The Snake Game and make it computer automated using a path-finding algorithm.
After hours and hours of searching, I settled on the A* path-finding algorithm to do the work. But I ran into more problems. The algorithm itself was copied from the web and it worked perfectly. The idea was to map out a short path between the head of the snake and the fruit and have the head of the snake follow that path.
The path generated was perfect, but I wasn't able to get the snake to follow the path properly. The snake kept running around like a headless chicken. So I gave up.
Then I decided to add multiplayer capabilities to my game. So I added 4 new parameters to my 'snake' class that details on the movement keys that can be used. For example, the given parameters for one snake can be the arrow keys while they can be WASD for another snake.
But something really unexpected happened.
Somehow....the snakehead had detached from its body. That's not what it was, but that's what it looked like. On further inspection, I found out that the two snakes remained the same colour, the second snake followed the first snake, there was no reaction to the input of the WASD keys and the hitbox on the fruit wasn't responding at all.
So...I left that too. For now.
As it stands now, I want to continue on both paths I set out on. I aim to create a working .exe file that plays like a real game ( Interactive GUI, multiplayer and single-player options and 'play against computer' options, etc.)
So I'll get back when I calm down from the snake detachment I just witnessed.
Comments
Post a Comment