Professional Documents
Culture Documents
UNIX PROGRAMMING
“SNAKE GAME”
V Semester
Section A
Submitted By
BHAVANA N S (1BY20CS038)
Assistant Professor
2022-2023
2
Snake Game
INSTITUTE VISION
To emerge as one of the finest technical institutions of higher learning, to develop
engineering professionals who are technically competent, ethical and
environment friendly for betterment of the society.
INSTITUTE MISSION
Accomplish stimulating learning environment through high quality academic
instruction, innovation and industry-institute interface.
DEPARTMENT VISION
To develop technical professionals acquainted with recent trends and
technologies of computer science to serve as valuable resource for the
nation/society.
DEPARTMENT MISSION
Facilitating and exposing the students to various learning opportunities through
dedicated academic teaching, guidance and monitoring.
ABSTRACT:
This project aims to bring the fun and simplicity of snake game with some new features.
This basic Snake Game provides the following functionalities:
Snake can move in a given direction and when it eats the food, the length of snake
increases.
When the snake crosses itself, the game will be over.
This project explores a new dimension in the traditional snake game to make
it more interesting and challenging.
INTRODUCTION:
The program generates a snake game in your Unix machine terminal window. The goal
is to have the snake eat the food, placed randomly on the screen. The more food the snake
eats, the longer it gets and the faster it crawls, making the game more difficult. The snake
can traverse anywhere, in direction (up, down, left, right) provided it doesn't crawl into itself.
Perl Programming:
Perl is an interpreted language, which means you will always need the Perl interpreter
which will compile and execute your program each time you run it. Instead of compiling your
program into bytecode, like in C++ or Pascal, and then executing it, you can simply copy
your program's source code to a different computer (that has the Perl interpreter) and run it.
Perl is a script language, which is compiled each time before running. That unix knows
that it is a perl script there must be the following header at the topline of every perl
script: #!/usr/bin/perl where the path to perl has to be correct and the line must not exeed
32 charachters.
Perl Features
Perl takes the best features from other languages, such as C, awk, sed, sh, and
BASIC, among others.
Perls database integration interface DBI supports third-party databases
including Oracle, Sybase, Postgres, MySQL and others.
Perl works with HTML, XML, and other mark-up languages.
Perl supports Unicode.
Perl is Y2K compliant.
Perl supports both procedural and object-oriented programming.
Perl interfaces with external C/C++ libraries through XS or SWIG.
Perl is extensible. There are over 20,000 third party modules available from the
Comprehensive Perl Archive Network (CPAN).
IMPLEMENTATION SNAPSHOTS:
First, we need a 2D grid and some constants to label the blocks, which are described bellow:
1. HEAD
o follows input or block directions
o creates BODY blocks
2. BODY
o represents the body of the snake
3. TAIL
o follows block directions
o changes TAIL to VOID
o changes BODY to TAIL
4. FOOD
o suspends TAIL actions
5. VOID
o represents an empty block
Initially, the grid is created with all the blocks labeled as VOID
After we have the 2D grid, we need to create the snake itself and the food source. Currently,
the snake has no BODY, only the HEAD and the TAIL, both with a left (⬅) direction
specified:
After applying the HEAD definition, the HEAD moves to the left by one block and creates a
new BODY block in its old position:
Following the TAIL definition, the TAIL moves to the left by one block and replaces
the BODY label with TAIL and the old TAIL with VOID:
If we now press the up-arrow key (⬆), the HEAD will move upwards, instead of following the
block direction. Also, because the HEAD encountered FOOD this time, the TAIL step is
skipped, so the snake grows by one BODY block without it being removed by the TAIL.
The new BODY block always stores the current HEAD direction:
In the next step, the HEAD follows its block direction and continues to move upwards,
creating a new BODY block in its old place:
Because no FOOD was encountered this time, the TAIL will follow its block direction and
replace BODY with TAIL, but it will never change the block direction:
OUTPUT SNAPSHOTS:
REFERENCES:
1. Learning Perl – 5th Edition O’Reilly Publications Randal L. Schwartz Tom Phoenix and
Brian D. Foy
2. Perl Programming- Programming Language by Tutorial’s point Simply Easy
Learning Publications
3. L. Wall, T. Christiansen and R.L. Schwartz, Programming Perl, Sebastapol,
Calif.,, 1997.
4. S. Srinivasan, Advanced Perl Programming, Sebastapol, Calif.,, 1996.
5. Geeks-for-geeks: https://www.geeksforgeeks.org/perl-programming-language/
6. Why Perl is still relevant in 2022?: https://stackoverflow.blog/2022/07/06/why-perl-is-still-
relevant-in-2022/