Control your snake and avoid collusion!
- π΄ This is the final project of Data Structure instructed by Prof. Ken-Yi Lee at National Taiwan University
- π₯ Our algorithm is rated 1st/41 teams
- π₯ Watch our final project demo competition here
- Set up the environment for using SFML on your IDE
- macOS users need to download SFML for macOS, make sure the project has access to your keyboard at privacy setting
- Xcode
- Dev C++
- Visual Studio
- Add all the source files to your IDE (I use Xcode for building the project)
- Define your controller in
CustomController.h
, and build the project
- There are 3 challenges and 3 modes to choose from:
- 3 challenges
- Type A: No other snakes
- Type B: Several other snakes, and they won't avoid collusion with you
- Type C: Several other snakes, and they will avoid collusion with you
- 3 modes
- Mode 0: Use your keyboard
up
down
left
right
to control your snake - Mode 1: Use the controller defined in
CustomController.h
and run the game with GUI - Mode 2: Run till the end without GUI and show the score
- Mode 0: Use your keyboard
- 3 challenges
- The game will end in a period by default
- Every snake is allowed to collide with itself
- Gameover if collide with walls or other snakes
- Eat more dots to get scores
.
βββ CMakeLists.txt
βββ DSAP-Final
βΒ Β βββ DSAP-Final-Info.plist
βΒ Β βββ Resources
βΒ Β βββ arial.ttf
βββ README.md
βββ img
βΒ Β βββ TypeA.png
βΒ Β βββ TypeB.png
βΒ Β βββ TypeC.png
βββ src
βββ Config.h
βββ ConstantDirectionController.h
βββ ConstantDirectionControllerA.h
βββ ConstantDirectionControllerB.h
βββ CustomController.h
βββ DirectionType.h
βββ GUI.cpp
βββ GUI.h
βββ Game.cpp
βββ Game.h
βββ ISnakeController.h
βββ PlayerController.h
βββ Position.cpp
βββ Position.h
βββ Snake.cpp
βββ Snake.h
βββ StraightForwardController.cpp
βββ StraightForwardController.h
βββ main.cpp
4 directories, 26 files
- We use the function getCollisionDistance() to determine whether we will collide soon(i.e. in danger)
- If we are in danger, we use DesideTurnDirection() to decide whether we should turn left or right
- We always turn to the direction that is farest from the obstacle in front of us
- If we start to loop, decrease the turing radius of the snake