Advance Java Project Report
Advance Java Project Report
Advance Java Project Report
PROJECT REPORT
“Ludo Game”
In the partial fulfilment for the requirement for the Diploma in
COMPUTER ENGINEERING
Submitted To
Mumbai
PROJECT TITLE
Ludo Game
“Ludo Game”
As Prescribed by MSBTE, Mumbai, as part of Syllabus for the Partial Fulfillment in Diploma in
Computer Technology for Academic year 2020-2021
2 Aims/Benefits 1
4 Literature Review 1
8 Application 29
MICRO PROJECT REPORT
Ludo Game
1.0 Rationale:-
Ludo is a strategy board game for two to four players, in which the players race their four
tokens from start to finish according to the rolls of a single die. Like other cross and circle
games, Ludo is derived from the Indian game Pachisi, but simpler. The game and its variations
are popular in many countries and under various names.
2.0 Aims/Benefits of the Micro-project:-
To make a Ludo Game using Advance Java Programming.
3.0 Course Outcomes Achieved:-
1) Develop Program using GUI Framework (AWT and Swing).
2) Handle events of AWT and Swing Components.
3) Develop Programs to handle events in java Programming.
4.0 Literature review:-
(INFORMATION DESCRIPTION)
1. Mouse Listener:-
The Java MouseListener is notified whenever you change the state of mouse. It is notified
against MouseEvent. The MouseListener interface is found in java.awt.event package. It has
five methods.
1) mouseClicked()
2) mouseEntered()
3) mouseExited()
4) mousePressed()
5) mouseReleased()
2. Mouse Motion Listener:-
The Java MouseMotionListener is notified whenever you move or drag mouse. It is
notified against MouseEvent. The MouseMotionListener interface is found in
java.awt.event package.
3. java.awt.event.*; :-
1
The java.awt.event package defines classes and interfaces used for event handling in
the AWT and Swing. The members of this package fall into three categories: Events. The
classes with names ending in "Event" represent specific types of events, generated by
the AWT or by one of the AWT or Swing components.
4. public void init():-
A method is a named group of Java statements that can be called. It is similar to a
subroutine or function in other programming languages. The term init () is a method name
in Java. The name is followed by Java code within {and}.
5. Graph classes (graph):-
Java implementation of the same is here on my blog. The Graph class represents an
undirected graph of vertices named 0 through V - 1. It supports the following two primary
operations: add an edge to the graph, iterate over all of the vertices adjacent to a vertex.
5.0 Actual Methodology followed:-
We develop a project on Ludo Game under the subject Advance JAVA Programming. We
make this projects for user entertainment purpose. We start the program code with the used
of import java.awt.event.* of this java package. Also we get the used from
getImage(getCodeBase()) of this function in our Ludo Game program. For some condition
expressions we used if else statement in our program. Also we used the Boolean expressions
in our Ludo Game program. Ludo Game is a single and multiplayer based game, in this Game
2-4 players can play this game. In this game only player can play this game?
5.0 Actual Resources used:-
Hardware Requirements:-
2
Software Requirements:-
CODE:-
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
boolean playerturn;
boolean oneturn;
boolean twoturn;
boolean gameWon;
boolean counterMoved;
boolean Pressed;
Image img, img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12,
img13, img14, img15, img16, img17, img18, img19, img20, img21, img22, img23, img24,
img25, img26;
3
public void init()
{
setSize(700,700);
fillarray();
playerone[0][2] = 1;
playertwo[0][2] = 1;
playerthree[0][2] = 1;
playerfour[0][2] = 1;
Counter = 0;
addMouseListener(this);
winner = 0;
counterMoved = true;
Pressed = false;
picNumber = 0;
}
4
img24 = getImage(getCodeBase(), "yellow roll.JPG");
img25 = getImage(getCodeBase(), "green roll.JPG");
img26 = getImage(getCodeBase(), "blue roll.JPG");
if(gameWon == false)
{
graf.drawImage(img6, 450, 100, this);
}
if(counterMoved == false)
{
graf.drawImage(img8, 400, 400, this);
}
if(picNumber == 1)
{
graf.drawImage(img8, 400, 400, this);
}
if(picNumber == 2)
{
graf.drawImage(img24, 400, 400, this);
}
if(picNumber == 3)
{
5
graf.drawImage(img25, 400, 400, this);
}
if(picNumber == 4)
{
graf.drawImage(img26, 400, 400, this);
}
if(playertwo[i][2] == 1)
{
graf.setColor(Color.yellow);
graf.fillOval(playertwo[i][0] + 10, playertwo[i][1] + 10,30,30);
}
if(playerthree[i][2] == 1)
{
graf.setColor(Color.green);
graf.fillOval(playerthree[i][0] + 10, playerthree[i][1] + 10,30,30);
}
if(playerfour[i][2] == 1)
{
graf.setColor(Color.blue);
graf.fillOval(playerfour[i][0] + 10, playerfour[i][1] + 10,30,30);
}
}
6
graf.fillOval(298, 298,30,30);
}
if(playertwo[44][2] == 1)
{
graf.setColor(Color.yellow);
graf.fillOval(298, 322,30,30);
}
if(playerthree[44][2] == 1)
{
graf.setColor(Color.green);
graf.fillOval(322, 322,30,30);
}
if(playerfour[44][2] == 1)
{
graf.setColor(Color.blue);
graf.fillOval(322, 298,30,30);
}
7
//---------------------- display winner --------------------------
if(winner == 1 & counterMoved == true)
{
graf.drawImage(img16, 50, 425, this);
}
if(winner == 2)
{
graf.drawImage(img17, 50, 425, this);
}
if(winner == 3)
{
graf.drawImage(img18, 50, 425, this);
}
if(winner == 4)
{
graf.drawImage(img19, 50, 425, this);
}
8
playerthree[i+20][0] = xCoord;
playerthree[i+20][1] = yCoord;
playerfour[i+30][0] = xCoord;
playerfour[i+30][1] = yCoord;
xCoord = xCoord + 50;
}
playerone[9][0] = 300;
playertwo[19][0] = 300;
playerthree[29][0] = 300;
playerfour[39][0] = 300;
playerone[9][1] = 50;
playertwo[19][1] = 50;
playerthree[29][1] = 50;
playerfour[39][1] = 50;
yCoord = 50;
xCoord = 350;
for(int i=10; i<=14; i++)
{
playerone[i][0] = xCoord;
playerone[i][1] = yCoord;
playertwo[i+10][0] = xCoord;
playertwo[i+10][1] = yCoord;
playerthree[i+20][0] = xCoord;
playerthree[i+20][1] = yCoord;
playerfour[i-10][0] = xCoord;
playerfour[i-10][1] = yCoord;
9
yCoord = yCoord + 50;
}
yCoord = 250;
xCoord = 400;
for(int i=15; i<=18; i++)
{
playerone[i][0] = xCoord;
playerone[i][1] = yCoord;
playertwo[i+10][0] = xCoord;
playertwo[i+10][1] = yCoord;
playerthree[i+20][0] = xCoord;
playerthree[i+20][1] = yCoord;
playerfour[i-10][0] = xCoord;
playerfour[i-10][1] = yCoord;
xCoord = xCoord + 50;
}
playerone[19][0] = 550;
playertwo[29][0] = 550;
playerthree[39][0] = 550;
playerfour[9][0] = 550;
playerone[19][1] = 300;
playertwo[29][1] = 300;
playerthree[39][1] = 300;
playerfour[9][1] = 300;
xCoord = 550;
yCoord = 350;
for(int i=20; i<=24; i++)
{
playerone[i][0] = xCoord;
playerone[i][1] = yCoord;
playertwo[i+10][0] = xCoord;
playertwo[i+10][1] = yCoord;
playerthree[i-20][0] = xCoord;
playerthree[i-20][1] = yCoord;
playerfour[i-10][0] = xCoord;
playerfour[i-10][1] = yCoord;
xCoord = xCoord - 50;
}
xCoord = 350;
10
yCoord = 400;
for(int i=25; i<=28; i++)
{
playerone[i][0] = xCoord;
playerone[i][1] = yCoord;
playertwo[i+10][0] = xCoord;
playertwo[i+10][1] = yCoord;
playerthree[i-20][0] = xCoord;
playerthree[i-20][1] = yCoord;
playerfour[i-10][0] = xCoord;
playerfour[i-10][1] = yCoord;
yCoord = yCoord + 50;
}
playerone[29][0] = 300;
playertwo[39][0] = 300;
playerthree[9][0] = 300;
playerfour[19][0] = 300;
playerone[29][1] = 550;
playertwo[39][1] = 550;
playerthree[9][1] = 550;
playerfour[19][1] = 550;
xCoord = 250;
yCoord = 550;
for(int i=30; i<=34; i++)
{
playerone[i][0] = xCoord;
playerone[i][1] = yCoord;
playertwo[i-30][0] = xCoord;
playertwo[i-30][1] = yCoord;
playerthree[i-20][0] = xCoord;
playerthree[i-20][1] = yCoord;
playerfour[i-10][0] = xCoord;
playerfour[i-10][1] = yCoord;
yCoord = yCoord - 50;
}
xCoord = 200;
yCoord = 350;
for(int i=35; i<=38; i++)
{
playerone[i][0] = xCoord;
11
playerone[i][1] = yCoord;
playertwo[i-30][0] = xCoord;
playertwo[i-30][1] = yCoord;
playerthree[i-20][0] = xCoord;
playerthree[i-20][1] = yCoord;
playerfour[i-10][0] = xCoord;
playerfour[i-10][1] = yCoord;
xCoord = xCoord - 50;
}
playerone[39][0] = 50;
playertwo[9][0] = 50;
playerthree[19][0] = 50;
playerfour[29][0] = 50;
playerone[39][1] = 300;
playertwo[9][1] = 300;
playerthree[19][1] = 300;
playerfour[29][1] = 300;
xCoord = 100;
yCoord = 300;
for(int i=40; i<=44; i++)
{
playerone[i][0] = xCoord;
playerone[i][1] = yCoord;
xCoord = xCoord + 50;
}
xCoord = 300;
yCoord = 500;
for(int i=40; i<=44; i++)
{
playertwo[i][0] = xCoord;
playertwo[i][1] = yCoord;
yCoord = yCoord - 50;
}
xCoord = 500;
yCoord = 300;
for(int i=40; i<=44; i++)
{
playerthree[i][0] = xCoord;
playerthree[i][1] = yCoord;
12
xCoord = xCoord - 50;
}
xCoord = 300;
yCoord = 100;
for(int i=40; i<=44; i++)
{
playerfour[i][0] = xCoord;
playerfour[i][1] = yCoord;
yCoord = yCoord + 50;
}
13
public void mouseEntered(MouseEvent e)
{
}
14
if (roll<6)
{
playerone[39][2] = 0;
playerone[39+roll][2] = 1;
if(gameWon == false)
{
counterMoved = false;
}
}
oneturn = false;
}
else
if (playerone[40][2] == 1 & oneturn == true)
{
if (roll<5)
{
playerone[40][2] = 0;
playerone[40+roll][2] = 1;
if(gameWon == false)
{
counterMoved = false;
}
}
oneturn = false;
}
else
if (playerone[41][2] == 1 & oneturn == true)
{
if (roll<4)
{
playerone[41][2] = 0;
playerone[41+roll][2] = 1;
if(gameWon == false)
{
counterMoved = false;
}
}
oneturn = false;
}
else
if (playerone[42][2] == 1 & oneturn == true)
{
if (roll<3)
15
{
playerone[42][2] = 0;
playerone[42+roll][2] = 1;
if(gameWon == false)
{
counterMoved = false;
}
}
oneturn = false;
}
else
if (playerone[43][2] == 1 & oneturn == true)
{
if (roll<2)
{
playerone[43][2] = 0;
playerone[43+roll][2] = 1;
if(gameWon == false)
{
counterMoved = false;
}
}
oneturn = false;
}
else
if (playerone[44][2] == 1 & oneturn == true)
{
oneturn = false;
}
}
if(oneturn == true)
{
for(int i=43; i>=0; i--)
{
if (playerone[i][2] == 1)
{
playerone[i][2] = 0;
playerone[i+roll][2] = 1;
if(gameWon == false)
{
counterMoved = false;
}
}
16
}
}
17
if (playertwo[40][2] == 1 & oneturn == true)
{
if (roll<5)
{
playertwo[40][2] = 0;
playertwo[40+roll][2] = 1;
}
oneturn = false;
}
else
if (playertwo[41][2] == 1 & oneturn == true)
{
if (roll<4)
{
playertwo[41][2] = 0;
playertwo[41+roll][2] = 1;
}
oneturn = false;
}
else
if (playertwo[42][2] == 1 & oneturn == true)
{
if (roll<3)
{
playertwo[42][2] = 0;
playertwo[42+roll][2] = 1;
}
oneturn = false;
}
else
if (playertwo[43][2] == 1 & oneturn == true)
{
if (roll<2)
{
playertwo[43][2] = 0;
playertwo[43+roll][2] = 1;
}
oneturn = false;
}
else
if (playertwo[44][2] == 1 & oneturn == true)
{
oneturn = false;
18
}
}
if(oneturn == true)
{
for(int i=43; i>=0; i--)
{
if (playertwo[i][2] == 1)
{
playertwo[i][2] = 0;
playertwo[i+roll][2] = 1;
}
}
19
if(playertwo[i][0] == playerfour[j][0] & playertwo[i][1] == playerfour[j][1])
{
playerfour[j][2] = 0;
playerfour[0][2] = 1;
}
}
}
}
}
}
Counter = 2;
if(playerthree[44][2] == 1)
{
Counter = 3;
}
if(playerthree[44][2] == 1 & playerfour[44][2] == 1)
{
Counter = 0;
}
if(playerthree[44][2] == 1 & playerfour[44][2] == 1 & playerone[44][2] == 1)
{
Counter = 1;
if(playertwo[44][2] == 1)
{
if(playerthree[44][2] != 1)
{
Counter = 2;
}
else
if(playerfour[44][2] != 1)
{
Counter = 3;
}
else
Counter = 0;
}
}
}
else
if(Counter == 2)
{
roll = 1 + (int)(Math.random() * 6);
20
picNumber = 3;
oneturn = true;
for(int i=39; i<45; i++)
{
if (playerthree[39][2] == 1 & oneturn == true)
{
if (roll<6)
{
playerthree[39][2] = 0;
playerthree[39+roll][2] = 1;
}
oneturn = false;
}
else
if (playerthree[40][2] == 1 & oneturn == true)
{
if (roll<5)
{
playerthree[40][2] = 0;
playerthree[40+roll][2] = 1;
}
oneturn = false;
}
else
if (playerthree[41][2] == 1 & oneturn == true)
{
if (roll<4)
{
playerthree[41][2] = 0;
playerthree[41+roll][2] = 1;
}
oneturn = false;
}
else
if (playerthree[42][2] == 1 & oneturn == true)
{
if (roll<3)
{
playerthree[42][2] = 0;
playerthree[42+roll][2] = 1;
}
oneturn = false;
}
21
else
if (playerthree[43][2] == 1 & oneturn == true)
{
if (roll<2)
{
playerthree[43][2] = 0;
playerthree[43+roll][2] = 1;
}
oneturn = false;
}
else
if (playerthree[44][2] == 1 & oneturn == true)
{
oneturn = false;
}
}
if(oneturn == true)
{
for(int i=43; i>=0; i--)
{
if (playerthree[i][2] == 1)
{
playerthree[i][2] = 0;
playerthree[i+roll][2] = 1;
}
}
22
{
if(playerone[j][2] == 1)
{
if(playerthree[i][0] == playerone[j][0] & playerthree[i][1] == playerone[j][1])
{
playerone[j][2] = 0;
playerone[0][2] = 1;
}
}
}
for(int j=0; j<playerfour.length; j++)
{
if(playerfour[j][2] == 1)
{
if(playerthree[i][0] == playerfour[j][0] & playerthree[i][1] == playerfour[j][1])
{
playerfour[j][2] = 0;
playerfour[0][2] = 1;
}
}
}
}
}
}
Counter = 3;
if(playerfour[44][2] == 1)
{
Counter = 0;
}
if(playerfour[44][2] == 1 & playerone[44][2] == 1)
{
Counter = 1;
}
if(playerfour[44][2] == 1 & playerone[44][2] == 1 & playertwo[44][2] == 1)
{
Counter = 2;
}
}
else
if(Counter == 3)
{
23
roll = 1 + (int)(Math.random() * 6);
picNumber = 4;
oneturn = true;
for(int i=39; i<45; i++)
{
if (playerfour[39][2] == 1 & oneturn == true)
{
if (roll<6)
{
playerfour[39][2] = 0;
playerfour[39+roll][2] = 1;
}
oneturn = false;
}
else
if (playerfour[40][2] == 1 & oneturn == true)
{
if (roll<5)
{
playerfour[40][2] = 0;
playerfour[40+roll][2] = 1;
}
oneturn = false;
}
else
if (playerfour[41][2] == 1 & oneturn == true)
{
if (roll<4)
{
playerfour[41][2] = 0;
playerfour[41+roll][2] = 1;
}
oneturn = false;
}
else
if (playerfour[42][2] == 1 & oneturn == true)
{
if (roll<3)
{
playerfour[42][2] = 0;
playerfour[42+roll][2] = 1;
}
oneturn = false;
24
}
else
if (playerfour[43][2] == 1 & oneturn == true)
{
if (roll<2)
{
playerfour[43][2] = 0;
playerfour[43+roll][2] = 1;
}
oneturn = false;
}
else
if (playerfour[44][2] == 1 & oneturn == true)
{
oneturn = false;
}
}
if(oneturn == true)
{
for(int i=43; i>=0; i--)
{
if (playerfour[i][2] == 1)
{
playerfour[i][2] = 0;
playerfour[i+roll][2] = 1;
}
}
25
for(int j=0; j<playerthree.length; j++)
{
if(playerthree[j][2] == 1)
{
if(playerfour[i][0] == playerthree[j][0] & playerfour[i][1] == playerthree[j][1])
{
playerthree[j][2] = 0;
playerthree[0][2] = 1;
}
}
}
for(int j=0; j<playerone.length; j++)
{
if(playerone[j][2] == 1)
{
if(playerfour[i][0] == playerone[j][0] & playerfour[i][1] == playerone[j][1])
{
playerone[j][2] = 0;
playerone[0][2] = 1;
}
}
}
}
}
}
Counter = 0;
if(playerone[44][2] == 1)
{
Counter = 1;
}
if(playerone[44][2] == 1 & playertwo[44][2] == 1)
{
Counter = 2;
}
if(playerone[44][2] == 1 & playertwo[44][2] == 1 & playerthree[44][2] == 1)
{
Counter = 3;
}
}
}
if(Counter == 5)
26
{
for(int i=0; i<playerone.length; i++)
{
if(playerone[i][3] == 1)
{
if(xPos >= playerone[i][0] & xPos <= playerone[i][0]+50 & yPos >= playerone[i][1] & yPos <=
playerone[i][1]+50)
{
Pressed = true;
}
}
if(playerone[i][2] == 1)
{
if(XPos >= playerone[i][0] & XPos <= playerone[i][0]+50 & YPos >= playerone[i][1] & YPos
<= playerone[i][1]+50)
{
counterMoved = true;
Pressed = false;
Counter = 1;
}
27
}
}
for(int j=0; j<44; j++)
{
if(playerfour[j][2] == 1)
{
if(playerone[i][0] == playerfour[j][0] & playerone[i][1] == playerfour[j][1])
{
playerfour[j][2] = 0;
playerfour[0][2] = 1;
}
}
}
}
}
}
28
}
}
From this project we learn the Mouse Listener, Mouse Motion Listener.
The demo is made more interactive with a mouse interaction module in the program.
29