SlideShare a Scribd company logo
1 of 34
Download to read offline
12/1/2013

Rashidul Islam
No

Description

Page

Task 1

a)

The application that I produce

1

Task 2
a)

Screen shots

25

Task 3
a)

Class diagrams

Rashidul Islam

30
Task 1:
The application that I have created:
a) Class - SuitableLocation.java:

---------------------------------------------------------------------------

Rashidul Islam
1.) Documentation:

Constructor Summary
SuitableLocation(int i, int j)

b) Class - Crate.java:

---------------------------------------------------------------------------

Rashidul Islam
1.) Documentation:
Constructor Summary
Crate(int i, int j)

c) Class - PlayerCharacter.java:

---------------------------------------------------------------------------

Rashidul Islam
1.) Documentation:

sokobangame
Class PlayerCharacter
java.lang.Object
sokobangame.User
sokobangame.PlayerCharacter
public class PlayerCharacterextends sokobangame.User
Constructor Summary
PlayerCharacter(int i, int j)

Rashidul Islam
d) Class - Obstacle.java:

---------------------------------------------------------------------------

1.) Documentation:

Constructor Summary
Obstacle(int i, int j)

Rashidul Islam
e) Class - User.java:

Rashidul Islam
Rashidul Islam
---------------------------------------------------------------------------

1.) Documentation:

Constructor Summary
User(int x, int y)

---------------------------------------------------------------------------------------------f) Class - Panel.java:
--------------------------------------------------------------------------package sokobangame;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
/**import java.awt.event.ActionEvent;*/
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JPanel;
/**
*
*
* @author (Md. Rashidul Islam)
* @version ()
*/

Rashidul Islam
public class Panel extends JPanel {
/**

*
*/
// instance variables
//Attributes: instance variables of an object

/**
* Constructor for objects of class Panel
*/
private static final long serialVersionUID = 1L;
private final int OFFSET = 30;
private JButton btn1; /*type: JButton, variable: btn1 */
private JButton btn2;
private JButton btn3;
private JButton btn4;
private JButton btn5;
private JButton btn6;
private JButton btn7;
//private JButton btnQuit;
private final int SPACE = 20;
private final int LEFT_COLLISION = 1;
private final int RIGHT_COLLISION = 2;
private final int TOP_COLLISION = 3;
private final int BOTTOM_COLLISION = 4;
private ArrayList<Obstacle> obs = new ArrayList<Obstacle>();
private ArrayList<Crate> crates = new ArrayList<Crate>();

Rashidul Islam
private ArrayList<SuitableLocation> SuitLo = new
ArrayList<SuitableLocation>();
private PlayerCharacter PlayerChar;
private int w = 0;
private int h = 0;
private boolean solved = false;
private String stage =
" ######n"
+ " ## #n"
+ " ##$ #n"
+ " #### $##n"
+ " ## $ $ #n"
+ "#### # ## # ######n"
+ "## # ## ##### ..#n"
+ "## $ $
..#n"
+ "###### ### #@## ..#n"
+ " ## #########n"
+ " ########n";
public Panel() {
// initialise instance variables
addKeyListener(new TAdapter());
setFocusable(true);
initWorld();
}
/**

*/
public int getBoardWidth() {
return this.w;
}
public int getBoardHeight() {
return this.h;
}

Rashidul Islam
public final void initWorld() {
btn1 = new JButton("Level 1");
btn1.setBounds(10000, 1000, 200, 50);
this.add(btn1);
Font f = new Font("Courier New",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn1.setFont(f);
btn2 = new JButton("Level 2");
btn2.setBounds(10000, 1055, 200, 50);
this.add(btn2);
Font g = new Font("Monospaced",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn2.setFont(g);
btn3 = new JButton("Level 3");
btn3.setBounds(10000, 1110, 200, 50);
this.add(btn3);
Font n = new Font("Monospaced",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn3.setFont(n);
btn4 = new JButton("Level 4");
btn4.setBounds(500, 1165, 200, 50);
this.add(btn4);
Font m = new Font("Monospaced",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn4.setFont(m);
btn5 = new JButton("Level 5");
btn5.setBounds(500, 1220, 200, 50);
this.add(btn5);
Font j = new Font("Monospaced",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn5.setFont(j);
btn6 = new JButton("Steps");

Rashidul Islam
btn6.setBounds(500, 1275, 200, 50);
this.add(btn6);
Font k = new Font("Courier New",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn6.setFont(k);
btn7 = new JButton("Exit");
btn7.setBounds(500, 1330, 200, 50);
this.add(btn7);
Font l = new Font("Courier New",
Font.LAYOUT_LEFT_TO_RIGHT,24);
btn7.setFont(l);
/**btnQuit = new JButton("Quit");
btnQuit.setBounds(440, 380, 100, 50);
btnQuit.setFont(f);
btnQuit.addActionListener(this);
this.add(btnQuit);
this.setVisible(true);*/

}*/

/**public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnQuit)
System.exit(0);

int x = OFFSET;
int y = OFFSET;
Obstacle wall;
Crate b;
SuitableLocation a;
for (int i = 0; i < stage.length(); i++) {
char item = stage.charAt(i);
if (item == 'n') {

Rashidul Islam
y += SPACE;
if (this.w < x) {
this.w = x;
}
x = OFFSET;
} else if (item == '#') {
wall = new Obstacle(x, y);
obs.add(wall);
x += SPACE;
} else if (item == '$') {
b = new Crate(x, y);
crates.add(b);
x += SPACE;
} else if (item == '.') {
a = new SuitableLocation(x, y);
SuitLo.add(a);
x += SPACE;
} else if (item == '@') {
PlayerChar = new PlayerCharacter(x, y);
x += SPACE;
} else if (item == ' ') {
x += SPACE;
}

}

}

h = y;

public void buildWorld(Graphics g) {
g.setColor(new Color(0, 108, 209));
g.fillRect(0, 0, this.getWidth(), this.getHeight());
ArrayList<User> world = new ArrayList<User>();
world.addAll(obs);
world.addAll(SuitLo);
world.addAll(crates);
world.add(PlayerChar);

Rashidul Islam
for (int i = 0; i < world.size(); i++) {
User item = (User) world.get(i);
if ((item instanceof PlayerCharacter)
|| (item instanceof Crate)) {
g.drawImage(item.getImage(), item.x() + 2, item.y() + 2, this);
} else {
g.drawImage(item.getImage(), item.x(), item.y(), this);
}
if (solved) {
g.setColor(new Color(255,255,255));
g.drawString("The level has been solved!", 25, 20);
Font f = new Font("Courier New", Font.BOLD,14);
setFont(f);
}
}

}

@Override
public void paint(Graphics g) {
super.paint(g);
buildWorld(g);
}
class TAdapter extends KeyAdapter {
@Override
public void keyPressed(KeyEvent e) {
if (solved) {
return;
}
int key = e.getKeyCode();

Rashidul Islam
if (key == KeyEvent.VK_LEFT) {
if (checkWallCollision(PlayerChar,
LEFT_COLLISION)) {
return;
}
if (checkBagCollision(LEFT_COLLISION)) {
return;
}
PlayerChar.move(-SPACE, 0);
} else if (key == KeyEvent.VK_RIGHT) {
if (checkWallCollision(PlayerChar,
RIGHT_COLLISION)) {
return;
}
if (checkBagCollision(RIGHT_COLLISION)) {
return;
}
PlayerChar.move(SPACE, 0);
} else if (key == KeyEvent.VK_UP) {
if (checkWallCollision(PlayerChar,
TOP_COLLISION)) {
return;
}
if (checkBagCollision(TOP_COLLISION)) {
return;
}
PlayerChar.move(0, -SPACE);

Rashidul Islam
} else if (key == KeyEvent.VK_DOWN) {
if (checkWallCollision(PlayerChar,
BOTTOM_COLLISION)) {
return;
}
if (checkBagCollision(BOTTOM_COLLISION)) {
return;
}
PlayerChar.move(0, SPACE);
} else if (key == KeyEvent.VK_R) {
restartStage();
}

}

}

repaint();

private boolean checkWallCollision(User actor, int type) {
if (type == LEFT_COLLISION) {
for (int i = 0; i < obs.size(); i++) {
Obstacle wall = (Obstacle) obs.get(i);
if (actor.isLeftCollision(wall)) {
return true;
}
}
return false;
} else if (type == RIGHT_COLLISION) {
for (int i = 0; i < obs.size(); i++) {
Obstacle wall = (Obstacle) obs.get(i);
if (actor.isRightCollision(wall)) {

Rashidul Islam
}

return true;

}
return false;
} else if (type == TOP_COLLISION) {
for (int i = 0; i < obs.size(); i++) {
Obstacle wall = (Obstacle) obs.get(i);
if (actor.isTopCollision(wall)) {
return true;
}
}
return false;
} else if (type == BOTTOM_COLLISION) {
for (int i = 0; i < obs.size(); i++) {
Obstacle wall = (Obstacle) obs.get(i);
if (actor.isBottomCollision(wall)) {
return true;
}
}
return false;

}

}
return false;

private boolean checkBagCollision(int type) {
if (type == LEFT_COLLISION) {
for (int i = 0; i < crates.size(); i++) {
Crate bag = (Crate) crates.get(i);
if (PlayerChar.isLeftCollision(bag)) {
for (int j=0; j < crates.size(); j++) {
Crate item = (Crate) crates.get(j);

Rashidul Islam
if (!bag.equals(item)) {
if (bag.isLeftCollision(item)) {
return true;
}
}
if (checkWallCollision(bag,
LEFT_COLLISION)) {
return true;
}

}

}
bag.move(-SPACE, 0);
isSolved();

}
return false;
} else if (type == RIGHT_COLLISION) {
for (int i = 0; i < crates.size(); i++) {
Crate bag = (Crate) crates.get(i);
if (PlayerChar.isRightCollision(bag)) {
for (int j=0; j < crates.size(); j++) {
Crate item = (Crate) crates.get(j);
if (!bag.equals(item)) {
if (bag.isRightCollision(item)) {
return true;
}
}
if (checkWallCollision(bag,
RIGHT_COLLISION)) {
return true;
}

}

}

}
bag.move(SPACE, 0);
isSolved();

Rashidul Islam
return false;
} else if (type == TOP_COLLISION) {
for (int i = 0; i < crates.size(); i++) {
Crate bag = (Crate) crates.get(i);
if (PlayerChar.isTopCollision(bag)) {
for (int j = 0; j < crates.size(); j++) {
Crate item = (Crate) crates.get(j);
if (!bag.equals(item)) {
if (bag.isTopCollision(item)) {
return true;
}
}
if (checkWallCollision(bag,
TOP_COLLISION)) {
return true;
}

}

}

}
bag.move(0, -SPACE);
isSolved();

return false;
} else if (type == BOTTOM_COLLISION) {
for (int i = 0; i < crates.size(); i++) {
Crate bag = (Crate) crates.get(i);
if (PlayerChar.isBottomCollision(bag)) {
for (int j = 0; j < crates.size(); j++) {
Crate item = (Crate) crates.get(j);
if (!bag.equals(item)) {
if (bag.isBottomCollision(item)) {

Rashidul Islam
}

return true;

}
if (checkWallCollision(bag,
BOTTOM_COLLISION)) {
return true;
}

}
}

}

}

}
bag.move(0, SPACE);
isSolved();

return false;

public void isSolved() {
int num = crates.size();
int compl = 0;
for (int i = 0; i < num; i++) {
Crate bag = (Crate) crates.get(i);
for (int j = 0; j < num; j++) {
SuitableLocation area = (SuitableLocation) SuitLo.get(j);
if (bag.x() == area.x()
&& bag.y() == area.y()) {
compl += 1;
}
}
}

}

if (compl == num) {
solved = true;
repaint();
}

Rashidul Islam
public void restartStage() {

}

}

SuitLo.clear();
crates.clear();
obs.clear();
initWorld();
if (solved) {
solved = false;
}

1.) Documentation:

Constructor Summary
Panel()

g) Class - Game.java:
---------------------------------------------------------------------------

Rashidul Islam
Rashidul Islam
---------------------------------------------------------------------------

1.) Documentation:

Constructor Summary
Game()
private JButton btn1; private JButton btn2; private JButton btn3;
private JButton btn4; private JButton btn5; private JButton btn6; private
JButton btn7;
---------------------------------------------------------------------------

Task 2:

Screen shots:

a) Level-1:

Fig: starting position

Rashidul Islam
Fig: Level Solved

b) Level-2:

Fig: starting position

Rashidul Islam
Fig: level solved

b) Level-3:

Fig: starting position

Rashidul Islam
Fig: level solved

c) Level-4:

Fig: starting position

Rashidul Islam
Fig: level solved

d) Level-5:

Fig: starting position

Rashidul Islam
Fig: starting position with buttons

---------------------------------------------------------------------------

Task 3:
Class diagrams:
a) Class Diagram:
i)

Class Diagram or Design In UML Using StarUML:

Fig: Level 1

Rashidul Islam
Fig: Level One

Rashidul Islam
ii)

Testing Data By BlueJ:

Fig : Testing Data By BlueJ

Rashidul Islam
Rashidul Islam
Rashidul Islam

More Related Content

Viewers also liked

How to find a solution
How to find a solutionHow to find a solution
How to find a solutionskku_npc
 
5장 그래프의 비밀 (Programming Game AI by Example)
5장 그래프의 비밀 (Programming Game AI by Example)5장 그래프의 비밀 (Programming Game AI by Example)
5장 그래프의 비밀 (Programming Game AI by Example)hyun soomyung
 
Game AI Overview
Game AI OverviewGame AI Overview
Game AI Overview기룡 남
 
[0122 구경원]게임에서의 충돌처리
[0122 구경원]게임에서의 충돌처리[0122 구경원]게임에서의 충돌처리
[0122 구경원]게임에서의 충돌처리KyeongWon Koo
 
테스트 케이스와 SW 품질
테스트 케이스와 SW 품질테스트 케이스와 SW 품질
테스트 케이스와 SW 품질도형 임
 
Step by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's CubeStep by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's CubeKush2K
 
Ai 그까이거
Ai 그까이거Ai 그까이거
Ai 그까이거도형 임
 

Viewers also liked (9)

How to find a solution
How to find a solutionHow to find a solution
How to find a solution
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
5장 그래프의 비밀 (Programming Game AI by Example)
5장 그래프의 비밀 (Programming Game AI by Example)5장 그래프의 비밀 (Programming Game AI by Example)
5장 그래프의 비밀 (Programming Game AI by Example)
 
Game AI Overview
Game AI OverviewGame AI Overview
Game AI Overview
 
[0122 구경원]게임에서의 충돌처리
[0122 구경원]게임에서의 충돌처리[0122 구경원]게임에서의 충돌처리
[0122 구경원]게임에서의 충돌처리
 
테스트 케이스와 SW 품질
테스트 케이스와 SW 품질테스트 케이스와 SW 품질
테스트 케이스와 SW 품질
 
Step by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's CubeStep by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's Cube
 
Chapter 2 (final)
Chapter 2 (final)Chapter 2 (final)
Chapter 2 (final)
 
Ai 그까이거
Ai 그까이거Ai 그까이거
Ai 그까이거
 

Similar to Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagrams )

Creating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdfCreating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdfShaiAlmog1
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfapexcomputer54
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
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
 
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
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfcalderoncasto9163
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision DetectionJenchoke Tachagomain
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2MEJenchoke Tachagomain
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptSaadAsim11
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfanjandavid
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfarmcomputers
 

Similar to Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagrams ) (20)

662305 11
662305 11662305 11
662305 11
 
Creating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdfCreating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdf
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
 
J slider
J sliderJ slider
J slider
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.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
 
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
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
Clock For My
Clock For MyClock For My
Clock For My
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 

Recently uploaded

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagrams )

  • 2. No Description Page Task 1 a) The application that I produce 1 Task 2 a) Screen shots 25 Task 3 a) Class diagrams Rashidul Islam 30
  • 3. Task 1: The application that I have created: a) Class - SuitableLocation.java: --------------------------------------------------------------------------- Rashidul Islam
  • 4. 1.) Documentation: Constructor Summary SuitableLocation(int i, int j) b) Class - Crate.java: --------------------------------------------------------------------------- Rashidul Islam
  • 5. 1.) Documentation: Constructor Summary Crate(int i, int j) c) Class - PlayerCharacter.java: --------------------------------------------------------------------------- Rashidul Islam
  • 6. 1.) Documentation: sokobangame Class PlayerCharacter java.lang.Object sokobangame.User sokobangame.PlayerCharacter public class PlayerCharacterextends sokobangame.User Constructor Summary PlayerCharacter(int i, int j) Rashidul Islam
  • 7. d) Class - Obstacle.java: --------------------------------------------------------------------------- 1.) Documentation: Constructor Summary Obstacle(int i, int j) Rashidul Islam
  • 8. e) Class - User.java: Rashidul Islam
  • 10. --------------------------------------------------------------------------- 1.) Documentation: Constructor Summary User(int x, int y) ---------------------------------------------------------------------------------------------f) Class - Panel.java: --------------------------------------------------------------------------package sokobangame; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; /**import java.awt.event.ActionEvent;*/ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JPanel; /** * * * @author (Md. Rashidul Islam) * @version () */ Rashidul Islam
  • 11. public class Panel extends JPanel { /** * */ // instance variables //Attributes: instance variables of an object /** * Constructor for objects of class Panel */ private static final long serialVersionUID = 1L; private final int OFFSET = 30; private JButton btn1; /*type: JButton, variable: btn1 */ private JButton btn2; private JButton btn3; private JButton btn4; private JButton btn5; private JButton btn6; private JButton btn7; //private JButton btnQuit; private final int SPACE = 20; private final int LEFT_COLLISION = 1; private final int RIGHT_COLLISION = 2; private final int TOP_COLLISION = 3; private final int BOTTOM_COLLISION = 4; private ArrayList<Obstacle> obs = new ArrayList<Obstacle>(); private ArrayList<Crate> crates = new ArrayList<Crate>(); Rashidul Islam
  • 12. private ArrayList<SuitableLocation> SuitLo = new ArrayList<SuitableLocation>(); private PlayerCharacter PlayerChar; private int w = 0; private int h = 0; private boolean solved = false; private String stage = " ######n" + " ## #n" + " ##$ #n" + " #### $##n" + " ## $ $ #n" + "#### # ## # ######n" + "## # ## ##### ..#n" + "## $ $ ..#n" + "###### ### #@## ..#n" + " ## #########n" + " ########n"; public Panel() { // initialise instance variables addKeyListener(new TAdapter()); setFocusable(true); initWorld(); } /** */ public int getBoardWidth() { return this.w; } public int getBoardHeight() { return this.h; } Rashidul Islam
  • 13. public final void initWorld() { btn1 = new JButton("Level 1"); btn1.setBounds(10000, 1000, 200, 50); this.add(btn1); Font f = new Font("Courier New", Font.LAYOUT_LEFT_TO_RIGHT,24); btn1.setFont(f); btn2 = new JButton("Level 2"); btn2.setBounds(10000, 1055, 200, 50); this.add(btn2); Font g = new Font("Monospaced", Font.LAYOUT_LEFT_TO_RIGHT,24); btn2.setFont(g); btn3 = new JButton("Level 3"); btn3.setBounds(10000, 1110, 200, 50); this.add(btn3); Font n = new Font("Monospaced", Font.LAYOUT_LEFT_TO_RIGHT,24); btn3.setFont(n); btn4 = new JButton("Level 4"); btn4.setBounds(500, 1165, 200, 50); this.add(btn4); Font m = new Font("Monospaced", Font.LAYOUT_LEFT_TO_RIGHT,24); btn4.setFont(m); btn5 = new JButton("Level 5"); btn5.setBounds(500, 1220, 200, 50); this.add(btn5); Font j = new Font("Monospaced", Font.LAYOUT_LEFT_TO_RIGHT,24); btn5.setFont(j); btn6 = new JButton("Steps"); Rashidul Islam
  • 14. btn6.setBounds(500, 1275, 200, 50); this.add(btn6); Font k = new Font("Courier New", Font.LAYOUT_LEFT_TO_RIGHT,24); btn6.setFont(k); btn7 = new JButton("Exit"); btn7.setBounds(500, 1330, 200, 50); this.add(btn7); Font l = new Font("Courier New", Font.LAYOUT_LEFT_TO_RIGHT,24); btn7.setFont(l); /**btnQuit = new JButton("Quit"); btnQuit.setBounds(440, 380, 100, 50); btnQuit.setFont(f); btnQuit.addActionListener(this); this.add(btnQuit); this.setVisible(true);*/ }*/ /**public void actionPerformed(ActionEvent e) { if (e.getSource() == btnQuit) System.exit(0); int x = OFFSET; int y = OFFSET; Obstacle wall; Crate b; SuitableLocation a; for (int i = 0; i < stage.length(); i++) { char item = stage.charAt(i); if (item == 'n') { Rashidul Islam
  • 15. y += SPACE; if (this.w < x) { this.w = x; } x = OFFSET; } else if (item == '#') { wall = new Obstacle(x, y); obs.add(wall); x += SPACE; } else if (item == '$') { b = new Crate(x, y); crates.add(b); x += SPACE; } else if (item == '.') { a = new SuitableLocation(x, y); SuitLo.add(a); x += SPACE; } else if (item == '@') { PlayerChar = new PlayerCharacter(x, y); x += SPACE; } else if (item == ' ') { x += SPACE; } } } h = y; public void buildWorld(Graphics g) { g.setColor(new Color(0, 108, 209)); g.fillRect(0, 0, this.getWidth(), this.getHeight()); ArrayList<User> world = new ArrayList<User>(); world.addAll(obs); world.addAll(SuitLo); world.addAll(crates); world.add(PlayerChar); Rashidul Islam
  • 16. for (int i = 0; i < world.size(); i++) { User item = (User) world.get(i); if ((item instanceof PlayerCharacter) || (item instanceof Crate)) { g.drawImage(item.getImage(), item.x() + 2, item.y() + 2, this); } else { g.drawImage(item.getImage(), item.x(), item.y(), this); } if (solved) { g.setColor(new Color(255,255,255)); g.drawString("The level has been solved!", 25, 20); Font f = new Font("Courier New", Font.BOLD,14); setFont(f); } } } @Override public void paint(Graphics g) { super.paint(g); buildWorld(g); } class TAdapter extends KeyAdapter { @Override public void keyPressed(KeyEvent e) { if (solved) { return; } int key = e.getKeyCode(); Rashidul Islam
  • 17. if (key == KeyEvent.VK_LEFT) { if (checkWallCollision(PlayerChar, LEFT_COLLISION)) { return; } if (checkBagCollision(LEFT_COLLISION)) { return; } PlayerChar.move(-SPACE, 0); } else if (key == KeyEvent.VK_RIGHT) { if (checkWallCollision(PlayerChar, RIGHT_COLLISION)) { return; } if (checkBagCollision(RIGHT_COLLISION)) { return; } PlayerChar.move(SPACE, 0); } else if (key == KeyEvent.VK_UP) { if (checkWallCollision(PlayerChar, TOP_COLLISION)) { return; } if (checkBagCollision(TOP_COLLISION)) { return; } PlayerChar.move(0, -SPACE); Rashidul Islam
  • 18. } else if (key == KeyEvent.VK_DOWN) { if (checkWallCollision(PlayerChar, BOTTOM_COLLISION)) { return; } if (checkBagCollision(BOTTOM_COLLISION)) { return; } PlayerChar.move(0, SPACE); } else if (key == KeyEvent.VK_R) { restartStage(); } } } repaint(); private boolean checkWallCollision(User actor, int type) { if (type == LEFT_COLLISION) { for (int i = 0; i < obs.size(); i++) { Obstacle wall = (Obstacle) obs.get(i); if (actor.isLeftCollision(wall)) { return true; } } return false; } else if (type == RIGHT_COLLISION) { for (int i = 0; i < obs.size(); i++) { Obstacle wall = (Obstacle) obs.get(i); if (actor.isRightCollision(wall)) { Rashidul Islam
  • 19. } return true; } return false; } else if (type == TOP_COLLISION) { for (int i = 0; i < obs.size(); i++) { Obstacle wall = (Obstacle) obs.get(i); if (actor.isTopCollision(wall)) { return true; } } return false; } else if (type == BOTTOM_COLLISION) { for (int i = 0; i < obs.size(); i++) { Obstacle wall = (Obstacle) obs.get(i); if (actor.isBottomCollision(wall)) { return true; } } return false; } } return false; private boolean checkBagCollision(int type) { if (type == LEFT_COLLISION) { for (int i = 0; i < crates.size(); i++) { Crate bag = (Crate) crates.get(i); if (PlayerChar.isLeftCollision(bag)) { for (int j=0; j < crates.size(); j++) { Crate item = (Crate) crates.get(j); Rashidul Islam
  • 20. if (!bag.equals(item)) { if (bag.isLeftCollision(item)) { return true; } } if (checkWallCollision(bag, LEFT_COLLISION)) { return true; } } } bag.move(-SPACE, 0); isSolved(); } return false; } else if (type == RIGHT_COLLISION) { for (int i = 0; i < crates.size(); i++) { Crate bag = (Crate) crates.get(i); if (PlayerChar.isRightCollision(bag)) { for (int j=0; j < crates.size(); j++) { Crate item = (Crate) crates.get(j); if (!bag.equals(item)) { if (bag.isRightCollision(item)) { return true; } } if (checkWallCollision(bag, RIGHT_COLLISION)) { return true; } } } } bag.move(SPACE, 0); isSolved(); Rashidul Islam
  • 21. return false; } else if (type == TOP_COLLISION) { for (int i = 0; i < crates.size(); i++) { Crate bag = (Crate) crates.get(i); if (PlayerChar.isTopCollision(bag)) { for (int j = 0; j < crates.size(); j++) { Crate item = (Crate) crates.get(j); if (!bag.equals(item)) { if (bag.isTopCollision(item)) { return true; } } if (checkWallCollision(bag, TOP_COLLISION)) { return true; } } } } bag.move(0, -SPACE); isSolved(); return false; } else if (type == BOTTOM_COLLISION) { for (int i = 0; i < crates.size(); i++) { Crate bag = (Crate) crates.get(i); if (PlayerChar.isBottomCollision(bag)) { for (int j = 0; j < crates.size(); j++) { Crate item = (Crate) crates.get(j); if (!bag.equals(item)) { if (bag.isBottomCollision(item)) { Rashidul Islam
  • 22. } return true; } if (checkWallCollision(bag, BOTTOM_COLLISION)) { return true; } } } } } } bag.move(0, SPACE); isSolved(); return false; public void isSolved() { int num = crates.size(); int compl = 0; for (int i = 0; i < num; i++) { Crate bag = (Crate) crates.get(i); for (int j = 0; j < num; j++) { SuitableLocation area = (SuitableLocation) SuitLo.get(j); if (bag.x() == area.x() && bag.y() == area.y()) { compl += 1; } } } } if (compl == num) { solved = true; repaint(); } Rashidul Islam
  • 23. public void restartStage() { } } SuitLo.clear(); crates.clear(); obs.clear(); initWorld(); if (solved) { solved = false; } 1.) Documentation: Constructor Summary Panel() g) Class - Game.java: --------------------------------------------------------------------------- Rashidul Islam
  • 25. --------------------------------------------------------------------------- 1.) Documentation: Constructor Summary Game() private JButton btn1; private JButton btn2; private JButton btn3; private JButton btn4; private JButton btn5; private JButton btn6; private JButton btn7; --------------------------------------------------------------------------- Task 2: Screen shots: a) Level-1: Fig: starting position Rashidul Islam
  • 26. Fig: Level Solved b) Level-2: Fig: starting position Rashidul Islam
  • 27. Fig: level solved b) Level-3: Fig: starting position Rashidul Islam
  • 28. Fig: level solved c) Level-4: Fig: starting position Rashidul Islam
  • 29. Fig: level solved d) Level-5: Fig: starting position Rashidul Islam
  • 30. Fig: starting position with buttons --------------------------------------------------------------------------- Task 3: Class diagrams: a) Class Diagram: i) Class Diagram or Design In UML Using StarUML: Fig: Level 1 Rashidul Islam
  • 32. ii) Testing Data By BlueJ: Fig : Testing Data By BlueJ Rashidul Islam