You are on page 1of 38

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

JNANA SANGAMA, BELAGAVI-590018, KARNATAKA

A Mini Project Report


on
TETRIS GAME

Submitted in partial fulfillment of the requirements for the VI Semester of degree of Bachelor
of Engineering in Information Science and Engineering of Visvesvaraya Technological
University, Belagavi

Submitted by

SANJEEV J 1AM18IS049
PRASHANTH M 1AM18IS037

Under the Guidance of

Mrs Mala B A
Assistant Professor
Department of ISE

Department of Information Science and Engineering


AMC ENGINEERING COLLEGE
18 Km, Bannerghatta Road, Bangalore-560083
2020-21
AMC ENGINEERING COLLEGE
18 Km, Bannerghatta Road, Bangalore-560083

DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING

CERTIFICATE

Certified that the mini project work entitled TETRIS GAME has been successfully
completed by SANJEEV J (1AM18IS049), PRASHANTH M (1AM18IS037) bonafide
students of AMC Engineering College, Bengaluru in partial fulfillment of the
requirements for the award of degree in Bachelor of Engineering in Information
Science and Engineering of Visvesvaraya Technological University, Belgaum during
academic year 2020-2021. The project report has been approved as it satisfies the
academic requirements in respect of project work for the said degree.

____________________ _____________________ _____________________

Mrs Mala B A Dr. M V Sudhamani Dr.Girisha C


Project Guide Professor and HOD Principal
Assistant Professor Department of ISE AMCEC
Department of ISE AMCEC

External Viva
Name of the Examiners Signature with Date

1. ___________________________ 1. ______________________

2. ___________________________ 2. ______________________
DECLARATION

We, SANJEEV J (1AM18IS049), PRASHANTH M (1AM18IS037), students of VI


Semester BE in Information Science and Engineering, AMCEC hereby declare that the
Project entitled Tetris Game has been carried out by us and submitted in partial
fulfillment of the requirements for the VI Semester of degree of Bachelor of Engineering
in Information Science and Engineering of Visvesvaraya Technological University,
Belgaum during academic year 2020-2021.

Place : Bengaluru
Date :

SANJEEV J (1AM18IS049)
PRASHANTH M (1AM18IS037)
ACKNOWLEDGMENT

At the very onset we would like to place our gratefulness to all those people who
helped us in making this project a successful one.

Coming up, this project to be a success was not easy. Apart from the shear
effort, the enlightenment of our very experienced teachers also plays a paramount role
because it is they who guide us in the right direction.

First of all, we would like to thank Management of AMCEC for providing


such a healthy environment for the successful completion of project work.

In this regard, we express our sincere gratitude to the Director Dr. K M Babu
and the principal Dr.Girisha C, for providing us all the facilities in this college.

We are extremely grateful to our Professor and Head of Department of


Information science and Engineering, Dr. M V Sudhamani, for having accepted to
patronize us in the right direction with all her wisdom.

We place our heartfelt thanks to Mrs Mala B A, Assistant Professor,


Department of information science and Engineering for having guided for project and
all the staff members of our department for helping us out at all times.

We thank our beloved friends for having supported us with all their strength
and might. Last but not the least; we thank our parents for supporting and encouraging
us throughout. We made an honest effort in this assignment.

SANJEEV J (1AM18IS049)
PRASHANTH M (1AM18IS037)
ABSTRACT

Tetris is a puzzle game in which geometric shapes called "tetrominoes" fall down onto a
playing field, and the player has to arrange them to form gapless lines. Pajitnov took
inspiration from pentomino, a classic puzzle game consisting of all the different shapes
that can be made by combining five squares – 12 in total – with the goal of arranging
them in a wooden box like a jigsaw puzzle.

To simplify things, he knocked that down to four squares, thus reducing the number of
shapes from 12 to seven. He called the game Tetris, combining the Greek numeral "tetra"
(meaning four) and tennis, his favorite sport.Pajitnov himself was immediately hooked. "I
couldn't stop myself from playing this prototype version, because it was very addictive to
put the shapes together.
Table of Contents
CERTIFICATE……………………………………………………………..i
DECLARATION…………………………………………………………...ii
ACKNOWLEDGMENT…………………………………………………..iii
ABSTRACT………………………………………………………………..iv
Chapter 1 .................................................................................................. 1
INTRODUCTION .................................................................................... 1
BACKGROUND ....................................................................................... 1
PROPOSED SYSTEM .............................................................................. 2
ADVANTAGES OF PROPOSED SYSTEM ............................................ 2
CHAPTER 2 ................................................................................................ 4
REQUIREMENT ANALYSIS ................................................................ 4
PROJECT IDENTIFICATION .............................................................. 4
OBJECTIVES .......................................................................................... 4
METHODOLOGY .................................................................................. 5
CHAPTER 3 ................................................................................................ 6
SYSTEM REQUIREMENT SPECIFICATION .................................... 6
HARDWARE REQUIREMENTS .......................................................... 7
SOFTWARE REQUIREMENTS ........................................................... 7
FUNCTIONAL REQUIREMENTS ....................................................... 7
NON-FUNCTIONAL REQUIREMENTS ............................................. 8
CHAPTER 4 ................................................................................................ 9
SYSTEM DESIGN .................................................................................. 9
DATAFLOW DIAGRAM ....................................................................... 9
USE CASE DIAGRAM ......................................................................... 11
ClassDiagram ......................................................................................... 13
CHAPTER 5 .............................................................................................. 14
IMPLEMENTATION ........................................................................... 14
OVERVIEW OF SYSTEM IMPLEMENTATION ............................. 14
ALGORITHM ....................................................................................... 15
PSEUDO CODE .................................................................................... 15
Chapter 6 ................................................................................................... 29
SYSTEM TESTING .............................................................................. 29
SNAPSHOTS ............................................................................................ 31
Chapter 7 ................................................................................................... 32
CONCLUSION ...................................................................................... 32
REFERENCES ...................................................................................... 32
TEXT BOOKS ....................................................................................... 32
TETRIS GAME

CHAPTER 1
INTRODUCTION

Tetris is a tile-matching puzzle video game and it is one of the most famous game in the
world. It is played on a board with 20 rows and 10 columns. There are seven shapes of
Tetriminos, and Tetriminos fall from top of the board and come to rest at the bottom
every time. The player has to control the Tetriminos by moving left and right and rotating
clockwise, and the player is needed to get the score as high as possible by clearing lines,
which is filling the horizontal row in the board.

The rules of Tetris are very simple but it is not easy to master it, like clearing more 500 of
lines. Players need to find the solution to keep the board in good shape meanwhile clear
the lines as many as possible. More lines have been cleared, the falling speed of the
Tetriminos increases, which means the difficulty increases and the player has less time to
decide the best move in the later part of the game. Therefore, the player will be prone to
make the wrong decision, and finally lose the game.

BACKGROUND
Tetris (Russian: Тéтрис [ˈtʲɛtrʲɪs]) is a tile-matching video game created by Russian software
engineer Alexey Pajitnov in 1984 for the Electronika 60 computer. It has been published by
several companies, most prominently during a dispute over the appropriation of the rights in
the late 1980s. After a significant period of publication by Nintendo, the rights reverted to
Pajitnov in 1996, who co-founded The Tetris Company with Henk Rogers to manage
licensing.

In Tetris, players complete lines by moving differently shaped pieces (tetrominoes), which
descend onto the playing field. The completed lines disappear and grant the player points,
and the player can proceed to fill the vacated spaces. The game ends when the playing field
is filled. The longer the player can delay this inevitable outcome, the higher their score will
be. In multiplayer games, the players must last longer than their opponents, and in certain
versions, players can inflict penalties on opponents by completing a significant number of
lines. Some adaptations have provided variations to the game's theme, such as three-
dimensional displays or a system for reserving pieces.Built on simple rules and requiring
intelligence and skill, Tetris established itself as one of the great early video games. The
game is available on over 65 platforms, setting a Guinness world record for the most ported
video game title. Tetris is rooted within popular culture and its popularity extends beyond the

Dept. of ISE, AMCEC 2020-2021 Page 1


TETRIS GAME

sphere of video games; imagery from the game has influenced architecture, music
and cosplay. The game has also been the subject of various research studies that have
analyzed its theoretical complexity and have shown its effect on the human brain following a
session, in particular the Tetris effect.

PROPOSED SYSTEM

As one start the game ,he enters an arena of TETRIS .In this arena ,various shaped objects
fall with a given speed( the speed increases as one goes to a higher difficult level).The
player has to adjust these shapes in such a way that a bricked structure is
formed.Whenever a continuous line is formed ,that particular line disappears giving up
points.These blocks fall at random (one at a time).The blocks can be rotated (in just one
sense ,for example in 90 degrees or so).The speed of the block increases as the game
progreses.The game ends when the building created by these blocks touches the ceil(the
ceil is initially defined).
SCORING SYSTEM: The scoring in this game in as follows. When a single line of
brick is formed 100 points are awarded .When double line of brick is formed 300 points
are awarded .When triplet is formed 500 points are awarded and on the formation of
TETRIS 800 points are awarded . In this way the game goes on.

TYPES OF STRUCTURE:the following are the the structure we propose for the game
SQUARE
STRAIGHT ROD
OPPOSITE “L”SHAPED ROD
”L” SHAPED ROD
OPPOSITE “S” SHAPED ROD
”S”SHAPED ROD
BENDED ROD

ADVANTAGES OF PROPOSED SYSTEM

Improved Brain Efficiency


It’s believed as a person improves their skills over time, the brain uses less glucose to fuel
the problem solving Tetris relentlessly demands. As Jeremy Fordham states in The

Dept. of ISE, AMCEC 2020-2021 Page 2


TETRIS GAME

Neuroscience of Tetris, “What this shows is that the brain actually learns how to solve
Tetris conundrums with energy efficiency while it improves performance on the same
tasks that once required loads of glucose. This is a prime example of brain efficiency.”

Assisting With Diets and Addiction


It’s been observed playing Tetris is a useful task for anyone wishing to control their
excesses. In early 2014 Science Direct published Playing Tetris reduces the strength,
frequency and vividness of naturally occurring cravings. The paper acknowledges,
“Participants who had played ‘Tetris’ had significantly lower craving and less vivid
craving imagery. The findings support EI theory, showing that a visuospatial working
memory load reduces naturally occurring cravings, and that Tetris might be a useful task
for tackling cravings outside the laboratory.”

Potential Alleviation of Neurological Conditions


Tetris has been at the centre of several studies into neurological conditions, and research
in this area has been conducted for over 20 years. In 1994 Lynn Okagaki and Peter
Frensch, in Journal of Applied Developmental Psychology, concluded playing Tetris had
positive results on spatial skills, such as mental rotation, spatial perception, and spatial
visualization.

Prolonged bouts of play can lead to the “Tetris effect”. The term is given to someone who
plays Tetris to such an extent it becomes part of their visual day to day life: they can
dream about tetrominos (the four part geometric shapes in the game), and organize items
they see in their environment. Robert Stickgold’s research, published in 2000
by ScienceMag, noted this intriguing phenomenon, “Amnesic patients with extensive
bilateral medial temporal lobe damage produced hypnagogic reports despite being unable
to recall playing the game, suggesting that such imagery may arise without important
contribution from the declarative memory system.”

Dept. of ISE, AMCEC 2020-2021 Page 3


TETRIS GAME

CHAPTER 2
REQUIREMENT ANALYSIS

PROJECT IDENTIFICATION
The user can install this amazing application on his/her smart phone and can get all
feature of this application. This game is played by adults and children’s as well. it is also
known as board game. Some are obvious kids enjoy them and board games are
opportunities for families to play together. In addition social scientist has argued games
teach lesson about getting along with others. Board game can teach the important social
skills.
For example Games may encourage kids to
• Consider the concept of rule
• Practice of rules
• Reason about moral problem

OBJECTIVES
The goal of Tetris is to score as many points as possible by clearing horizontal lines of
Blocks. The player must rotate, move, and drop the falling Tetriminos inside the Matrix
(playing field). Lines are cleared when they are filled with Blocks and have no empty
spaces.

As lines are cleared, the level increases and Tetriminos fall faster, making the game
progressively more challenging. If the Blocks land above the top of the playing field, the
game is over.

GENERAL GAMEPLAY INFO

GOAL – Put your organizational skills and endurance to the test by clearing as many
lines as possible.

CLEAR LINES – Maneuver the falling Tetriminos to fit them together within the Matrix.
To clear a line, fill every square within a single row.

SCORE POINTS – Earn points by clearing lines. Clear multiple lines at once to increase
your scoring opportunities.

Dept. of ISE, AMCEC 2020-2021 Page 4


TETRIS GAME

NEXT QUEUE – Preview the upcoming Tetrimino in the Next Queue to plan ahead and
increase your scoring opportunities.

GAME OVER – Stack the Tetriminos too high and the game is over!

METHODOLOGY
This project is made by using Android studio, Virtual emulator and Photoshop. The
programming languages used for building the application are Java, XML and C++. User
interface is handled using XML codes. Backend programming is handled mainly through
set of java codes. The libraries required are:
⚫ Android SDK tools

⚫ Android SDK platform tools

⚫ Android SDK build tools


⚫ SDK platform

⚫ ARM EABI v7a System Image

⚫ Intel x86 Atom_64 System Image

⚫ Google APIs
⚫ Google APIs ARM EABI v7a System Image

⚫ GPU Debugging tools

⚫ Android Support Library

⚫ Google play services


⚫ Intel x86 Emulator Accelerator (HAXM installer)This application adopts the use of
XML – with java programming language for its implementation

Dept. of ISE, AMCEC 2020-2021 Page 5


TETRIS GAME

CHAPTER 3
SYSTEM REQUIREMENT SPECIFICATION

Software requirements specification is produced at the culmination of the analysis task.


The function and the performance allocated to software as part of system engineering are
refined by establishing a complete information description, a detailed functional and
behavioral description, an indication of performance requirements and design constraints,
appropriate validation criteria and other data pertinent to requirements. Here is the detail,
outline of specification ▪ Introduction ▪ Information description ▪ Functional description ▪
Behavioral description ▪ Validation criteria The introduction states the goals and
objectives of the software, describing it in the context of the computer-based system.
Actually, the introduction may be nothing more than the software scope of the planning
document. The infomation description provides a detailed description of the problem that
the software must solve. Information content and relationships, flow and structure are
documented. Hardware software, a human interfaces are described for external system
elements and internal software functions. A description of each function required to solve
the problem is presented in the functional description. A processing narrative is provided
for each function; design constraints are stated and justified; performance characteristics
are stated and justified; and one or more diagrams are included to graphically represent
the overall structure of the software and interplay among software functions and other
system elements. The behavioral description section of the specification examines the
operation of the software as a consequence of external events and internally generated
control characteristics. Process Model To solve actual problems in an industry setting,
software engineer or a team of engineers must in co-operate a development strategy that
encompasses the process, methods, and tools. This strategy is often referred to as a
process model of a software engineering paradigm. A process model for software
engineering is chosen based on the nature of the project and application, the methods and
tools to be used, and the controls and deliverables that are required.

Dept. of ISE, AMCEC 2020-2021 Page 6


TETRIS GAME

HARDWARE REQUIREMENTS

1. Microsoft Windows 7/8/10 (32-bit or 64-bit)


2. x86-64 processor (64-bit bit Windows with an Intel Core 2 Duo, Intel Core i3, Intel
Core i5, Intel Core i7, or Xeon processor)
3. 4 GB RAM minimum, 8 GB RAM recommended (plus 1 GB for the Android
Emulator)
4. 2 GB of available disk space minimum, 4 GB recommended (500 MB for IDE plus 1.5
GB for Android SDK and emulator system image).
5. 1280 x 800 minimum screen resolution

SOFTWARE REQUIREMENTS
1. Android development tool(ADT)
• Android Studio
• XML
• Java Development tool kit (JDK)
• SDK 7.0
• UML

FUNCTIONAL REQUIREMENTS
Game properties
1 Game pieces The user shall be able to control several different kinds of pieces.
2 Boundaries There shall be boundaries limiting piece movement.
3 Falling pieces The pieces shall move downwards with a given speed.
4 Score The system shall keep and display a total score.
5 Get help The user shall be able to access game instructions.
6 Menu system The user shall be able to navigate a menu system to access the different
game functions.
Game sessions
7 Start singleplayer game session The user shall be able to start a singleplayer game
session.
8 Host multiplayer game The user shall be able to host a network game.
9 Host private game The user shall be able to host a private network game.

Dept. of ISE, AMCEC 2020-2021 Page 7


TETRIS GAME

10 Join multiplayer game The user shall be able to join a network game.
11 Chat with other users The user shall be able to chat with other users when in a game.
Piece movement
12 Move piece vertically The user shall be able to increase vertical piece movement
downwards.
13 Move piece horizontally The user shall be able to control the pieces' horizontal
movement.
14 Rotate piece The user shall be able to rotate the piece that he controls.
15 Collide with other player-controlled bricks In multiplayer sessions, different players'
pieces shall be able to collide.
Brick placement
16 Piece control The user shall control one piece at a time.
17 Fixate piece A piece that cannot move downwards shall be fixated to the board.
18 Remove row When a row is completed, it shall be removed from the game board.
19 Finishing a game session When a piece gets fixated above the top boundary, the game
session shall end.
Powerups
20 Obtain powerup The user shall be able to obtain powerups.
21 Create powerup The system shall introduce powerup bricks when rows are removed.
22 Use powerup Players shall be able to activate obtained powerups.

NON-FUNCTIONAL REQUIREMENTS
Documentation
The game shall have documentation describing the game objective, how to start a
singleplayer game session, join a session, host a session and navigate pieces. Further,
it shall explain the different powerups.
Graphics acceleration
The user shall be able to use graphics acceleration hardware for playing the game.
Inputs
The system shall support two input devices – a keyboard and the X-Box 360 game
controller.

Dept. of ISE, AMCEC 2020-2021 Page 8


TETRIS GAME

CHAPTER 4
SYSTEM DESIGN

SYSTEM ARCHITECTURE

PS/2
50MHz Write
W/R SRAM
Keyboard Control
Control
25MHz Read

SDRAM TETRIS CPU


VGA VGA
Control Display

DM9000A
DM9000A Control

For a game like Tetris, the screen display dynamically changes. As game goes on, blocks
can be created as a whole and fall down as a whole but parts of them might get
eliminated. It means that lots of block data will be written dynamically into SRAM and
then output to VGA display. The clock rate of CPU and VGA are different. So there will
be a control module to monitor the read and write of SRAM. Based on these
considerations, the system structure is designed as shown in the picture.

DATAFLOW DIAGRAM

As information moves through software, it modified by a series of transfomation. A Data


Flow Diagram is graphical representation that depicts information flow and transforms
that are applied as Data move from input to output. The basic form of Data Flow
Diagram, also known as a Data Flow Graph or a Bubble Chart, is illustrated in figure. The
Data Flow Diagram may be used to represent a system or software at any level of
abstraction. In fact, DFDs may be partitioned into level that represents increasing
information low and functional detail. Therefore, the DFD provides a mechanism for

Dept. of ISE, AMCEC 2020-2021 Page 9


TETRIS GAME

functional modeling as well as information flow modeling. In so doing, it satisfies the


second operation analysis principle.
The data flow diagram enables the software engineer to develop models of the
information domain and functional domain at the same time. As the DFD is refined into
greater levels of detail, the analyst performs an implicit functional decomposition of the
system, thereby accomplishing the fourth operation analysis principle for function. At the
same time, the DFD refinement results in a corresponding refinement of data as it moves
through the processes that embody the application.

Dept. of ISE, AMCEC 2020-2021 Page 10


TETRIS GAME

USE CASE DIAGRAM

Use case: Hard/Easy Mode


Actor: User
The User can select easy or hard mode accordingly.
Pre-condition:. click the hard or easy mode button to choose the game accordingly
Post condition: After choosing the hard or easy mode the game will start according to the
user wish.
Description: player can select easy or hard mode accordingly

Dept. of ISE, AMCEC 2020-2021 Page 11


TETRIS GAME

Use case: pause/play


Actor: User
User will be able to pause the game whenever they needed.
Pre-condition: User can pause the game by clicking pause button.
Post condition: The game will pause after clicking on pause button.
Description: When user click on pause button the game will paused.

Use case: Left


Actor: User
Pre-condition:. Click on the left button when the user need the shapes to move left .
Post condition: After choosing the left button the shapes will move to left.
Description: player can move the shape to left by clicking the left button.

Use case: Right


Actor: User
Pre-condition:. Click on the Right button when the user need the shapes to move right .
Post condition: After choosing the right button the shapes will move to right.
Description: player can move the shape to right by clicking the right button.

Use case: Rotate


Actor: User
Pre-condition:.Click on the Rotate button when the user need to rotate the shapes.
Post condition: After choosing the rotate button the shapes will rotate.
Description: player can rotate the shape by clicking the rotate button.

Dept. of ISE, AMCEC 2020-2021 Page 12


TETRIS GAME

ClassDiagram

Dept. of ISE, AMCEC 2020-2021 Page 13


TETRIS GAME

CHAPTER 5
IMPLEMENTATION
The implementation phase involves putting the project plan into action. It’s here that the
project manager will coordinate and direct project resources to meet the objectives of the
project plan. As the project unfolds, it’s the project manager’s job to direct and manage
each activity, every step of the way. That’s what happens in the implementation phase of
the project life cycle: you follow the plan you’ve put together and handle any problems
that come up.
The steps undertaken to build each deliverable will vary depending on the type of project
are undertaken, and cannot therefore be described here in any real detail. For instance
engineering and telecommunications projects will focus on using equipment, resources,
and materials to construct each project deliverable, whereas computer software projects
may require the development and implementation of software code routines to produce
each project deliverable. The activities required to build each deliverable will be clearly
specified within the project requirements document and project plan.

OVERVIEW OF SYSTEM IMPLEMENTATION

The Project Implementation phase has two essential functions: execution of the work and
proper delivery. The resources used in the implementation have to be accurate. Based on
the implementation, the project’s fate is decided. The success and effectiveness can only
be known after proper monitoring and feedback. This phase of delivering provides the
client with an outlook of the project. There could be many ways of implementing this
project we have chosen java because one of the most popular amongst other languages
and highly used language for developing most of the applications because the applications
that are produced by using Java are cross-platform suitable

It comes with a rich library of default design patterns and other best practices. It is more
adaptable for mobile app development because it is open-source like Spring that uses the
concept of Object-Oriented Programming. Android smartphones are now much accessible
and easy to get from the market. Here comes your idea for the execution as an innovative
mobile app that is useful for significant users that increases the rate of success.

Dept. of ISE, AMCEC 2020-2021 Page 14


TETRIS GAME

ALGORITHM
Step 1: We have to run the code in android studio
Step 2: Click on Play Game.
Step 3: Select the Hard/Easy mode.
Step 4: The falling Tetriminos to fit them together within the Matrix. To clear a line, fill
every square within a single row.

Step 5: Earn points by clearing lines. Clear multiple lines at once to increase your scoring
opportunities.

Step 6: Stack the Tetriminos too high and the game is over!

PSEUDO CODE
Pseudo code is an informal high-level description of the operating principle of a computer
program or other algorithm. It uses the structural conventions of a programming
language, but is intended for human reading rather machine reading. Pseudocode is a
useful thing to learn because it focuses on the building block concepts of programming
languages without you having to worry about whether you are using the "right" words.
Once you've nailed the logic of coding, the rest is just filling in your pseudocode with the
syntax of a particular programming language.

GameState.java

package com.tetris.tetris;
import android.util.SparseArray;
class GameState {
boolean status;
int score;
boolean pause;
BasicBlock[][] board;
Tetramino falling;
boolean difficultMode;
private int rows;

Dept. of ISE, AMCEC 2020-2021 Page 15


TETRIS GAME

private int columns;


private Integer ctr;
private SparseArray<Tetramino> tetraminos;

GameState(int rows, int columns, TetraminoType fallingTetraminoType) {

this.rows = rows;
this.columns = columns;
this.pause = false;
ctr = 0;
score = 0;
this.status = true;
difficultMode = false;

board = new BasicBlock[rows][columns];


for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
board[row][column] = new BasicBlock(row, column);
}
}

tetraminos = new SparseArray<>();

falling = new Tetramino(fallingTetraminoType, this.ctr);

tetraminos.put(this.ctr, falling);
}

private BasicBlock getCoordinateBlock(Coordinate coordinate) {

return this.board[coordinate.y][coordinate.x];
}

private boolean isConflicting(Coordinate coordinate) {


Dept. of ISE, AMCEC 2020-2021 Page 16
TETRIS GAME

if (coordinate.x < 0 || coordinate.x >= this.columns || coordinate.y < 0 || coordinate.y


>= this.rows)
return true;

returnthis.getCoordinateBlock(coordinate).state==BasicBlockState.ON_TETRAMINO;

private boolean canTetraminoDisplace(Tetramino tetramino, Coordinate displacement)


{

for (BasicBlock block : tetramino.blocks) {


if (block.state == BasicBlockState.ON_TETRAMINO) {
Coordinate shifted = Coordinate.add(block.coordinate, displacement);
if (isConflicting(shifted)) {
return false;
}
}
}
return true;
}

boolean moveFallingTetraminoDown() {

if (canTetraminoDisplace(falling, new Coordinate(1, 0))) {


falling.moveDown();
return true;
} else {
return false;
}

}
Dept. of ISE, AMCEC 2020-2021 Page 17
TETRIS GAME

boolean moveFallingTetraminoLeft() {

if (canTetraminoDisplace(falling, new Coordinate(0, -1))) {


falling.moveLeft();
return true;
} else {
return false;
}
}

boolean moveFallingTetraminoRight() {

if (canTetraminoDisplace(falling, new Coordinate(0, 1))) {


falling.moveRight();
return true;
} else {
return false;
}
}

boolean rotateFallingTetraminoAntiClock() {
if (falling.type == TetraminoType.SQUARE_SHAPED) {
return true;
} else {
for (BasicBlock block : falling.blocks) {
if (block.state == BasicBlockState.ON_EMPTY)
continue;

BasicBlock referenceBlock = falling.blocks[0];


Coordinate baseCoordinate = Coordinate.sub(block.coordinate,
referenceBlock.coordinate);
if (isConflicting(Coordinate.add(Coordinate.rotateAntiClock(baseCoordinate),
referenceBlock.coordinate))) {
Dept. of ISE, AMCEC 2020-2021 Page 18
TETRIS GAME

return false;
}
}
falling.performClockWiseRotation();
return true;
}
}

void paintTetramino(Tetramino tetramino) {


for (BasicBlock block : tetramino.blocks) {
if (block.state == BasicBlockState.ON_EMPTY)
continue;
this.getCoordinateBlock(block.coordinate).set(block);
}
}

void pushNewTetramino(TetraminoType tetraminoType) {


this.ctr++;

falling = new Tetramino(tetraminoType, this.ctr);


this.tetraminos.put(this.ctr, falling);
for (BasicBlock block : falling.blocks) {

if(this.getCoordinateBlock(block.coordinate).state==BasicBlockState.ON_TETRAMINO
)
this.status = false;
}
}

void incrementScore() {

this.score++;
}

Dept. of ISE, AMCEC 2020-2021 Page 19


TETRIS GAME

void lineRemove() {
boolean removeLines;
do {
removeLines = false;
for (int row = this.rows - 1; row >= 0; row--) {
boolean rowIsALine = true;
for (int column = 0; column < this.columns; column++) {
if (this.board[row][column].state != BasicBlockState.ON_TETRAMINO) {
rowIsALine = false;
break;
}
}
if (!rowIsALine) {
continue;
}

for (int column = 0; column < this.columns; column++) {


Tetramino tetramino = this.tetraminos.get((this.board[row][column].tetraId));

BasicBlock blockToClear = this.board[row][column];


blockToClear.setEmptyBlock(blockToClear.coordinate);

if (tetramino == null) {
continue;
}

for (BasicBlock block : tetramino.blocks) {


if (block.state == BasicBlockState.ON_EMPTY) {
continue;
}

if (block.coordinate.y == row && block.coordinate.x == column) {


block.state = BasicBlockState.ON_EMPTY;

Dept. of ISE, AMCEC 2020-2021 Page 20


TETRIS GAME

this.ctr++;
Tetramino upperTetramino = tetramino.copy(this.ctr);
this.tetraminos.put(this.ctr, upperTetramino);
for (BasicBlock upperBlock : upperTetramino.blocks) {
if (upperBlock.coordinate.y >= block.coordinate.y) {
upperBlock.state = BasicBlockState.ON_EMPTY;
} else {

this.getCoordinateBlock(upperBlock.coordinate).tetraId=upperBlock.tetraId;
}
}

this.ctr++;
Tetramino lowerTetramino = tetramino.copy(this.ctr);
this.tetraminos.put(this.ctr, lowerTetramino);
for (BasicBlock lowerBlock : lowerTetramino.blocks) {
if (lowerBlock.coordinate.y <= block.coordinate.y) {
lowerBlock.state = BasicBlockState.ON_EMPTY;
} else {
this.getCoordinateBlock(lowerBlock.coordinate).tetraId=lowerBlock.tetraId;
}
}
this.tetraminos.remove(block.tetraId);
break;
}

}
}
this.adjustTheMatrix();
this.incrementScore();
removeLines = true;
break;
}
} while (removeLines);
Dept. of ISE, AMCEC 2020-2021 Page 21
TETRIS GAME

private void adjustTheMatrix() {


for (int row = this.rows - 1; row >= 0; row--) {
for (int column = 0; column < this.columns; column++) {
Tetramino T = (this.tetraminos).get((this.board[row][column].tetraId));

if (T != null)
this.shiftTillBottom(T);
}
}
}

private void shiftTillBottom(Tetramino tetramino) {


boolean shiftTillBottom;
do {
boolean shouldShiftDown = true;
shiftTillBottom = false;

for (BasicBlock block : tetramino.blocks) {


if (block.state == BasicBlockState.ON_EMPTY)
continue;

CoordinatenewCoordinate=Coordinate.add(block.coordinate,newCoordinate(1, 0));

if (isTetraPresent(newCoordinate, tetramino))
continue;

if (isConflicting(newCoordinate))
shouldShiftDown = false;
}

if (shouldShiftDown) {
for (BasicBlock block : tetramino.blocks) {
Dept. of ISE, AMCEC 2020-2021 Page 22
TETRIS GAME

if (block.state == BasicBlockState.ON_EMPTY)
continue;
this.getCoordinateBlock(block.coordinate).setEmptyBlock(block.coordinate);
block.coordinate.y++;
}

for (BasicBlock block : tetramino.blocks) {


if (block.state == BasicBlockState.ON_EMPTY)
continue;

this.getCoordinateBlock(block.coordinate).set(block);

}
shiftTillBottom = true;
}
} while (shiftTillBottom);
}
private boolean isTetraPresent(Coordinate coordinate, Tetramino tetramino) {
for (BasicBlock block : tetramino.blocks) {
if (block.state == BasicBlockState.ON_EMPTY)
continue;

if (Coordinate.isEqual(block.coordinate, coordinate))
return true;
}
return false;
}

MainActivity.java

package com.tetris.tetris;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Dept. of ISE, AMCEC 2020-2021 Page 23
TETRIS GAME

import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button play;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play = findViewById(R.id.play);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Game.class);
startActivity(intent);
}
});

Tetramino.java

package com.tetris.tetris;
import java.util.Random;
enum TetraminoType {
SQUARE_SHAPED,
T_SHAPED,
L_SHAPED,
LINE_SHAPED,
Z_SHAPED,
INV_L_SHAPED,
INV_Z_SHAPED;

private static final TetraminoType[] VALUES = values();


private static final int SIZE = VALUES.length;
private static final Random RANDOM = new Random();
Dept. of ISE, AMCEC 2020-2021 Page 24
TETRIS GAME

public static TetraminoType getRandomTetramino() {


return VALUES[RANDOM.nextInt(SIZE)];
}
}

class Tetramino {
BasicBlock[] blocks;
TetraminoType type;
Tetramino(TetraminoType type, int tetraId) {
Coordinate[] coordinates;

switch (type) {
case SQUARE_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(0, 10),
new Coordinate(1, 10),
new Coordinate(1, 11),
new Coordinate(0, 11)
};
blocks = this.blocksGenerator(tetraId, 1, coordinates);
break;
case INV_L_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(0, 10),
new Coordinate(0, 11),
new Coordinate(1, 10),
new Coordinate(2, 10)
};
blocks = this.blocksGenerator(tetraId, 2, coordinates);
break;
case L_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(0, 11),
Dept. of ISE, AMCEC 2020-2021 Page 25
TETRIS GAME

new Coordinate(0, 10),


new Coordinate(1, 11),
new Coordinate(2, 11)
};
blocks = this.blocksGenerator(tetraId, 3, coordinates);
break;
case T_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(1, 10),
new Coordinate(0, 10),
new Coordinate(1, 11),
new Coordinate(2, 10)
};
blocks = this.blocksGenerator(tetraId, 4, coordinates);
break;
case Z_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(1, 11),
new Coordinate(1, 10),
new Coordinate(0, 10),
new Coordinate(2, 11)
};
blocks = this.blocksGenerator(tetraId, 5, coordinates);
break;
case INV_Z_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(1, 11),
new Coordinate(0, 11),
new Coordinate(1, 10),
new Coordinate(2, 10)
};
blocks = this.blocksGenerator(tetraId, 6, coordinates);
break;
case LINE_SHAPED:
Dept. of ISE, AMCEC 2020-2021 Page 26
TETRIS GAME

coordinates = new Coordinate[]{


new Coordinate(0, 10),
new Coordinate(1, 10),
new Coordinate(2, 10),
new Coordinate(3, 10)
};
blocks = this.blocksGenerator(tetraId, 7, coordinates);
break;
}
}

private Tetramino(BasicBlock[] blocks) {


this.blocks = blocks;
}

private BasicBlock[] blocksGenerator(int tetraId, int colour, Coordinate[] coordinates)


{
BasicBlock[] blocks = new BasicBlock[coordinates.length];
for (int itr = 0; itr < coordinates.length; itr++) {
blocks[itr] = new BasicBlock(colour, tetraId, coordinates[itr],
BasicBlockState.ON_TETRAMINO);
}
return blocks;
}
Tetramino copy(int tetraId) {
BasicBlock[] newBlocks = new BasicBlock[this.blocks.length];
for (int itr = 0; itr < this.blocks.length; itr++) {
newBlocks[itr] = this.blocks[itr].copy();
newBlocks[itr].tetraId = tetraId;
}
return new Tetramino(newBlocks);
}

void moveDown() {
Dept. of ISE, AMCEC 2020-2021 Page 27
TETRIS GAME

for (BasicBlock block : blocks) {


block.coordinate.y++;
}
}

void moveLeft() {
for (BasicBlock block : blocks) {
block.coordinate.x--;
}
}

void moveRight() {
for (BasicBlock block : blocks) {
block.coordinate.x++;
}
}

void performClockWiseRotation() {
BasicBlock referenceBlock = blocks[0];
for (BasicBlock block : blocks) {

CoordinatebaseCoordinate=Coordinate.sub(block.coordinate,referenceBlock.coordinate);
block.coordinate=Coordinate.add(Coordinate.rotateAntiClock(baseCoordinate),reference
Block.coordinate);
}
}
}

Dept. of ISE, AMCEC 2020-2021 Page 28


TETRIS GAME

CHAPTER 6
SYSTEM TESTING
Testing is a critical element of software quality assurance and represents the ultimate
review of specification, design, and coding- The increasing visibility of a software as a
system element and the attendant "costs" associated with a software failure are motivating
forces for well-planned, through testing. It is not unusual for the organization to spent 30
or 40 percent of total project effort on testing. In the extreme, testing of human rated
software can cost three to five times as much as all the other software engineering
activities combined! Testing presents the software an alliterating anomaly for the
software engineer.
The engineer creates the series of test cases that are intended to demolish the software
that has been built. In fact, testing is the one step in the software engineering process that
could be viewed as destructive rather than constructive. Software developers are
constructive by nature. Testing requires that developers discard preconceived notions of
the "correctness" of software just developed and overcome a conflict of interest that
occurs when the errors are uncovered. Testing objectives The following are the objectives
of testing:
1. Testing is a process of executing a program with the intention of finding an error.
2. A good test case is one that has a high probability of finding an as-yet undiscovered
error.
3. A successful test is one that uncovers as as-set undiscovered error.

Testing principles:
Before applying methods to design effective test cases, a software engineer must
understand the basic principles of testing.
They are as following:
• All tests should be traceable to customer requirements.
• Test should be planned long before testing is done.
• The Pareto principle applies to software testing.
• Testing should begin "in the small" and progress toward testing "in the large."
• Exclusive testing is not possible.
• To be most effective, independent third party should conduct testing

Dept. of ISE, AMCEC 2020-2021 Page 29


TETRIS GAME

Testability
Software testability is simply how easily a computer program can be tested. Since testing
is profoundly difficult, it pays to know what can be done to streamline it. Sometimes
programmers are willing to do things that will help the testing process, and a checklist of
possible design points, features, and so on can be useful in negotiating with them. Here
are the set of characteristics that lead to testable software.
Operability: "the better it works, more efficiently it can be tested'
Observably: "what you see is what you test"
Controllability: "the better we can control the software, the more the testing can be
automated and optimized
Decomposability: "by controlling the scope of testing, we can more quickly isolate
problems and perform smarter retesting".
Simplicity: "the less there is test; the more quickly we can test it
Stability: "the fewer the changes, the fewer the disruption to testing"
Understandability: 'the more the information we have, the smarter we can test."

Unit test cases


Unit testing focuses verification effort on the smallest unit of the software design the
stage. Using the procedural design description as a guide important control paths are
tested to uncover errors within the boundary of the stage the relative complexity of test
and uncovered errors is limited by constrained scope established for unit testing. The unit
test is normally white box oriented and the step can be conducted in a parallel for multiple
stages.
Unit test considerations
The stage interface is tested to ensure that information properly flows into and out of the
program unit under, test. The local data structure is examined to ensure that the data
stored temporarily maintains its integrity during all steps in algorithms executions.
Boundary condition are tested to ensure that the stage operates properly at boundaries
established to limit or restrict processing.

Dept. of ISE, AMCEC 2020-2021 Page 30


TETRIS GAME

SNAPSHOTS

Dept. of ISE, AMCEC 2020-2021 Page 31


TETRIS GAME

CHAPTER 7
CONCLUSION
Android as a full, open and free mobile device platform, with its powerful function and
good user experience rapidly developed into the most popular mobile operating system.
This report gives an overview of the different challenges and issues faced in android app
development. The experience of developing an android app is quite challenging,
motivating as well as satisfying.

Here we tried to show the brief description of Game theory. Along with this we showed
some features of game. Then we gave a brief of Artificial Intelligence along with games
and usage of AI in games. After this we explained about the gaming searches in
algorithms used mainly for the Tetris. And after all this, description of Tetris in the form
of case study is explained where the algorithm is optimized for using lesser indices so that
there is less complexity for guessing the tack number.

REFERENCES
➢ https://developer.android.com

➢ https://www.javatpoint.com

TEXT BOOKS
➢ Busy Coder’s Guide to Advanced Android Development
➢ Beginning Android 4 Games Development

Dept. of ISE, AMCEC 2020-2021 Page 32

You might also like