Project information

  • Category: Game
  • Language used: Cpp
  • Project date: 23 April, 2023
  • Project URL: Click here

Project details

This is a C++ program for a simple Snake game using console output. The code consists of several classes and functions. The Point class represents a point on the console screen with an x and y coordinate. It contains methods to move the point up, down, left or right, and to draw or erase it from the console screen. The Snake class is the main class that controls the game. It has an array of Point objects representing the snake's body, a fruit object representing the prey, a size variable representing the current size of the snake, a dir variable representing the direction in which the snake is moving, and a state variable representing whether the snake is alive or dead. The Snake class also contains methods for adding a new cell to the snake's body, turning the snake in a given direction, moving the snake forward by redrawing its body parts, checking for self-collision, and handling collision with the fruit. The gotoxy function is used to move the console cursor to a specific location on the screen. The setcursor function is used to show or hide the cursor and set its size. The main function initializes the game by creating a Snake object and repeatedly calling its Move method until the user presses the 'e' key to exit. The 'w', 'a', 's', and 'd' keys are used to control the snake's movement.