SlideShare a Scribd company logo
1 of 49
ACKNOWLEDGEMENT
So, with gratitude we acknowledge all those who guided and encouraged has
served a beacon of light and crowned the effect with success.
We would like to thank SURESH GYAN VIHAR UNIVERSITY for providing an
opportunity to carry out the project successfully.
We would then like to thank Miss. Tanuja Rajput
Mam who guided and provided the technical and moral supportthroughout the
project. Next we would also to thank the entire faculty for their full co-operation.
REQUIREMENTS :-
Hardware Requirements:-
Processor : 2 MHZ
RAM : 2 GB
Hard Disk : 10 GB (Free space on HDD)
Software Requirements:-
Operating System :- Windows 10 pro
Softwear :- NetBeans IDE 8.0.1
SOURCECODE:-
snake.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class Snake extends JFrame implements KeyListener, Runnable {
JPanel p1, p2;
JButton[] lb = new JButton[200];
JButton bonusfood; JTextArea t; int x = 500, y = 250, gu = 2, directionx = 1, directiony = 0, speed =
50, difference = 0, oldx, oldy, score = 0; int[] lbx = new int[300]; int[] lby = new int[300];
Point[] lbp = new Point[300];
Point bfp = new Point(); Thread myt; boolean food = false, runl = false, runr =
true, runu = true, rund = true, bonusflag = true; Random r = new Random();
JMenuBar mymbar;
JMenu game, help, level;
public void initializeValues()
{ gu = 3; lbx[0] = 100;
lby[0] = 150; directionx =
10; directiony = 0;
difference = 0;
score = 0;
food = false;
runl = false; runr
= true; runu =
true; rund = true;
bonusflag = true;
}
Snake() {
super("Snake");
setSize(500, 330);
//Create Menue bar with functions
creatbar();
//initialize all variables
initializeValues(); // Start of UI design
p1 = new JPanel(); p2 = new JPanel();
// t will view the score t = new
JTextArea("Score ==>" + score);
t.setEnabled(false);
t.setBackground(Color.BLACK);
// snake have to eat bonousfood to
growup bonusfood =new JButton();
bonusfood.setEnabled(false); // will make
first snake createFirstSnake();
p1.setLayout(null);
p2.setLayout(new GridLayout(0, 1));
p1.setBounds(0, 0, x, y);
p1.setBackground(Color.blue);
p2.setBounds(0, y, x, 30);
p2.setBackground(Color.RED);
p2.add(t); // will contain score board
// end of UI design
getContentPane().setLayout(null);
getContentPane().add(p1);
getContentPane().add(p2);
show();
setDefaultCloseOperation(EXIT_ON_CLOSE);
addKeyListener(this);
// start thread myt = new
Thread(this); myt.start(); // go to
run() method
}
public void createFirstSnake() {
// Initially the snake has small length 3
for (int i = 0; i < 3; i++) { lb[i] = new
JButton("lb" + i);
lb[i].setEnabled(false); p1.add(lb[i]);
lb[i].setBounds(lbx[i], lby[i], 10, 10);
lbx[i + 1] = lbx[i] - 10; lby[i + 1] =
lby[i];
}
}
public void creatbar() {
mymbar = new JMenuBar();
game = new JMenu("Game");
JMenuItem newgame = new JMenuItem("New Game");
JMenuItem exit = new JMenuItem("Exit");
newgame.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
reset();
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
game.add(newgame);
game.addSeparator(); game.add(exit);
mymbar.add(game);
level = new JMenu("Level");
mymbar.add(level);
help = new JMenu("Help");
JMenuItem creator = new JMenuItem("Creator");
JMenuItem instruction = new JMenuItem("Instraction");
creator.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(p2, "Name :Abdullah al hasbnRollno :2006331093nSub
:cseninstitute :sust");
}
});
help.add(creator);
help.add(instruction);
mymbar.add(help);
setJMenuBar(mymbar);
}
void reset() {
initializeValues();
p1.removeAll();
myt.stop();
createFirstSnake();
t.setText("Score==>" + score);
myt = new Thread(this);
myt.start();
}
void growup() {
lb[gu] = new JButton();
lb[gu].setEnabled(false);
p1.add(lb[gu]);
int a = 10 + (10 * r.nextInt(48));
int b = 10 + (10 * r.nextInt(23));
lbx[gu] = a;
lby[gu] = b;
lb[gu].setBounds(a,b, 10, 10);
gu++;
}
// this method contains the logic to move the snake. player will define the derection
// this method just forward the snake to the right derection which deriction is pressed
// by the player.
void moveForward() {
for (int i = 0; i < gu; i++) {
lbp[i] = lb[i].getLocation();
}
lbx[0] += directionx;
lby[0] += directiony;
lb[0].setBounds(lbx[0], lby[0], 10, 10);
for (int i = 1; i < gu; i++) {
lb[i].setLocation(lbp[i - 1]);
}
if (lbx[0] == x) {
lbx[0] = 10;
} else if (lbx[0] == 0) {
lbx[0] = x - 10;
} else if (lby[0] == y) {
lby[0] = 10;
} else if (lby[0] == 0) {
lby[0] = y - 10;
}
if (lbx[0] == lbx[gu - 1] && lby[0] == lby[gu - 1]) {
food = false; score += 5;
t.setText("Score==>" + score);
if (score % 50 == 0 && bonusflag == true) {
p1.add(bonusfood);
bonusfood.setBounds((10* r.nextInt(50)), (10 * r.nextInt(25)), 15, 15);
bfp = bonusfood.getLocation();
bonusflag = false;
}
}
if (bonusflag == false) {
if (bfp.x <= lbx[0] && bfp.y <= lby[0] && bfp.x + 10 >= lbx[0] && bfp.y + 10 >= lby[0]) {
p1.remove(bonusfood); score += 100;
t.setText("Score ==>" + score);
bonusflag = true;
}
}
if (food == false) {
growup();
food = true;
} else {
lb[gu - 1].setBounds(lbx[gu - 1], lby[gu - 1], 10, 10);
}
for (int i = 1; i < gu; i++) {
if (lbp[0] == lbp[i]) {
t.setText("GAME OVER " + score);
try {
myt.join();
} catch (InterruptedException ie) {
}
break;
}
}
p1.repaint();
show();
}
public void keyPressed(KeyEvent e) {
// snake move to left when player pressed left arrow
if (runl == true && e.getKeyCode() == 37) {
directionx = -10; // means snake move right to left by 10pixels
directiony = 0;
runr = false; // run right(runr) means snake cant move from left to right
runu = true; // run up (runu) means snake can move from down to up rund =
true; // run down (run down) means snake can move from up to down
}
// snake move to up when player pressed up arrow
if (runu == true && e.getKeyCode() == 38) {
directionx = 0;
directiony = -10; // means snake move from down to up by 10 pixel
rund = false; // run down (run down) means snake can move from up to down
runr = true; // run right(runr) means snake can move from left to right
runl = true; // run left (runl) means snake can move from right to left
}
// snake move to right when player pressed right arrow
if (runr == true && e.getKeyCode() == 39) {
directionx = +10; // means snake move from left to right by 10 pixel
directiony = 0; runl = false; runu = true; rund = true;
}
// snake move to down when player pressed down arrow
if (rund == true && e.getKeyCode() == 40) {
directionx = 0;
directiony = +10; // means snake move from left to right by 10 pixel
runu = false;
runr = true;
runl = true;
}
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
public void run() {
for (;;) {
// Move the snake move forword. In the start of the game snake move left to right,
// if player press up, down, right or left arrow snake change its direction according to
// pressed arrow
moveForward();
try {
Thread.sleep(speed);
} catch (InterruptedException ie) {
}
}
}
}
OUTPUT:-
Conclusion:-
The snake game in
java is
implemented and
executed
Successfully.
I hereby thanks to
to tanuja Rajput
mam for her
supportand guidance which helped us to complete this project.

More Related Content

What's hot

The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181Mahmoud Samir Fayed
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 
The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 53 of 189
The Ring programming language version 1.6 book - Part 53 of 189The Ring programming language version 1.6 book - Part 53 of 189
The Ring programming language version 1.6 book - Part 53 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 61 of 210
The Ring programming language version 1.9 book - Part 61 of 210The Ring programming language version 1.9 book - Part 61 of 210
The Ring programming language version 1.9 book - Part 61 of 210Mahmoud Samir Fayed
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word documentrudrapratap61
 
The Ring programming language version 1.5.3 book - Part 61 of 184
The Ring programming language version 1.5.3 book - Part 61 of 184The Ring programming language version 1.5.3 book - Part 61 of 184
The Ring programming language version 1.5.3 book - Part 61 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196Mahmoud Samir Fayed
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88Mahmoud Samir Fayed
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12jafar104
 
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212Mahmoud Samir Fayed
 

What's hot (20)

The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88
 
The Ring programming language version 1.6 book - Part 53 of 189
The Ring programming language version 1.6 book - Part 53 of 189The Ring programming language version 1.6 book - Part 53 of 189
The Ring programming language version 1.6 book - Part 53 of 189
 
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31
 
The Ring programming language version 1.9 book - Part 61 of 210
The Ring programming language version 1.9 book - Part 61 of 210The Ring programming language version 1.9 book - Part 61 of 210
The Ring programming language version 1.9 book - Part 61 of 210
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
The Ring programming language version 1.5.3 book - Part 61 of 184
The Ring programming language version 1.5.3 book - Part 61 of 184The Ring programming language version 1.5.3 book - Part 61 of 184
The Ring programming language version 1.5.3 book - Part 61 of 184
 
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180
 
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202
 
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184
 
The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12
 
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180
 
The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212
 

Similar to Snake report ROHIT MALAV

Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfillyasraja7
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon runMaja Kraljič
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdffazilfootsteps
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11nbb3i
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfpoblettesedanoree498
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdfaquacosmossystems
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swiftChiwon Song
 
ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf
ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdfANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf
ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdfanugrahafancy
 

Similar to Snake report ROHIT MALAV (20)

Aditazz 01-ul
Aditazz 01-ulAditazz 01-ul
Aditazz 01-ul
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Connect 4
Connect 4Connect 4
Connect 4
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11
 
Sbaw090519
Sbaw090519Sbaw090519
Sbaw090519
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
Voce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu CodigoVoce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu Codigo
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
 
ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf
ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdfANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf
ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf
 

More from Rohit malav

Aca lab project (rohit malav)
Aca lab project (rohit malav) Aca lab project (rohit malav)
Aca lab project (rohit malav) Rohit malav
 
operating system calls input and output by (rohit malav)
operating system calls input and output by (rohit malav)operating system calls input and output by (rohit malav)
operating system calls input and output by (rohit malav)Rohit malav
 
Python pandas liberary
Python pandas liberaryPython pandas liberary
Python pandas liberaryRohit malav
 
Presentation by purshotam verma
Presentation by purshotam vermaPresentation by purshotam verma
Presentation by purshotam vermaRohit malav
 
Deep learning in python by purshottam verma
Deep learning in python by purshottam vermaDeep learning in python by purshottam verma
Deep learning in python by purshottam vermaRohit malav
 
Atm Security System Using Steganography Nss ptt by (rohit malav)
Atm Security System Using  Steganography Nss ptt by (rohit malav)Atm Security System Using  Steganography Nss ptt by (rohit malav)
Atm Security System Using Steganography Nss ptt by (rohit malav)Rohit malav
 
Samba server Pts report pdf by Rohit malav
Samba server Pts report pdf by Rohit malavSamba server Pts report pdf by Rohit malav
Samba server Pts report pdf by Rohit malavRohit malav
 
System calls operating system ppt by rohit malav
System calls operating system  ppt by rohit malavSystem calls operating system  ppt by rohit malav
System calls operating system ppt by rohit malavRohit malav
 
A project on spring framework by rohit malav
A project on spring framework by rohit malavA project on spring framework by rohit malav
A project on spring framework by rohit malavRohit malav
 
android text encryption Network security lab by rohit malav
android text encryption Network security lab by rohit malavandroid text encryption Network security lab by rohit malav
android text encryption Network security lab by rohit malavRohit malav
 
samba server setup Pts ppt (rohit malav)
samba server setup Pts ppt (rohit malav)samba server setup Pts ppt (rohit malav)
samba server setup Pts ppt (rohit malav)Rohit malav
 
Spring frame work by rohit malav(detailed)
Spring frame work by rohit malav(detailed)Spring frame work by rohit malav(detailed)
Spring frame work by rohit malav(detailed)Rohit malav
 
spring framework ppt by Rohit malav
spring framework ppt by Rohit malavspring framework ppt by Rohit malav
spring framework ppt by Rohit malavRohit malav
 
Samba server linux (SMB) BY ROHIT MALAV
Samba server linux (SMB) BY ROHIT MALAVSamba server linux (SMB) BY ROHIT MALAV
Samba server linux (SMB) BY ROHIT MALAVRohit malav
 
Payroll system ppt1 (rohit malav)
Payroll system ppt1 (rohit malav)Payroll system ppt1 (rohit malav)
Payroll system ppt1 (rohit malav)Rohit malav
 
Payroll system ppt2 (rohit malav) version point 2
Payroll system ppt2 (rohit malav) version point 2Payroll system ppt2 (rohit malav) version point 2
Payroll system ppt2 (rohit malav) version point 2Rohit malav
 
ONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEMONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEMRohit malav
 
digital unlock power point slide
digital unlock power point slidedigital unlock power point slide
digital unlock power point slideRohit malav
 
Rohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan viharRohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan viharRohit malav
 

More from Rohit malav (20)

Aca lab project (rohit malav)
Aca lab project (rohit malav) Aca lab project (rohit malav)
Aca lab project (rohit malav)
 
operating system calls input and output by (rohit malav)
operating system calls input and output by (rohit malav)operating system calls input and output by (rohit malav)
operating system calls input and output by (rohit malav)
 
Python pandas liberary
Python pandas liberaryPython pandas liberary
Python pandas liberary
 
Presentation by purshotam verma
Presentation by purshotam vermaPresentation by purshotam verma
Presentation by purshotam verma
 
Deep learning in python by purshottam verma
Deep learning in python by purshottam vermaDeep learning in python by purshottam verma
Deep learning in python by purshottam verma
 
Atm Security System Using Steganography Nss ptt by (rohit malav)
Atm Security System Using  Steganography Nss ptt by (rohit malav)Atm Security System Using  Steganography Nss ptt by (rohit malav)
Atm Security System Using Steganography Nss ptt by (rohit malav)
 
Samba server Pts report pdf by Rohit malav
Samba server Pts report pdf by Rohit malavSamba server Pts report pdf by Rohit malav
Samba server Pts report pdf by Rohit malav
 
System calls operating system ppt by rohit malav
System calls operating system  ppt by rohit malavSystem calls operating system  ppt by rohit malav
System calls operating system ppt by rohit malav
 
A project on spring framework by rohit malav
A project on spring framework by rohit malavA project on spring framework by rohit malav
A project on spring framework by rohit malav
 
android text encryption Network security lab by rohit malav
android text encryption Network security lab by rohit malavandroid text encryption Network security lab by rohit malav
android text encryption Network security lab by rohit malav
 
samba server setup Pts ppt (rohit malav)
samba server setup Pts ppt (rohit malav)samba server setup Pts ppt (rohit malav)
samba server setup Pts ppt (rohit malav)
 
Spring frame work by rohit malav(detailed)
Spring frame work by rohit malav(detailed)Spring frame work by rohit malav(detailed)
Spring frame work by rohit malav(detailed)
 
spring framework ppt by Rohit malav
spring framework ppt by Rohit malavspring framework ppt by Rohit malav
spring framework ppt by Rohit malav
 
Samba server linux (SMB) BY ROHIT MALAV
Samba server linux (SMB) BY ROHIT MALAVSamba server linux (SMB) BY ROHIT MALAV
Samba server linux (SMB) BY ROHIT MALAV
 
Payroll system ppt1 (rohit malav)
Payroll system ppt1 (rohit malav)Payroll system ppt1 (rohit malav)
Payroll system ppt1 (rohit malav)
 
Payroll system ppt2 (rohit malav) version point 2
Payroll system ppt2 (rohit malav) version point 2Payroll system ppt2 (rohit malav) version point 2
Payroll system ppt2 (rohit malav) version point 2
 
ONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEMONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEM
 
digital unlock power point slide
digital unlock power point slidedigital unlock power point slide
digital unlock power point slide
 
Rohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan viharRohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan vihar
 
Gyan vihar app
Gyan vihar appGyan vihar app
Gyan vihar app
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 

Recently uploaded (20)

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 

Snake report ROHIT MALAV

  • 1.
  • 2.
  • 3. ACKNOWLEDGEMENT So, with gratitude we acknowledge all those who guided and encouraged has served a beacon of light and crowned the effect with success. We would like to thank SURESH GYAN VIHAR UNIVERSITY for providing an opportunity to carry out the project successfully. We would then like to thank Miss. Tanuja Rajput Mam who guided and provided the technical and moral supportthroughout the project. Next we would also to thank the entire faculty for their full co-operation. REQUIREMENTS :- Hardware Requirements:- Processor : 2 MHZ RAM : 2 GB Hard Disk : 10 GB (Free space on HDD) Software Requirements:- Operating System :- Windows 10 pro Softwear :- NetBeans IDE 8.0.1
  • 4.
  • 5.
  • 7. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; class Snake extends JFrame implements KeyListener, Runnable { JPanel p1, p2; JButton[] lb = new JButton[200]; JButton bonusfood; JTextArea t; int x = 500, y = 250, gu = 2, directionx = 1, directiony = 0, speed = 50, difference = 0, oldx, oldy, score = 0; int[] lbx = new int[300]; int[] lby = new int[300]; Point[] lbp = new Point[300]; Point bfp = new Point(); Thread myt; boolean food = false, runl = false, runr = true, runu = true, rund = true, bonusflag = true; Random r = new Random(); JMenuBar mymbar; JMenu game, help, level; public void initializeValues() { gu = 3; lbx[0] = 100; lby[0] = 150; directionx = 10; directiony = 0; difference = 0;
  • 8.
  • 9.
  • 10.
  • 11. score = 0; food = false; runl = false; runr = true; runu = true; rund = true; bonusflag = true; } Snake() { super("Snake"); setSize(500, 330); //Create Menue bar with functions creatbar(); //initialize all variables initializeValues(); // Start of UI design p1 = new JPanel(); p2 = new JPanel(); // t will view the score t = new JTextArea("Score ==>" + score); t.setEnabled(false); t.setBackground(Color.BLACK); // snake have to eat bonousfood to growup bonusfood =new JButton(); bonusfood.setEnabled(false); // will make first snake createFirstSnake(); p1.setLayout(null); p2.setLayout(new GridLayout(0, 1)); p1.setBounds(0, 0, x, y); p1.setBackground(Color.blue);
  • 12.
  • 13.
  • 14.
  • 15. p2.setBounds(0, y, x, 30); p2.setBackground(Color.RED); p2.add(t); // will contain score board // end of UI design getContentPane().setLayout(null); getContentPane().add(p1); getContentPane().add(p2); show(); setDefaultCloseOperation(EXIT_ON_CLOSE); addKeyListener(this); // start thread myt = new Thread(this); myt.start(); // go to run() method } public void createFirstSnake() { // Initially the snake has small length 3 for (int i = 0; i < 3; i++) { lb[i] = new JButton("lb" + i); lb[i].setEnabled(false); p1.add(lb[i]); lb[i].setBounds(lbx[i], lby[i], 10, 10); lbx[i + 1] = lbx[i] - 10; lby[i + 1] = lby[i]; } } public void creatbar() { mymbar = new JMenuBar();
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. game = new JMenu("Game"); JMenuItem newgame = new JMenuItem("New Game"); JMenuItem exit = new JMenuItem("Exit"); newgame.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { reset(); } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); game.add(newgame); game.addSeparator(); game.add(exit);
  • 21. mymbar.add(game); level = new JMenu("Level"); mymbar.add(level); help = new JMenu("Help");
  • 22.
  • 23.
  • 24.
  • 25. JMenuItem creator = new JMenuItem("Creator"); JMenuItem instruction = new JMenuItem("Instraction"); creator.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(p2, "Name :Abdullah al hasbnRollno :2006331093nSub :cseninstitute :sust"); } }); help.add(creator); help.add(instruction); mymbar.add(help); setJMenuBar(mymbar); } void reset() { initializeValues(); p1.removeAll(); myt.stop(); createFirstSnake(); t.setText("Score==>" + score); myt = new Thread(this); myt.start();
  • 27.
  • 28.
  • 29.
  • 30. lb[gu] = new JButton(); lb[gu].setEnabled(false); p1.add(lb[gu]); int a = 10 + (10 * r.nextInt(48)); int b = 10 + (10 * r.nextInt(23)); lbx[gu] = a; lby[gu] = b; lb[gu].setBounds(a,b, 10, 10); gu++; } // this method contains the logic to move the snake. player will define the derection // this method just forward the snake to the right derection which deriction is pressed // by the player. void moveForward() { for (int i = 0; i < gu; i++) { lbp[i] = lb[i].getLocation(); } lbx[0] += directionx; lby[0] += directiony; lb[0].setBounds(lbx[0], lby[0], 10, 10); for (int i = 1; i < gu; i++) { lb[i].setLocation(lbp[i - 1]); } if (lbx[0] == x) { lbx[0] = 10;
  • 31. } else if (lbx[0] == 0) { lbx[0] = x - 10;
  • 32.
  • 33.
  • 34.
  • 35. } else if (lby[0] == y) { lby[0] = 10; } else if (lby[0] == 0) { lby[0] = y - 10; } if (lbx[0] == lbx[gu - 1] && lby[0] == lby[gu - 1]) { food = false; score += 5; t.setText("Score==>" + score); if (score % 50 == 0 && bonusflag == true) { p1.add(bonusfood); bonusfood.setBounds((10* r.nextInt(50)), (10 * r.nextInt(25)), 15, 15); bfp = bonusfood.getLocation(); bonusflag = false; } } if (bonusflag == false) { if (bfp.x <= lbx[0] && bfp.y <= lby[0] && bfp.x + 10 >= lbx[0] && bfp.y + 10 >= lby[0]) { p1.remove(bonusfood); score += 100; t.setText("Score ==>" + score); bonusflag = true; } } if (food == false) { growup(); food = true; } else { lb[gu - 1].setBounds(lbx[gu - 1], lby[gu - 1], 10, 10); }
  • 36.
  • 37.
  • 38.
  • 39. for (int i = 1; i < gu; i++) { if (lbp[0] == lbp[i]) { t.setText("GAME OVER " + score); try { myt.join(); } catch (InterruptedException ie) { } break; } } p1.repaint(); show(); } public void keyPressed(KeyEvent e) { // snake move to left when player pressed left arrow if (runl == true && e.getKeyCode() == 37) { directionx = -10; // means snake move right to left by 10pixels directiony = 0; runr = false; // run right(runr) means snake cant move from left to right runu = true; // run up (runu) means snake can move from down to up rund = true; // run down (run down) means snake can move from up to down } // snake move to up when player pressed up arrow
  • 40. if (runu == true && e.getKeyCode() == 38) { directionx = 0; directiony = -10; // means snake move from down to up by 10 pixel rund = false; // run down (run down) means snake can move from up to down runr = true; // run right(runr) means snake can move from left to right runl = true; // run left (runl) means snake can move from right to left
  • 41.
  • 42.
  • 43.
  • 44. } // snake move to right when player pressed right arrow if (runr == true && e.getKeyCode() == 39) { directionx = +10; // means snake move from left to right by 10 pixel directiony = 0; runl = false; runu = true; rund = true; } // snake move to down when player pressed down arrow if (rund == true && e.getKeyCode() == 40) { directionx = 0; directiony = +10; // means snake move from left to right by 10 pixel runu = false; runr = true; runl = true; } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public void run() { for (;;) { // Move the snake move forword. In the start of the game snake move left to right, // if player press up, down, right or left arrow snake change its direction according to // pressed arrow moveForward(); try { Thread.sleep(speed);
  • 45.
  • 46.
  • 47. } catch (InterruptedException ie) { } } } } OUTPUT:-
  • 48.
  • 49. Conclusion:- The snake game in java is implemented and executed Successfully. I hereby thanks to to tanuja Rajput mam for her supportand guidance which helped us to complete this project.