TETRIS1 Merged
TETRIS1 Merged
Micro-project
report on
Types of Network
Submitted To
MSBTE
In Partial Fulfilment of
Requirement of Diploma of
Computer Engineering
Under I Scheme
Submitted By
CERTIFICATE
Seal of
Institution
INDEX
1 Acknowledgement 1
2. Abstract 2
3. Introduction 3
4. Java Programming 4
7. Program 9-20
8. Output 21
9. Reference 22
Department of Computer Engineering Tetris Game
ACKNOWLEDGEMENT
First, I would like to take this opportunity to thank our lecturer MR.T.C.MHAPANKAR SIR
for guidance and advice on this project. This project would not have completed without their
enormous help and worthy experience.
I am very much thankful to Principal Mr. G. A. Bhosale for this support and encouragement.
This work I complete with blessings of my all-family members. I express my sincere
gratitude towards them for their kind co-operation and encouragement which helped me in
completion of this project. I would like to express my sincere thanks to all teaching and non-
teaching staff of department of COMPUTER ENGINEERING, YBIT for their expert advice
and help. It was indeed a fabulous experience and learning for me to work on this project.
Last but not least I would like to thank all my friends and well-wishers who were involved
directly or indirectly in successful completion of the present work.
YBIT 1|Page
Department of Computer Engineering Tetris Game
ABSTRACT
The Tetris game is one of the most popular computer games ever created. As the years go, there
are many developers that develop the tetris game due to the people in the world needs
something new in the game. This project will implement the concept of tetris game and make
the game more complicated by modify the directions of the falling tetrominoes and modify the
meeting point of the tetrominoes.
This project was made using the Java programming language and the data will be transformed
from binary numbers into a shape of the tetrominoes using the two dimensional array. The
output will be a tetris game which has four directions of the falling tetrominoes and will be met
together in the center of the board game.
Tetris game is a classic game of logic control. This article gives a programming design of Tetris
game based on the FPGA using VHDL. Game players can move and rotate blocks with the
PS/2 interface keyboard, and the game video is showed in a VGA monitor. The game realized
the function of the movement and rotation of blocks, randomly generating next blocks,
eliminating rows, getting scores and speeding up. It also contained the normal mode
corresponding to 7 types of blocks and the expert mode corresponding to 11 types of blocks.
Tetris is a very popular game that has served as an inspiration for many puzzle-style,
tilematching video games we have. The fan base is growing every year because there are many
variations of the game each with its own adjustments and different ways of gameplay. Each of
these variations have concepts such as, speed increase, special effects, music and theme
differences, colours, world environments, game boards and number of tetrominoes/shapes
possible to clear rows, new bonus awards other than getting a Tetris in the game, for example
DodecaTetris and OctoTetris.
Recently, the Tetris industry provided another variation called Tetris effect that heavily focuses
on effects and somewhat time manipulation which has helped the Tetris community experience
another addition of the game. This project seeks to provide a new variation of the Tetris game,
a harder and more compelling version. Previous variations kept the hold and next feature which
just makes the game too easy, especially for the Experts.
This Tetris project will remove them and may only make them available by earning scores and
levels for a temporary time. This project will also include an augmented reality integration to
give its final edge. The current literature on this Tetris game variation is examined in order to
clearly describe what has been done, what has worked, and the challenges that have arisen in
this context. To achieve the intended goal, a methodology and design approach were
established based on the literature research.
YBIT 2|Page
Department of Computer Engineering Tetris Game
INTRODUCTION
One of Java's primary strengths lies in its "write once, run anywhere" philosophy, enabled by
the Java Virtual Machine (JVM). This unique feature allows Java programs to be compiled into
bytecode, which can then be executed on any device with a JVM installed, irrespective of the
underlying operating system. This portability makes Java an ideal choice for developing cross-
platform applications, ensuring consistent performance across diverse environments.
Additionally, Java's rich standard library, coupled with a vast ecosystem of third-party libraries
and frameworks, provides developers with a wealth of tools and resources to streamline
development and tackle complex challenges effectively.
YBIT 3|Page
Department of Computer Engineering Tetris Game
JAVA PROGRAMMING
Java programming language, renowned for its versatility and robustness, offers a rich set of
features and capabilities that make it well-suited for a wide range of applications. One of the
key strengths of Java is its platform independence, achieved through the Java Virtual Machine
(JVM).
Java source code is compiled into bytecode, which can run on any device with a JVM installed,
regardless of the underlying hardware or operating system. This portability has made Java a
popular choice for developing cross-platform applications, including web applications, mobile
apps, and enterprise-level systems.
Java's object-oriented programming (OOP) paradigm is another fundamental aspect that
contributes to its popularity and effectiveness. With OOP, developers can model real-world
entities as objects, encapsulating data and behavior within classes. This approach promotes
code organization, modularity, and reusability, leading to more maintainable and scalable
software solutions. Inheritance, polymorphism, and encapsulation are core principles of OOP
supported by Java, allowing developers to create hierarchies of classes, achieve code
extensibility, and implement modular designs.
Java's security features, including its robust memory management, bytecode verification, and
sandboxing mechanisms, contribute to its reputation as a secure programming language,
making it a preferred choice for developing mission-critical and high-security applications.
Overall, Java's combination of platform independence, object-oriented programming,
extensive standard library, security features, and community-driven ecosystem makes it a
versatile and powerful tool for building a wide variety of software applications.
YBIT 4|Page
Department of Computer Engineering Tetris Game
Java programming encompasses a wide range of concepts that form the foundation of the
language and are essential for developing robust and efficient applications. Here are some key
concepts of Java programming:
2. Classes and Objects: Classes are blueprints for creating objects, defining their
structure and behavior. Objects are instances of classes, representing real-world entities.
Classes encapsulate data and behavior related to a particular entity, promoting code
reusability and modularity.
3. Inheritance: Inheritance allows a class (subclass or child class) to inherit attributes and
methods from another class (superclass or parent class). This promotes code reuse and
facilitates the creation of hierarchies of related classes.
YBIT 5|Page
Department of Computer Engineering Tetris Game
7. Packages: Packages are used to organize classes and interfaces into namespaces,
providing a hierarchical structure to Java applications. Packages help in avoiding naming
conflicts, enhancing code readability, and facilitating modular development.
10. Generics: Generics enable the creation of parameterized classes and methods, allowing
developers to write reusable and type-safe code. Generics enhance code readability and
maintainability by enabling compile-time type checking and reducing the need for explicit type
casting.
These are just a few of the many concepts that form the backbone of Java programming.
Mastering these concepts is essential for becoming proficient in Java development and building
robust, scalable, and maintainable software solutions.
YBIT 6|Page
Department of Computer Engineering Tetris Game
TETRIS
Tetris is a surprising game. On paper, at least, it seems unlikely that something so basic should
have done so well beyond the year 1975. Nevertheless, it’s been a consistently popular video
game for decades. It was invented in Russia, and it was never expected to be as popular as it
became. Yet, the reason it is so popular is that it meets the key criteria for fun in a game. That
is, it has goals, rules, feedback, participation is voluntary, and there are unnecessary obstacles
that keep the game challenging.
Goals
The aim in Tetris is simple; you bring down blocks from the top of the screen. You can move
the blocks around, either left to right and/or you can rotate them. The blocks fall at a certain
rate, but you can make them fall faster if you’re sure of your positioning. Your objective is to
get all the blocks to fill all the empty space in a line at the bottom of the screen; whenever you
do this, you’ll find that the blocks vanish and you get awarded some points.
A goal gives us a reason to play the game. Tetris offers an incredibly simple reason to play—
pitting your wits against the computerized block dropper in order to last as long as you can.
Rules
Tetris has very simple rules: you can only move the pieces in specific ways; your game is over
if your pieces reach the top of the screen; and you can only remove pieces from the screen by
filling all the blank space in a line.
Rules give much needed structure to our play. A completely random environment offers no
clue as to how to play and would be incredibly frustrating. How fortunate it is, then, that Tetris’s
three rules are what shape it into such an award-winning game.
YBIT 7|Page
Department of Computer Engineering Tetris Game
You have probably seen Tetris (or even played it), but, just in case—this is what Tetris looks
like.
Feedback
Each time you clear a line in Tetris, you are awarded more points. Each time your pieces reach
the top of the screen, your game is over. That means, if you’re not particularly attentive, your
game can be over very quickly.
Feedback in Tetris is instant and incontrovertible. You always know how well you are
performing as you play the game. We like feedback, and this enables us to feel
satisfied/dissatisfied with our performance. track here.
Obstacles
Tetris has a cunning means of adding challenge. It becomes faster the better you do. This means
you have to make the same decisions but under a higher level of pressure. There’s no end in
Tetris if you could think and move your fingers fast enough – you could literally play forever.
However, this is the real genius of Tetris – we play it because it keeps us in a state of “flow”;
that is, it balances our skills with the challenge in hand. We’ll never “finish” the game, but we
are constantly compelled to come back again and try to do a little bit better. Take the highest
level you’ve reached and remember the fast, furious gameplay involved. Yes, we’re talking
endorphins again… and going “Grr” when a piece lands badly… and perhaps shouting at
anyone who dares to distract us in these tension-laced-but-addictively-fun moments.
YBIT 8|Page
Department of Computer Engineering Tetris Game
PROGRAM
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Timer;
public Shape() {
void initShape() {
// set the shape of the piece to the given shape and set the coordinates of the piece to the
coordinates of the given shape
protected void setShape(Tetrominoe shape) {
}
}
pieceShape = shape;
}
void setX(int index, int x) { coords[index][0] = x; } // set the x coordinate of the piece
void setY(int index, int y) { coords[index][1] = y; } // set the y coordinate of the piece
public int x(int index) { return coords[index][0]; } // get the x coordinate of the piece
public int y(int index) { return coords[index][1]; } // get the y coordinate of the piece
public Tetrominoe getShape() { return pieceShape; } // get the shape of the piece
// set the shape of the piece to a random shape everytime a new piece is created
public void setRandomShape() {
int m = coords[0][0];
for (int i=0; i < 4; i++) { // for the no of rows in the shape
int m = coords[0][1];
for (int i=0; i < 4; i++) { // for the no of rows in the shape
result.setX(i, y(i)); // set the x coordinate of the new shape to the y coordinate of the
piece
result.setY(i, -x(i)); // set the y coordinate of the new shape to the negative x coordinate
of the piece
}
result.setX(i, -y(i)); // set the x coordinate of the new shape to the negative y coordinate
of the piece
result.setY(i, x(i)); // set the y coordinate of the new shape to the x coordinate of the
piece
}
Timer timer;
boolean isFallingFinished = false; // check if the piece has finished falling
boolean isStarted = false; // check if the game has started
boolean isPaused = false; // check if the game is paused
int numLinesRemoved = 0; // the number of lines removed
int curX = 0; // the current x coordinate of the piece
int curY = 0; // the current y coordinate of the piece
JLabel statusbar;
Shape curPiece;
Tetrominoe[] board;
initBoard(parent);
}
setFocusable(true);
setBorder(BorderFactory.createLineBorder(Color.pink, 4));
timer = new Timer();
timer.scheduleAtFixedRate(new ScheduleTask(),
INITIAL_DELAY, PERIOD_INTERVAL);
statusbar = parent.getStatusBar();
board = new Tetrominoe[BOARD_WIDTH * BOARD_HEIGHT];
addKeyListener(new TAdapter());
clearBoard();
}
int squareWidth() {
return (int) getSize().getWidth() / BOARD_WIDTH;
}
int squareHeight() {
return (int) getSize().getHeight() / BOARD_HEIGHT;
}
isStarted = true;
clearBoard();
newPiece();
}
void pause() {
if (!isStarted) {
return;
}
isPaused = !isPaused;
if (isPaused) {
statusbar.setText("Paused");
} else {
statusbar.setText(String.valueOf(numLinesRemoved));
}
}
if (shape != Tetrominoe.NoShape) {
drawSquare(g, 0 + j * squareWidth(),
boardTop + i * squareHeight(), shape);
}
}
}
super.paintComponent(g);
doDrawing(g);
}
int newY = curY; // set the new y coordinate to the current y coordinate
if (!tryMove(curPiece, curX, newY - 1)) { // if the piece cannot move to the new
coordinates
pieceDropped();
}
}
void clearBoard() {
void pieceDropped() {
if (!tryMove(curPiece, curX, curY)) { // if the piece cannot move to the new coordinates
curPiece.setShape(Tetrominoe.NoShape); // set the shape of the piece to a no shape
timer.cancel();
isStarted = false;
statusbar.setText("GAME OVER!");
}
}
}
}
repaint(); // repaint the board with the new coordinates of the piece
for (int i = BOARD_HEIGHT - 1; i >= 0; --i) { // for the no of rows in the board
boolean lineIsFull = true; // set the line is full to true
for (int j = 0; j < BOARD_WIDTH; ++j) { // for the no of columns in the board
for (int k = i; k < BOARD_HEIGHT - 1; ++k) { // for the no of rows in the board
for (int j = 0; j < BOARD_WIDTH; ++j) { // for the no of columns in the board
YBIT 16 |
Page
Department of Computer Engineering Tetris Game
Color colors[] = {
new Color(0, 0, 0), new Color(204, 102, 102),
new Color(102, 204, 102), new Color(102, 102, 204),
new Color(204, 204, 102), new Color(204, 102, 204),
new Color(102, 204, 204), new Color(218, 170, 0),
};
g.setColor(color);
g.fillRect(x + 1, y + 1, squareWidth() - 2, squareHeight() - 2);
g.setColor(color.brighter());
g.drawLine(x, y + squareHeight() - 1, x, y);
g.drawLine(x, y, x + squareWidth() - 1, y);
g.setColor(color.darker());
g.drawLine(x + 1, y + squareHeight() - 1,
x + squareWidth() - 1, y + squareHeight() - 1);
g.drawLine(x + squareWidth() - 1, y + squareHeight() - 1,
x + squareWidth() - 1, y + 1);
void doGameCycle() {
update();
repaint();
}
void update() {
YBIT 17 |
Page
Department of Computer Engineering Tetris Game
@Override
public void keyPressed(KeyEvent e) {
int keycode = e.getKeyCode(); // get the key code of the pressed key
if (isPaused) {
return;
}
@Override
public void run() {
doGameCycle();
}
}
}
public Tetris() {
initUI();
}
void initUI() {
setTitle("Tetris");
YBIT 19 |
Page
Department of Computer Engineering Tetris Game
setSize(400, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setLocationRelativeTo(null);
}
return statusbar;
}
EventQueue.invokeLater(() -> {
YBIT 20 |
Page
Department of Computer Engineering Tetris Game
OUTPUT
YBIT 21 |
Page
Department of Computer Engineering Tetris Game
REFERENCE
https://www.cs.cornell.edu/boom/1999sp/projects/Tetris/whatis.htmL
https://tetris.com/about-us
https://medium.com/better-advice/playing-tetris-with-your-time-6ea044e64e0a
https://www.britannica.com/topic/Tetris
YBIT 22 |
Page