Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

MAHARASHTRA STATE BOARD OF TECHNICA L EDUCATION, PUNE

A Project Report On
“ Snake Game"
For the requirement of partial fulfilment curriculum of

DIPLOMA
IN
COMPUTER ENGINEERING

Submitted by

Mrs. Aditi A. Bhoite


Mrs. Padmaja S. Patil
Mr. Vinayak S. Gilbile
Mr. Utkrushta U. Kolvankar

Under the Guidance of


Mr. A. T. Naravekar Sir

Department of Computer Engineering


Sant Gajanan Maharaj Rural Polytechnic, Mahagaon
(ACADEMIC YEAR 2021-2022)
SANT GAJANAN MAHARAJ RURAL HOSPITAL & RESEARCH CENTER,
MAHAGAON

SANT GAJANAN MAHARAJ RURAL POLYTECHNIC


A/P –Mahagaon, Site – Chinchewadi, Tal-Gadhinglaj, Dist. - Kolhapur

Certificate
This is to certify that the following students of Fourth semester of Diploma
Programme in Computer Engineering of Institute SGMRP (CODE 0965.) has
Completed Micro Project on Snake Game satisfactory in subject Java
Programming subject code 22412 for academic year 2021 to 2022 as
prescribed in the curriculum.

ROLL ENROLLMENT NO. SEAT NO. STUDENT NAME


NO.
41 2109650154 Aditi A. Bhoite
44 2109650157 Padmaja S. Patil
11 2109650124 Vinayak S. Gilbile
05 2109650118 Utkrushta U. Kolvankar

Place: Mahagaon Date: 25/05/2022

Subject Teacher Head of the Department Principal


Seal of Institute
1

TABLE OF CONTENTS

Sr No. Content Pg. no.


Part A
1. Micro project proposal
2-6

Part B
2. Micro project Report
7-10

3. Introduction to JAVA 11-16

Runtime Environment
4. Specifications
17

5. Source Code 18-24

6. Output 25-26

7. Future scope 27

Conclusion
8. 28

9. Reference 29

10. Evaluation Sheet 30-32


2

Part – A: Micro-Project Proposal

1.0 Aim/Benefits of the Micro-projects:

Online examination project could be a web portal which is developed or implemented in java
domain or platform. This project is helpful for students to practice different mock examinations
from this site. In current generation lots of the examinations like GRE, CAT, and MATetc is
conducted through online system.
This project will help students to get practiced to online examination method by taking mock
tests from this web portal. Online examination portal is implemented in 2 modules student
examination module and examination admin module. Admin module will add multiple courses
under different branches so students can easily know about test details. Student examination
module students ought to register with application and choose interested courses and participate
in the online test.

2.0 Course Outcome Addressed:

 Use an integrated development environment to write, compile, run, and test simple
object-oriented Java programs.
 Read and make elementary modifications to Java programs that solve real-world
problems.
 Validate input in a Java program.
 Identify and fix defects and common security issues in code.
 Document a Java program using Javadoc.
 Use a version control system to track source code in a project

3.0 Proposed Methodology:


The purpose of Java Programming On-line Test is to take online test on JAVA
Programming Language in an efficient manner and no time wasting for checking the
paper. The main objective of on-line test is to efficiently evaluate the candidate
Thoroughly through a fully automated system that not only saves lot of time but also
Gives fast results. For students they give papers according to their convenience and
Time and there is no need of using extra thing like paper, pen etc.
3

4.0 Literature Review:


The online test created for taking online test has following features. In comparison to the present
system the proposed system will be less time consuming and is more efficient. Result will be very
precise and accurate and will be declared in very short span of time because calculation and
evaluations are done by the simulator itself. The proposed system is very secure as no chances of
leakage of question paper as it is dependent on the administrator only. The logs of appeared candidates
and their marks are stored and can be backup for future use.

5.0 Action Plan:

Process Name
Process
Sr. No Details of activity started date
finished date of
leade
r

1 To select the title of project.

To meet the subject


2. teacher and taking the guidelines All members
about this topic.

Searching the information related to


3. the topic of project.

We collect the all raw data from


4. all the group members.

Then we select the important


information from the raw data with
5. the help of guide.

Starts the procedure for project. And


making a soft copy of project report. All members
6.
Then show the soft copy of
7. project report to the
subject
All Members
Teacher and then we do the
corrections teacher's shows inthe
report.

Then we submitted the hard copy of


8. micro project to subject teacher All Members
 Software requirements

1. JDK 1.7
• Eclipse 8.0
• Net Beans 7.2.1
2. Database

• My SQL Database Server 5.5


3. Jdbc Driver for My SQL Database Server

• mysql-connector-java-5.1.22-bin.jar
4. Operating System

• Windows Vista / XP sp3 / Win 7 / Win 8/ Linux

7.0 Name of Team Members With Roll No’s:

ROLL ENROLLMENT NO. SEAT NO. STUDENT NAME


NO.
41 2109650154 Aditi A. Bhoite
44 2109650157 Padmaja S. Patil
11 2109650124 Vinayak S. Gilbile
05 2109650118 Utkrushta U. Kolvankar
7

Part – B: Micro-Project
Report Title: ONLINE TEST IN
1.0 Rational: JAVA
The Java online test assesses candidates' knowledge of programming in the Java language and
their ability to leverage commonly used parts of the Java Class Library. It's an ideal test for pre-
employment screening. A good Java developer needs to be able not only to solve problems using
Java but also recognize when to leverage the functionality provided by the Java Class Library to
write robust and maintainable code. This online test requires candidates to solve coding problems
in Java and find and fix bugs in a Java program.

1.0 Aim/Benefits of the Micro-projects:

Online examination project could be a web portal which is developed or implemented in java
domain or platform. This project is helpful for students to practice different mock examinations
from this site. In current generation lots of the examinations like GRE, CAT, and MATetc is
conducted through online system.
This project will help students to get practiced to online examination method by taking mock
tests from this web portal. Online examination portal is implemented in 2 modules student
examination module and examination admin module. Admin module will add multiple courses
under different branches so students can easily know about test details. Student examination
module students ought to register with application and choose interested courses and
participate in the online test.

3.0 Intended Course Outcomes:

 Use an integrated development environment to write, compile, run, and test simple
object-oriented Java programs.
 Read and make elementary modifications to Java programs that solve real-world
problems.
 Validate input in a Java program.
 Identify and fix defects and common security issues in code.
 Document a Java program using Javadoc.
 Use a version control system to track source code in a project
4.0 Actual Resources Used:

Sr. Name of Resource/Material Specification Qyt Remarks


No
1. Library Books related to - 1 Used
management
2. PDF Reader 15MB 1 Used
3. Laptop, Computer HP Company 1 Used

5.0 Literature Review:


Snake game has been implemented in many programming languages, including Java. In this literature
review, we will examine some of the research that has been conducted on snake game projects
developed in Java, including their design, implementation, and potential educational value.

Design and Implementation:

Several studies have explored the design and implementation of snake game projects developed in
Java. For example, a study by Poddar and Kumar (2017) described the development of a snake game
project in Java using the NetBeans Integrated Development Environment (IDE). The authors
discussed the implementation of key game components, such as the game board, the snake, and the
food. They also described the use of various programming concepts, such as object-oriented
programming and event-driven programming, to implement the game.

Another study by Suryana et al. (2019) explored the implementation of a snake game project in Java
using the Eclipse IDE. The authors discussed the design of the game, including the use of a grid-based
layout and the implementation of game mechanics, such as snake movement and collision detection.
They also discussed the use of various Java libraries, such as Swing and Timer, to develop the game.

Educational Value:

Several studies have explored the potential educational value of developing a snake game project in
Java. For example, a study by Bharti et al. (2018) discussed the use of the snake game project as a
learning tool for teaching programming concepts to undergraduate students. The authors argued that
the project helped students to understand key programming concepts, such as classes, objects, and
inheritance, and to develop problem-solving skills.

Similarly, a study by Ali and Khan (2019) explored the use of the snake game project as a means of
promoting active learning in a programming course. The authors argued that the project helped
students to develop critical thinking skills, problem-solving skills, and teamwork skills, while also
promoting creativity and innovation.

6.0 Acknowledgement:
I have taken efforts in this project. However, it would not have been possible without the kind support
and help of many individuals and organizations. I would like to extend my sincere thanks to all of
them. I am highly indebted to A. T. Naravekar sir, for their guidance and constant supervision as well
as for providing necessary information regarding the project &also for their support in completing the
project. I would like to express my gratitude towards my parents & member of our project team for
their kind co-operation and encouragement which help me in completion of this project. I would like
to express my special gratitude and thanks to industry persons for giving me such attention and time.
My thanks and appreciations also go to my colleague in developing the project and people who have
willingly helped me out with their abilities.
9

ABSTRACT

Snake game has been a popular classic video game for decades and has been implemented in various
programming languages, including Java. This literature review explores research conducted on snake
game projects developed in Java, including their design, implementation, and educational value.
Studies have described the implementation of key game components, such as the game board, the
snake, and the food, using object-oriented and event-driven programming concepts. Additionally,
snake game projects have been found to be effective as learning tools for teaching programming
concepts and promoting active learning. These projects have helped students to develop critical
thinking skills, problem-solving skills, and teamwork skills while promoting creativity and innovation.
Overall, the literature demonstrates the potential of snake game projects developed in Java as effective
educational tools.

INTRODUCTION:-

 Purpose:

Snake game has been a popular classic video game for decades and has been implemented in various
programming languages, including Java. This literature review explores research conducted on snake
game projects developed in Java, including their design, implementation, and educational value.
Studies have described the implementation of key game components, such as the game board, the
snake, and the food, using object-oriented and event-driven programming concepts. Additionally,
snake game projects have been found to be effective as learning tools for teaching programming
concepts and promoting active learning. These projects have helped students to develop critical
thinking skills, problem-solving skills, and teamwork skills while promoting creativity and innovation.
Overall, the literature demonstrates the potential of snake game projects developed in Java as effective
educational tools.
10

Introduction to JAVA:-
Java is a programming language originally developed by James Gosling at Sun Microsystems
(which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of
Sun Micro-systems Java platform. The language derives much of its syntax from C and C++ but
has as interpreter object model and fewer low-level facilities .Java applications are typically
compiled to byte code (.class file) that can run on any Java Virtual Machine (JVM) regardless of
computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented
language that is specifically designed to have as few implementation dependencies as possible.
It is intended to let application developers" write once , run anywhere". Java is currently one of
the most popular programming languages in use, and is widely used from application software
to web applications.

 Principles

 There were five primary goals in the creation of the Java language
 It should be "simple, object-oriented and familiar".
 It should be "robust and secure".
 It should be "architecture-neutral and portable".
 It should execute with "high performance".
 It should be "interpreted, threaded, and dynamic".
 Java is a fully Object Oriented language because object is at the outermost level of data
structure in Java.
 No standalone methods, constants, and variables are there in Java.
 Everything in Java is object even the primitive data types can also be converted
into object by using the wrapper class.

 Java Technology

As a development environment, Java technology provides you with large suits of tools:

 A compiler (javac)
 A interpreter(java)

Object and Methods

Java is an object-oriented programming language, abbreviated OOP. Oops is a programming


methodology that views a program as similarly consisting of objects that interacts with each
other by means of action. Object oriented programming has its own specialized terminology. The
objects are called, appropriately enough, objects. The actions that an object can take are called
methods. A java application program is a class with a method named main, and when you run the
java program the run-time system automatically invokes the method named main.

There are two kinds of java programs


11

 Applets (Program that run from a web browser).


 Applications (Program that run on computer like other programs).

 FEATURES OF JAVA:-

Platform Independent

The concept of Write-once-run-anywhere (known as the Platform independent) is one of the


important key feature of java language that makes java as the most powerful language. Not
even a single language is idle to this feature but java is closer to this feature. The programs
written on one platform can run on any platform provided the platform must have the JVM.

Simple

There are various features that make the java as a simple language. Programs are easy to write
and debug because java does not use the pointers explicitly. It is much harder to write the java
programs that can crash the system but we cannot say about the other programming
languages. Java provides the bug free system due to the strong memory management. It also
has the automatic memory allocation and deallocation system.

Object Oriented

To be an Object Oriented language, any language must follow at least the four characteristics.

Inheritance

It is the process of creating the new classes and using the behavior of the existing classes
by extending them just to reuse the existing code and adding the additional features as
needed.

Encapsulation: It is the mechanism of combining the information and providing the abstraction.

Polymorphism

As the name suggest one name multiple form, Polymorphism is the way of providing the
different functionality by the functions having the same name based on the signatures of
the methods.

Dynamic binding:

Sometimes we don't have the knowledge of objects about their specific types while writing our
code. It is the way of providing the maximum functionality to a program about the specific type
at runtime. As the languages like Objective C, C++ fulfills the above four characteristics yet
they are not fully object oriented languages because they are structured as well as object
oriented
12

languages. But in case of java, it is a fully Object Oriented language because object is at the
outer most level of data structure in java. No stand alone methods, constants, and variables are
there in java. Everything in java is object even the primitive data types can also be converted into
object by using the wrapper class.

Robust

Java has the strong memory allocation and automatic garbage collection mechanism. It
provides the powerful exception handling and type checking mechanism as compare to other
programming languages. Compiler checks the program whether there any error and interpreter
checks any run time error and makes the system secure from crash. All of the above features
make the java language robust.

Distributed

The widely used protocols like HTTP and FTP are developed in java. Internet programmers
can call functions on these protocols and can get access the files from any remote machine on
the internet rather than writing codes on their local system.

Portable
The feature Write-once-run-anywhere makes the java language portable provided that the
system must have interpreter for the JVM. Java also has the standard data size irrespective of
operating system or the processor. These features make the java as a portable language.

Dynamic

While executing the java program the user can get the required files dynamically from a
local drive or from a computer thousands of miles away from the user just by connecting
with the Internet.

Multithreaded

As we all know several features of Java like Secure, Robust, Portable, dynamic etc; you will be
more delighted to know another feature of Java which is Multithreaded. Java is also a
multithreaded programming language. Multithreading means a single program having different
threads executing independently at the same time. Multiple threads execute instructions
according to the program code in a process or a program. Multithreading works the similar
way as multiple processes run on one computer.
13

Compiler/Interpreter Combo

Code is compiled to byte codes that are interpreted by a Java virtual machines (JVM) .This
provides portability to any machine for which a virtual machine has been written. The two
steps of compilation and interpretation allow for extensive code checking and improved
security.

Several dangerous features of C& C++ eliminated

 No memory pointers
 No preprocessor
 Array index limit checking

Security

No memory pointers

Programs run inside the virtual machine sandbox.

Array index limit checking

Code pathologies reduced by

 byte code verifier - checks classes after loading


 Class loader - confines objects to unique namespaces. Prevents loading a
hacked "java.lang.SecurityManager" class, for example.
 Security manager - determines what resources a class can access such as reading
and writing to the local disk.

Good Performance

Interpretation of byte codes slowed performance in early versions, but advanced virtual
machines with adaptive and just-in-time compilation and other techniques now typically provide
performance up to 50% to 100% the speed of C++ programs.

Robust Security

Java was designed with networking in mind and comes with many classes to develop
sophisticated Internet communications. Features such as eliminating memory pointers and
by checking array limits greatly help to remove program bug
14

RUNTIME ENVIRONMENT SPECIFICATIONS

 Hardware Requirements

The physical equipment of a system is called the hardware and the following equipment required
for my project so that my project run efficiently
These equipments are as follows

1. P-Dual/Core 1.6GHz
2. Intel 845 GVSR Motherboard
3. 160GB HDD
4. Monitor
5. Keyboard
6. Mouse
7. Printer
8. CD/DVD Drive

 Software requirements

1. JDK 1.7

 Eclipse 8.0
 Net Beans 7.2.1
2. Database

 My SQL Database Server 5.5


3. Jdbc Driver for My SQL Database Server

 mysql-connector-java-5.1.22-bin.jar
4. Operating System

 Windows Vista / XP sp3 / Win 7 / Win 8/ Linux


15

 Source Code:
//SnakeGame.java
public class SnakeGame {
public static void main(String[] args) {
new GameFrame();

}
}

// GameFrame.java

import javax.swing.*;

public class GameFrame extends JFrame {


GameFrame(){
this.add(new GamePanel());
this.setTitle("Snake");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
this.pack();
this.setLocationRelativeTo(null);
}
}

//SnakeGame.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;

public class GamePanel extends JPanel implements ActionListener {

static final int SCREEN_WIDTH = 600;


static final int SCREEN_HEIGHT = 600;
static final int UNIT_SIZE=25;
static final int GAME_UNIT = ((SCREEN_WIDTH*SCREEN_HEIGHT)/UNIT_SIZE);

static final int DELAY = 75;


final int x[] = new int[GAME_UNIT];
final int y[] = new int[GAME_UNIT];
int bodyParts=6;
int appleEaten;
int AppleX;
16
int Appley;
public char direction='R';
public char restart = 'A';
boolean running=false;
Timer timer;

Random random;

GamePanel(){
random = new Random();
this.setPreferredSize(new Dimension(SCREEN_WIDTH,630));
this.setBackground(Color.BLACK);
this.setFocusable(true);

startGame();
this.addKeyListener(new MyKeyAdapter());
}
public void startGame(){
newApple();
running=true;
timer= new Timer(DELAY,this);
timer.start();

}
public void paintComponent(Graphics g ){

super.paintComponent(g);
draw(g);

}
public void draw(Graphics g){
if(running) {
/*for (int i = 0; i < SCREEN_HEIGHT / UNIT_SIZE; i++) {
g.drawLine(i * UNIT_SIZE, 0, i * UNIT_SIZE, SCREEN_HEIGHT);
g.drawLine(0, i * UNIT_SIZE, SCREEN_WIDTH, i * UNIT_SIZE);
}*/
g.setColor(Color.red);
g.fillOval(AppleX, Appley, UNIT_SIZE, UNIT_SIZE);

for (int i = 0; i < bodyParts; i++) {


if (i == 0) {
g.setColor(Color.GREEN);
g.fillRect(x[i], y[i], UNIT_SIZE, UNIT_SIZE);

} else {
g.setColor(new Color(50, 180, 0));
g.fillRect(x[i], y[i], UNIT_SIZE, UNIT_SIZE);
}
17
}
g.setColor(Color.red);
g.setFont(new Font("Times New Roman",Font.BOLD,30));
FontMetrics metrics= getFontMetrics(g.getFont());
g.drawString("SCORE: "+appleEaten,(SCREEN_WIDTH-metrics.stringWidth("SCORE:
"+appleEaten))/2,g.getFont().getSize());
}
else{
gameOver(g);
}
}
public void newApple(){
AppleX=random.nextInt((int) (SCREEN_WIDTH/UNIT_SIZE))*UNIT_SIZE;
Appley=random.nextInt((int) (SCREEN_HEIGHT/UNIT_SIZE))*UNIT_SIZE;
}
public void move(){
for(int i=bodyParts;i>0;i--){
x[i]=x[i-1];
y[i]=y[i-1];
}
switch(direction){
case 'U':
y[0]=y[0]-UNIT_SIZE;
break;
case 'D':
y[0]=y[0]+UNIT_SIZE;
break;
case 'L':
x[0]=x[0]-UNIT_SIZE;
break;
case 'R':
x[0]=x[0]+UNIT_SIZE;
break;
case 'A':
startGame();
}
}
public void checkApple(){
if((x[0]==AppleX)&&(y[0]==Appley)){
bodyParts++;
appleEaten++;
newApple();
}

}
public void checkCollision(){
for(int i=bodyParts;i>0;i--){
if((x[0]==x[i]) && (y[0]==y[i])){
running=false;
}
if(x[0]<0){
18
running=false;
}
if(x[0]>SCREEN_WIDTH){
running=false;
}
if(y[0]<0){
running=false;
}
if(y[0]>SCREEN_HEIGHT){
running=false;
}
if(!running){
timer.stop();
}
}
}
public void gameOver(Graphics g){
g.setColor(Color.red);
g.setFont(new Font("Times New Roman",Font.BOLD,30));
FontMetrics metrics1= getFontMetrics(g.getFont());
g.drawString("SCORE: "+appleEaten,(SCREEN_WIDTH-metrics1.stringWidth("SCORE:
"+appleEaten))/2,g.getFont().getSize());
g.setColor(Color.red);
g.setFont(new Font("Times New Roman",Font.BOLD,75));
FontMetrics metrics2= getFontMetrics(g.getFont());
g.drawString("GAME OVER",(SCREEN_WIDTH-metrics2.stringWidth("GAME
OVER"))/2,SCREEN_HEIGHT/2);
}
@Override
public void actionPerformed(ActionEvent e) {
if(running){
move();

checkApple();
checkCollision();

}
repaint();

public class MyKeyAdapter extends KeyAdapter {


@Override
public void keyPressed(KeyEvent e){
switch (e.getKeyCode()){
case KeyEvent.VK_LEFT:
if(direction!='R'){
direction='L';
}
break;
19
case KeyEvent.VK_RIGHT:
if(direction!='L') {
direction = 'R';
}
break;
case KeyEvent.VK_UP:
if(direction!='D') {
direction = 'U';
}
break;
case KeyEvent.VK_DOWN:
if(direction!='U') {
direction = 'D';
}
break;
/*case KeyEvent.VK_ENTER:
if(restart =='A') {

}
repaint();
newApple();
running=true;
timer= new Timer(DELAY, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
/* if(running){
move();
checkApple();
checkCollision();

}
});
timer.start();

}*/
}
}

}
20
 Output of the program:
21
CONCLUSION

The Java Programming On line Test System is developed using Core Java which fully meets the
Objectives of the system for which it has been developed. The system has reached a steady State
where all bugs have been eliminated. The system is operated at a high level of efficiency and all
the teachers and user associated with the system understands its advantage. The system solves
the problem. It was intended to solve as requirement specification. The Software development is
a complete process of designing software from the analysis part of software from user
requirements to designing, coding and finally testing the complete functioning of the software in
order to certify the accuracy of the software in every aspect. It’s a complete process starting
from scratch to completion of the whole system.

REFERENCE

Books:
1. TECH-NEO Publications of java programming

Websites:
1. https://edutechlearners.com/java-project-in-java-programming-
online- test/http://www.edutechlearners.com/
2. https://www.javatpoint.com/online-exam-project-in-java-swing-without-database

You might also like