0% found this document useful (0 votes)
34 views19 pages

Snack Project

Uploaded by

HR HABIB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views19 pages

Snack Project

Uploaded by

HR HABIB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Project Tittle: Console Based Snack Game

Presented By:-
MD: Habibur Rahman
ID: 41230201295

MD. Nasir Uddin


ID: 412302011061

MD. Muzahid Hasan


ID: 41230201111

Avizith Goshal
ID: 41230201057

Northern University Bangladesh


➢ CONTENT

1. Introduction.
2. Histroy of Game.
3. Objective.
4. Login and Registration Process.
5. Snake Movement and Collision Detection.
6. Game Board and Rendering.
7. Food System.
8. Game Loop and Logic.
9. Game Over Condition.
10. Conclusion.
INTRODUCTION

The Snack Game is a classic arcade-style game where the player controls a snake
that moves around the screen to collect food (snacks). Each time the snake eats a
snack, it grows longer. The challenge is to keep collecting snacks without the snake
running into the walls or itself. The game becomes progressively harder as the snake
grows, making it more difficult to avoid collisions.

Players control the snake's direction using arrow keys or touch gestures. The game
keeps track of the score, which increases with each snack consumed. Once the snake
crashes into a wall or its own body, the game ends.

The Snack Game is a simple yet addictive project often used by beginner
programmers to learn fundamental concepts like collision detection, movement
control, and game loops. It provides a fun way to practice coding while developing
problem-solving and logic skills.
HISTROY OF GAME

The Snack Game, widely known as "Snake," originated in the late


1970s and gained immense popularity in the 1990s with its inclusion
on Nokia mobile phones. Its roots trace back to arcade games like
"Blockade" and "Worm," which featured similar mechanics. The core
concept involves controlling a snake to eat food while avoiding
collisions with walls or itself, leading to a growing and increasingly
challenging gameplay experience.

The game's appeal lies in its simplicity and addictive nature, making
it accessible to players of all ages. The 1997 release of Snake on
Nokia's Game Boy and subsequent mobile phones brought it to
mainstream attention, cementing its place in gaming history. The
game's success has led to numerous modern adaptations and
variations, ensuring that Snake remains a beloved classic in both
retro gaming and contemporary game development.
OBJECTIVE

The objective of the Snack Game, also known as Snake, is to control a


snake as it moves around the screen to collect food items. Each time the
snake consumes a piece of food, it grows longer, which increases the
difficulty of the game. The primary goal is to achieve the highest score
possible by consuming as many food items as you can before running
into obstacles.

Players must navigate the snake carefully to avoid collisions with the
game’s boundaries or the snake’s own body. Successful navigation and
strategic movement are crucial as the snake grows longer, making it
more challenging to avoid self-collision and edge hazards. The game
ends when the snake collides with the wall or itself, and the player’s
final score is displayed. The simple yet engaging gameplay encourages
players to improve their reflexes and strategy, striving for higher scores
with each attempt.
➢ LOGIN AND REGISTRATION PROCESS

Registration:

A user can register by entering a unique username and a


password. The program checks if the username is
already taken. If it’s unique, the registration is
successful, and the username and password are stored.

Login

To log in, a user must input their registered


username and matching password. If the entered
credentials match, the user is considered logged in,
and the currentuser variable is updated to reflect
the logged-in user.
➢ CODE

➢ SAMPLE OUTPUT
➢ SNACK MOVEMENT AND COLLISION DETECTION
Movement:

The move() method updates the snake’s position based on its current direction. The
snake’s head is moved first, and then the rest of the body follows. If the growFlag is not
set, the tail segment is removed, keeping the snake's length constant. If growFlag is set,
the tail is not removed, effectively growing the snake by one segment.

Collision Detection:

▪ Boundary Collision:

The checkCollision() method ensures the snake’s head stays within the game’s board
limits. If the head moves outside these boundaries, the game detects a collision.

▪ Self Collision:

The checkSelfCollision() method checks if the snake’s head has collided with any of its
own body segments. This ensures that the game detects when the snake runs into itself.
➢ CODE

➢ SAMPLE OUTPUT
➢ GAME BOARD AND RENDERING

[Link] the Board:

The render() method is responsible for displaying the entire game board. The outer
boundary of the board is represented by walls made of # symbols. Inside the
boundary, the snake's body is visualized with O characters, and the food appears
as a * at its current position.

[Link] the Snake and Food:

The board iterates through each coordinate, checking if the current position
corresponds to a snake part or the food. If it does, it displays the respective
character (O for the snake, * for food). Otherwise, it leaves the cell empty,
rendering a blank space.
➢ CODE ➢ SAMPLE OUTPUT
➢ FOOD SYSTEM
[Link] Positioning:

The placeFood() method generates random coordinates within the


board's width and height. The rand() function is used to generate
random numbers, which are then constrained to fit within the board
dimensions using the modulo operator (%).

[Link] and Height Constraints:

The rand() function ensures that the x-coordinate of the food is between
0 and width-1 and the y-coordinate is between 0 and height-1. This
guarantees that the food is always placed within the board's boundaries.

➢ CODE
➢ GAME LOOP AND LOGIC:
Game Loop

The game loop is defined in the run() method:

Components:

[Link](): This method listens for user input (e.g., key presses to change the snake’s direction or adjust the
game speed).

[Link](): This method handles the game's core logic, such as moving the snake, checking for collisions, and
managing interactions between the snake and the food.

[Link](): This updates the game board, visually displaying the snake, food, walls, and any other
components.

[Link](speed): Controls how fast the game updates. The speed variable determines how long the game pauses
between updates, effectively controlling the snake’s speed.
User Input Handling

The input() method is responsible for managing real-time user input during
gameplay:

Components:

1._kbhit() and _getch(): These are used to detect and capture key presses. The snake’s direction
changes based on the key pressed.

[Link] Control:
▪ +: Speeds up the game by decreasing the speed value, making the snake move faster (as Sleep() is
called for a shorter period).
▪ -: Slows down the game by increasing the speed value, making the snake move slower (as Sleep() is
called for a longer period).

[Link] Direction: The snake's direction is changed via the [Link](key) method,
where the snake's movement is adjusted based on user input.
Game Logic

The logic() method drives the core mechanics of the game:

Components:

[Link] Movement: The snake moves one step each time [Link]() is called, and its
direction depends on the player's input.

[Link] Detection:
▪ Wall collision: If the snake moves outside the bounds of the board ([Link] or
[Link]), the game ends.
▪ Self-collision: If the snake runs into its own body ([Link]()), the game ends.
[Link] Interaction:
If the snake's head reaches the food's position ([Link]().front() == [Link]()):

▪ The snake grows ([Link]()).


▪ The food is repositioned on the board ([Link]()).
▪ The player's score increases by 10 points.
▪ The game speed increases slightly by reducing the speed value, making the game
progressively harder.

Game Speed Adjustment

Speed adjustment happens in two ways:

User Input: The player can manually adjust the speed using the + or - keys
during gameplay, as handled in the input() method.

Game Progression: The game becomes faster every time the snake eats food,
making it progressively more challenging. This is done in the logic() method by
decreasing speed after each food consumption.
➢ GAME OVER CONDITION
The "Game Over" condition is primarily detected through two types of collisions:

Wall collision: The snake’s head moves beyond the boundaries of the game board.

Self-collision: The snake’s head runs into its own body .

➢ CONCLUSION.
The snake game is a simple yet engaging arcade-style game that tests players'
reflexes and strategic planning. The gameplay revolves around controlling a
growing snake on a grid, with the primary objective of eating food to grow longer
and increase the score. However, this comes with the challenge of avoiding
collisions with the snake's own body and the grid's walls, which results in the
game ending.
The game's dynamic difficulty progression is driven by increasing speed as the
snake grows, adding tension and excitement. The user can also adjust the game
speed manually, giving them control over how fast or slow the game progresses.
Collision detection plays a central role in determining the "Game Over" condition,
ensuring that players are challenged by both spatial awareness and quick
reactions.

The simplicity of the game mechanics, combined with progressively increasing


difficulty, provides a satisfying balance of challenge and fun. With real-time input
handling and responsive gameplay, the snake game remains an enduring classic
that encourages players to improve their skills and achieve higher scores with
each session, offering a timeless gaming experience.
THANK YOU

You might also like