A classic implementation of the Snake game built using the Racket programming language. This project was created as a solution to the Build Your Own Snake Game coding challenge.
This project demonstrates functional game programming concepts using Racket's 2htdp/universe engine. It features a snake that grows as it consumes food (represented by a rat), collision detection, and score tracking.
Key Libraries Used:
- 2htdp/universe: For the game engine and world state management.
- 2htdp/image: For creating and handling game graphics.
- lang/posn: For coordinate and position management.
- rackunit: For unit testing game logic.
To run this game, you need to have DrRacket installed on your machine.
- Racket: Download and install it from https://racket-lang.org/download/.
Open your terminal and run the following command to clone the project:
git clone [https://github.com/ahmedsameha1/snake_game_racket.git](https://github.com/ahmedsameha1/snake_game_racket.git)- Open the DrRacket IDE (installed with Racket).
- Open the ccsnake.rkt file from the cloned repository.
- Click the Run button in the toolbar (or press Ctrl+R / Cmd+R).
- The game window should appear automatically.
This is my implementaion of the Snake game. It is written using Racket programming language. I used 2htdp/image to create and handle images. I used 2htdp/universe as the game engine. I used lang/posn to position images. I used rackunit for testing.
Use the keyboard to control the snake:
| Key | Action |
|---|---|
| ⬆️ Up Arrow | Move Up |
| ⬇️ Down Arrow | Move Down |
| ⬅️ Left Arrow | Move Left |
| ➡️ Right Arrow | Move Right |
This project includes unit tests to ensure game logic (like movement and growth) works correctly.
- Open ccsnake_test.rkt in DrRacket.
- Click the Run button.
- DrRacket will execute the tests defined with rackunit and report any failures in the interactions window.
- Challenge: This project is based on the Coding Challenges guide.
- Coursework: This project is created as a practice after studying Programming Languages, Part B on Coursera and inspired by UBCx: How to Code: Simple Data on edX.
- Assets: Rat image provided by Smashicons.