SlideShare uma empresa Scribd logo
1 de 33
Rashidul Islam
Sokoban Game Development using Java | Rashidul Islam
SOKOBAN GAME
Rashidul Islam
Table of Contents
No Description Page
Task 1
a) The application that I produce.
1
Task 2
a)
Test data.
17
Task 3
a)
Class diagrams
19
Rashidul Islam
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:
c) Class - PlayerCharacter.java:
---------------------------------------------------------------------------
Constructor Summary
Crate(int i, int j)
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. )
* @version (09/11/12)
*/
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("Level1");
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("Level2");
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("Level3");
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("Level4");
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("Level5");
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:
Test data:
a) Full Testing Plan:
It’s important that tests are described fully before they are carried out.
Anyone carrying out a test without first describing the expected outcome is
not testing, but experimenting.
My testing plan includes:
 The identity of the component to be tested.
 The purpose of the test.
 The condition under which the test is to be carried out.
 The expected outcome.
b) Why I chose the testing data:
Rashidul Islam
Because I think:
 The testing data is representative of other data.
 These were the best suitable test data where errors are particularly
likely to happen.
c) What testing categories you are stressing in your regime:
We need a structured approach to testing. These are the testing categories
that I am stressing in my regime:
 I am going to decide on a set of test data.
 I am going to record the expected results and the actual results.
d) Full log of how I implemented the testing:
e) What regression testing I needed to do as a result of fixes:
Rashidul Islam
1. Testing :
a. For Public class User (User.java) (Lines 13-15):
case Line
No.
Data
Type
i j x y Constructor Expected(i,j) Actual(i,j)
1 13 int 0 0 Public User()
14 int x 0 0 Public User() (X, -) (X, -)
15 int y 0 0 Public User() (x, y) (x, y)
b. For Public class User (User.java) (Lines 18-19):
case Line No. Data Type Method Expected Actual
2 18 Image(pic) java.awt.Image
getImage()
18. a. Image(pic) java.awt.Image
getImage()
pic pic
19 Image(pic) java.awt.Image
getImage()
pic pic
c. For Public class User (User.java) (Lines 20-21):
cas
e
Lin
e
No.
Data Type Method Expected(i
n pic)
Actual(i
n pic)
3 20 Image(im
g)
Void
setImage(java.awt.Image i
mg)
20.
a.
Image(im
g)
Void
setImage(java.awt.Image i
mg)
img img
21 Image(im
g)
Void
setImage(java.awt.Image i
mg)
img img
d. For Public class User (User.java) (Lines 22-23):
Rashidul Islam
case Line
No.
Data Type Method Expected Actual
4 22 int Int x()
22.
a.
int Int x() i i
23 int Int x() i i
e. For Public class User (User.java) (Lines 24-25):
case Line
No.
Data Type Method Expected Actual
5 24 int Int y()
24.
a.
int Int y() j j
25 int Int y() j j
f. For Public class User (User.java) (Lines 26-27):
case Line
No.
Data Type Method Expected
(in i)
Actual
(in i)
6 26 int(x) void setX(int x)
26.
a.
int(x) void setX(int x) x x
27 int(x) void setX(int x) x x
g. For Public class User (User.java) (Lines 26-27):
Rashidul Islam
case Line
No.
Data Type Method Expected
(in j)
Actual
(inj)
7 26 int(y) void setY(int x)
26.
a.
int(y) void setY(int x) y y
27 int(y) void setY(int x) y y
h. For Public class User (User.java) (Lines 30-31):
case Line
No.
Data Type Method Expected Actual
8 30 User(actor) boolean
isLeftCollision(User actor)
- -
30.
a.
User(actor) boolean
isLeftCollision(User actor)
true true
30.
b.
User(actor) boolean
isLeftCollision(User actor)
true true
30.
c.
User(actor) boolean
isLeftCollision(User actor)
false false
31 User(actor) boolean
isLeftCollision(User actor)
false false
i. For Public class User (User.java) (Lines 32-33):
Rashidul Islam
case Line
No.
Data Type Method Expected Actual
9 32 User(actor) boolean
isRightCollision(User actor)
- -
32.
a.
User(actor) boolean
isRightCollision(User actor)
true true
32.
b.
User(actor) boolean
isRightCollision(User actor)
true true
32.
c.
User(actor) boolean
isRightCollision(User actor)
false false
33 User(actor) boolean
isRightCollision(User actor)
false false
j. For Public class User (User.java) (Lines 34-35):
case Line
No.
Data Type Method Expected Actual
10 34 User(actor) boolean
isTopCollision(User actor)
- -
34.
a.
User(actor) boolean
isTopCollision(User actor)
true true
34.
b.
User(actor) boolean
isTopCollision(User actor)
true true
34.
c.
User(actor) boolean
isTopCollision(User actor)
false false
35 User(actor) boolean
isTopCollision(User actor)
false false
k. For Public class User (User.java) (Lines 36-37):
cas
e
Lin
e
Data Type Method Expecte
d
Actua
l
Rashidul Islam
No.
11 36 User(actor
)
boolean
isBottomCollision(User actor
)
- -
36.
a.
User(actor
)
boolean
isBottomCollision(User actor
)
true true
36.
b.
User(actor
)
boolean
isBottomCollision(User actor
)
true true
36.
c.
User(actor
)
boolean
isBottomCollision(User actor
)
false false
37 User(actor
)
boolean
isBottomCollision(User actor
)
false false
Rashidul Islam
Task 3:
Class diagrams:
a) Class Diagram:
Rashidul Islam

Mais conteúdo relacionado

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Destaque

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Introduction to-sokoban-game-development-using-java-by-rashidul-islam

  • 1. Rashidul Islam Sokoban Game Development using Java | Rashidul Islam SOKOBAN GAME
  • 2. Rashidul Islam Table of Contents No Description Page Task 1 a) The application that I produce. 1 Task 2 a) Test data. 17 Task 3 a) Class diagrams 19
  • 3. Rashidul Islam Task 1: The application that I have created: a) Class - SuitableLocation.java: ---------------------------------------------------------------------------
  • 4. Rashidul Islam 1.) Documentation: Constructor Summary SuitableLocation(int i, int j) ---------------------------------------------------------------------------------------------- b) Class - Crate.java: ---------------------------------------------------------------------------
  • 5. Rashidul Islam 1.) Documentation: c) Class - PlayerCharacter.java: --------------------------------------------------------------------------- Constructor Summary Crate(int i, int j)
  • 6. 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)
  • 7. Rashidul Islam d) Class - Obstacle.java: --------------------------------------------------------------------------- 1.) Documentation: Constructor Summary Obstacle(int i, int j)
  • 8. Rashidul Islam e) Class - User.java:
  • 10. 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. ) * @version (09/11/12) */
  • 11. 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>();
  • 12. 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; }
  • 13. Rashidul Islam public final void initWorld() { btn1 = new JButton("Level1"); 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("Level2"); 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("Level3"); 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("Level4"); 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("Level5"); 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");
  • 14. 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') {
  • 15. 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);
  • 16. 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();
  • 17. 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);
  • 18. 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)) {
  • 19. 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);
  • 20. 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(); } }
  • 21. 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)) {
  • 22. 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(); } }
  • 23. 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: ---------------------------------------------------------------------------
  • 25. 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: Test data: a) Full Testing Plan: It’s important that tests are described fully before they are carried out. Anyone carrying out a test without first describing the expected outcome is not testing, but experimenting. My testing plan includes:  The identity of the component to be tested.  The purpose of the test.  The condition under which the test is to be carried out.  The expected outcome. b) Why I chose the testing data:
  • 26. Rashidul Islam Because I think:  The testing data is representative of other data.  These were the best suitable test data where errors are particularly likely to happen. c) What testing categories you are stressing in your regime: We need a structured approach to testing. These are the testing categories that I am stressing in my regime:  I am going to decide on a set of test data.  I am going to record the expected results and the actual results. d) Full log of how I implemented the testing: e) What regression testing I needed to do as a result of fixes:
  • 27. Rashidul Islam 1. Testing : a. For Public class User (User.java) (Lines 13-15): case Line No. Data Type i j x y Constructor Expected(i,j) Actual(i,j) 1 13 int 0 0 Public User() 14 int x 0 0 Public User() (X, -) (X, -) 15 int y 0 0 Public User() (x, y) (x, y) b. For Public class User (User.java) (Lines 18-19): case Line No. Data Type Method Expected Actual 2 18 Image(pic) java.awt.Image getImage() 18. a. Image(pic) java.awt.Image getImage() pic pic 19 Image(pic) java.awt.Image getImage() pic pic c. For Public class User (User.java) (Lines 20-21): cas e Lin e No. Data Type Method Expected(i n pic) Actual(i n pic) 3 20 Image(im g) Void setImage(java.awt.Image i mg) 20. a. Image(im g) Void setImage(java.awt.Image i mg) img img 21 Image(im g) Void setImage(java.awt.Image i mg) img img d. For Public class User (User.java) (Lines 22-23):
  • 28. Rashidul Islam case Line No. Data Type Method Expected Actual 4 22 int Int x() 22. a. int Int x() i i 23 int Int x() i i e. For Public class User (User.java) (Lines 24-25): case Line No. Data Type Method Expected Actual 5 24 int Int y() 24. a. int Int y() j j 25 int Int y() j j f. For Public class User (User.java) (Lines 26-27): case Line No. Data Type Method Expected (in i) Actual (in i) 6 26 int(x) void setX(int x) 26. a. int(x) void setX(int x) x x 27 int(x) void setX(int x) x x g. For Public class User (User.java) (Lines 26-27):
  • 29. Rashidul Islam case Line No. Data Type Method Expected (in j) Actual (inj) 7 26 int(y) void setY(int x) 26. a. int(y) void setY(int x) y y 27 int(y) void setY(int x) y y h. For Public class User (User.java) (Lines 30-31): case Line No. Data Type Method Expected Actual 8 30 User(actor) boolean isLeftCollision(User actor) - - 30. a. User(actor) boolean isLeftCollision(User actor) true true 30. b. User(actor) boolean isLeftCollision(User actor) true true 30. c. User(actor) boolean isLeftCollision(User actor) false false 31 User(actor) boolean isLeftCollision(User actor) false false i. For Public class User (User.java) (Lines 32-33):
  • 30. Rashidul Islam case Line No. Data Type Method Expected Actual 9 32 User(actor) boolean isRightCollision(User actor) - - 32. a. User(actor) boolean isRightCollision(User actor) true true 32. b. User(actor) boolean isRightCollision(User actor) true true 32. c. User(actor) boolean isRightCollision(User actor) false false 33 User(actor) boolean isRightCollision(User actor) false false j. For Public class User (User.java) (Lines 34-35): case Line No. Data Type Method Expected Actual 10 34 User(actor) boolean isTopCollision(User actor) - - 34. a. User(actor) boolean isTopCollision(User actor) true true 34. b. User(actor) boolean isTopCollision(User actor) true true 34. c. User(actor) boolean isTopCollision(User actor) false false 35 User(actor) boolean isTopCollision(User actor) false false k. For Public class User (User.java) (Lines 36-37): cas e Lin e Data Type Method Expecte d Actua l
  • 31. Rashidul Islam No. 11 36 User(actor ) boolean isBottomCollision(User actor ) - - 36. a. User(actor ) boolean isBottomCollision(User actor ) true true 36. b. User(actor ) boolean isBottomCollision(User actor ) true true 36. c. User(actor ) boolean isBottomCollision(User actor ) false false 37 User(actor ) boolean isBottomCollision(User actor ) false false
  • 32. Rashidul Islam Task 3: Class diagrams: a) Class Diagram: