Skip to content

itsalicelee/The-Hungry-Snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

The-Hungry-Snake 🐍

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

Usage

  • Set up the environment for using SFML on your IDE
  • 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

How to play

  • 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

Rules

  • 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

Folder structure

.
β”œβ”€β”€ 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

Default algorithm introduction

  • 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

A little preview of the game

TypeA TypeB TypeB