00155002_aung zay ya adi (document)
TRANSCRIPT
MCC
ANALYSIS, DESIGN AND IMPLEMENTATION
Text Adventures
CREATED BY AUNG ZAY YA
NCC Education
TEXT ADVENTURES Created By Aung Zay Ya
NCCEducation
Level 5 Diploma in Computing
Analysis, Design and Implementation
Centre Name : MCC Training Institute (Yangon)
Assignment Title : Text Adventures
Exam Cycle : SEPTEMBER 2015
Candidate Name :Aung Zay Ya
NCC Education ID No. : 00155002
Submission Date : -
Marker’s Comment :
Moderator’s Comment :
Mark: Moderated Mark : Final Mark :
Statement and Confirmation of Own Work
Page 1 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Each time you submit an assignment you must attach this statement as the cover page for both the hard copy and the electronic version. If the statement is missing your work will not be marked.
Student Declaration
I have read and understood NCC Education’s Policy on Academic Dishonesty and Plagiarism.
I can confirm the following details:
Programme/Qualification Name: Level 5 Diploma in Computing
Student ID/Registration number: -
Name: Aung Zay Ya
Centre Name: MCC Training Institute (Yangon)
Module Name: Analysis, Design and Implementation
Module Leader: U Thein Naing Htwe
Number of words:
I confirm that this is my own work and that I have not plagiarized any part of it. I have also noted the
assessment criteria and pass mark for assignments.
Due Date:
Student Signature: aung
Table of ContentsIntroduction....................................................................................................................................5
Acknowledgement.........................................................................................................................6
Task 1............................................................................................................................................7
Page 2 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Candidate Class List and Diagrams...........................................................................................7
Text Adventures Class Diagrams (Figure 1.1).......................................................................7
Task 2............................................................................................................................................8
Activity Diagram.........................................................................................................................8
Choose Thing Activity Diagram (Figure 2.1)..........................................................................8
Find Thing Activity Diagram (Figure 2.2)................................................................................9
Go Down Thing From Bag Activity Diagram (Figure 2.3).....................................................10
Moving To Request Room Activity Diagram (Figure 2.4).....................................................11
Parsing Client Command Activity Diagram (Figure 2.5).......................................................12
Task 3..........................................................................................................................................13
Use Case Diagram...................................................................................................................13
Text Adventures Use Case Diagram (Figure 3.1)................................................................13
Task 4..........................................................................................................................................14
Code Architecture....................................................................................................................14
TextAdventures.java file (design for Text Adventures Game)..............................................14
AvailableThing.java file (to define the thing is available or unavailable)..............................17
Client.java file (to get thing from bag and to go down thing from bag).................................18
PermanentThing.java file (to define Permanent Thing)........................................................19
Task 5..........................................................................................................................................31
System Implementation...........................................................................................................31
Main (See: Figure 5.1)..........................................................................................................31
Find (See: Figure 5.2)..........................................................................................................32
Choose (See: Figure 5.3).....................................................................................................33
GoDown (See: Figure 5.4)...................................................................................................34
Move (See: Figure 5.5).........................................................................................................35
End (See: Figure 5.6)...........................................................................................................36
Page 3 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Support (See: Figure 5.7).....................................................................................................37
Page 4 of 41
TEXT ADVENTURES Created By Aung Zay Ya
IntroductionI am Aung Zay Ya from Myanmar. I am majoring in Business Information and Technology (BIT) Level 5 Diploma in Computing and now studying at MCC Training Institute, Yangon Campus. In this assignment, Take Art application s create. Also the documentation of the application like coding .
Page 5 of 41
TEXT ADVENTURES Created By Aung Zay Ya
AcknowledgementI would like to thank to my classmates and lecturers for helping throughout my assignments. Besides, special thank goes to my assignment teacher U Thein Naing Htwe.
Page 6 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Task 1
Candidate Class List and Diagrams The system needs to analyze the data for class, attribute, method for system architecture.
Noun (Class) Verb (Attribute) Adjective (Method)
Commands Change numerous
Player Explore various
Game Interpret
Parser Look
Room
Description
Area
Text
Move
Items
Class List and removed other unwanted candidates and reason why you removed
them
Noun
Commands
Parser
Description
Area
Text
Move
Page 7 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Noun Reason of RemovalParser SynonymDescriptionCommands
outside of the scopeAreaTextMove part of future design
Class diagram, with titles, attributes, methods, association and cardinalities
Page 8 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Text Adventures Class Diagrams (Figure 1.1)
Client
-name: String-bag: thing[*]+setName(n: String): Void+getName(): String+giveThing(t: String): Thing+clearBagThing(i: String): Thing+getBag(): Thing[*]+setBag(b: Thing[*]): Void
Match
-client: Client-rm: Room[*]+Match()+getClient(): String+setClient(C: String): Void+getRm(): String+setRm(rm: String): Void
Thing
-name: String-description: String+canChoose(): boolean+getDescription(): String+setDescription(desc: String): void+setName(n: String)
Room
-name: String-thing: Thing[*]-exit: String[*]+afterroomexit: String+giveThing(T: String): Thing+getName(): String+setName(n: String): void+getThing(): Thing[*]+setThing(t: Thing[*]): void+setexit(ext: Sring): void+getexit(): String[]+getafterroomexit(): String[]+setafterroomexit(rexit: String): void
Available Thing
+canChoose(): boolean
Permanent Thing
+canChoose(): boolean
11
*1
1
*
1
*
Parser
+parse(cmd: String): String+godown(T: String): String+choose(T: String): String+move(T: String): String+find(T: String): String
11
Figure 1.1 (Class List and Diagrams)
Page 9 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Task 2
Activity Diagram
Choose Thing Activity Diagram (Figure 2.1)
Client System
Client request Thing Name for Choose
Accept Thing Name Find the Thing in bag
check counter less than thing count
Find the Thing in room take thing at counter
NO YES
check thing equal to bag's thing name
increase counter by 1
choose thing
NO
YES
check counter less than thing count
Return Nothing take thing at counter
NO YES
increase counter by 1 choose thing
NO YES
Figure 2.1 (Choose Thing Activity)
Page 10 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Find Thing Activity Diagram (Figure 2.2)
Client System
give client input thing name
Accept Name set counter to 0
check counter less than thing count
Return Null take thing at counter
check thing equal to thing name
return thing at counter
increase counter by 1
NO YES
NO
YES
Figure 2.2 (Find Thing Activity Diagram)
Page 11 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Go Down Thing From Bag Activity Diagram (Figure 2.3)
Client System
Client request command go down Thing
accept go down thing command
find the thing in bag
Return Nothing take thing at counter
NO YES
check counter less than thing count
check thing equal to bag's thing name
go down thing increase counter by 1
YES NO
Figure 2.3 (Go Down Thing from Bag)
Page 12 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Moving To Request Room Activity Diagram (Figure 2.4)
Client System
Client command for moving room
accept moving command
find the moving room exit
Return Nothing
NO
check exit room
moving to the client command room
YES
Figure 2.4 (Moving to Request Room Activity Diagram)
Page 13 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Parsing Client Command Activity Diagram (Figure 2.5)
Client System
client sent command
Accept command
Check comman is Splitable
Check with valid command split cmd to c and obj with " "
NO YES
Check c with valid comman
Display Error Do command with obj
NO YES
display error Do command
YESNO
Figure 2.5 (Parsing Client Command Activity Diagram)
Page 14 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Task 3
Use Case Diagram
Text Adventures Use Case Diagram (Figure 3.1)
System
Begin Game
Client Find Thing
Find Room
Choose Thing
Go down Thing
Moving Room
Quit Game
Page 15 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Task 4
Code Architecture
TextAdventures.java file (design for Text Adventures Game)
Page 16 of 41
package pkTxtAdventureGUI;
import javax.swing.*;
import javax.swing.text.TabableView;
import pkTxtAdventure.Game;
import java.awt.event.*;
import java.awt.*;
public class TextAdventures extends JFrame implements KeyListener {
private JTextArea txaDisplay;
private JTextField txfCommand;
private Game gameTA;
public TextAdventures() {
setSize(600, 600);
setTitle("Text Adventures");
setLayout(new BorderLayout());
setLocationRelativeTo(null);
getContentPane().setBackground(Color.pink);
txaDisplay = new JTextArea();
txaDisplay.setFont(new Font("Comic Sans MS", Font.PLAIN, 18));
txaDisplay.setEditable(false);
txaDisplay.setBackground(Color.CYAN);
JScrollPane jsp = new JScrollPane(
txaDisplay,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(jsp, BorderLayout.CENTER);
TEXT ADVENTURES Created By Aung Zay Ya
Page 17 of 41
txfCommand = new JTextField();
txfCommand.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
txfCommand.addKeyListener(this);
add(txfCommand, BorderLayout.SOUTH);
JLabel lblhead = new JLabel("Text Advantures Game");
lblhead.setForeground(Color.blue);
lblhead.setFont(new Font("Comic Sans MS", Font.PLAIN, 20));
lblhead.setHorizontalAlignment((int) CENTER_ALIGNMENT);
add(lblhead, BorderLayout.NORTH);
String initial = "Game will start soon. Type 'help' if you need help!\n";
gameTA = new Game();
initial += gameTA.getPc().parser("look") + "\n";
txaDisplay.setText(initial);
setVisible(true);
txfCommand.requestFocus();
}
public static void main(String[] args) {
new TextAdventures();
}
TEXT ADVENTURES Created By Aung Zay Ya
Page 18 of 41
@Override
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent ke) {
if (ke.getKeyChar() == '\n') {
String cmd = txfCommand.getText().trim();
String temp = txaDisplay.getText();
temp += ">>" +cmd + "\n" + gameTA.getPc().parser(cmd) + "\n";
txaDisplay.setText(temp);
txfCommand.setText("");
txfCommand.requestFocus();
}
}
}
TEXT ADVENTURES Created By Aung Zay Ya
AvailableThing.java file (to define the thing is available or unavailable)
Page 19 of 41
package pkTxtAdventure;
public class AvailableThing extends Thing {
public AvailableThing(String n, String d) {
super(n, d);
}
public boolean isPickable(){
return true;
}
}
TEXT ADVENTURES Created By Aung Zay Ya
Client.java file (to get thing from bag and to go down thing from bag)
Page 20 of 41
package pkTxtAdventure;import java.util.ArrayList;public class Client {
private ArrayList<Thing> bag; public Client() {
bag = new ArrayList<Thing>();}public ArrayList<Thing> getBag() {
return bag;}public void setBag(ArrayList<Thing> bag) {
this.bag = bag;}public String findBagThing(String n){
String s = null;for (int i = 0; i < bag.size(); i++) {
if (bag.get(i).getName().equalsIgnoreCase(n)) {s = bag.get(i).getDescription();return s;
}}return s;
}public Thing godownBagThing(String n){
Thing t = null;for (int i = 0; i < bag.size(); i++) {
if (bag.get(i).getName().equalsIgnoreCase(n)) {t = bag.get(i);bag.remove(i);return t;
}}return t;
}public void addBagThing(Thing i){
bag.add(i);}
}
TEXT ADVENTURES Created By Aung Zay Ya
PermanentThing.java file (to define Permanent Thing)
Page 21 of 41
package pkTxtAdventure;
public class PermanentThing extends Thing{
public PermanentThing(String n, String d) {
super(n, d);
}
public boolean isPickable(){
return false;
}
}
TEXT ADVENTURES Created By Aung Zay Ya
Thing.java file (to get and define Thing Name and Description)
Page 22 of 41
package pkTxtAdventure;
public class Thing {
private String name;
private String description;
private boolean pickable;
public Thing(String n, String d) {
name = n;
description = d;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isPickable(){
return pickable;
}
}
TEXT ADVENTURES Created By Aung Zay Ya
Room.java file (to define the room exit , moving room, room description)
Page 23 of 41
package pkTxtAdventure;
import java.util.ArrayList;
public class Room {
private String name;
private ArrayList<Thing> roomT;
private ArrayList<String> exits;
private int nearByRoomNo[];
private String des;
public Room( ) {
roomT = new ArrayList<Thing>();
exits = new ArrayList<String>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Thing> getRoomItm() {
return roomT;
}
public void setRoomItm(ArrayList<Thing> roomItm) {
this.roomT = roomItm;
}
public ArrayList<String> getExits() {
return exits;
}
public void setExits(ArrayList<String> exits) {
this.exits = exits; }
TEXT ADVENTURES Created By Aung Zay Ya
Page 24 of 41
public String getDes() {
generateDescription();
return des;
}
public void setDes(String des) {
this.des = des;
}
public void generateDescription(){
des = "You are @ " + name + ".\nThere are ";
des+= roomT.get(0).getName();
for (int i = 1; i < roomT.size()-1; i++) {
des+= ", " + roomT.get(i).getName() ;
}
des+= " and " + roomT.get(roomT.size()-1).getName() + ".";
des+= "\nThere are "+ exits.size() + " exits : " ;
for (int i = 0; i < exits.size(); i++) {
des+= exits.get(i) + "; ";
}
}
TEXT ADVENTURES Created By Aung Zay Ya
Page 25 of 41
public String lookRoomItem(String n){
String s = null;
for (int i = 0; i < roomT.size(); i++) {
if (roomT.get(i).getName().equalsIgnoreCase(n)) {
s = roomT.get(i).getDescription();
return s;
}
}
return s;
}
public Thing giveRoomItem(String n){
Thing itm = null;
for (int i = 0; i < roomT.size(); i++) {
if (roomT.get(i).getName().equalsIgnoreCase(n) && roomT.get(i).isPickable()) {
itm = roomT.get(i);
roomT.remove(i);
return itm;
}
}
return itm;
}
public void addRoomItem(Thing i){
roomT.add(i);
}
public int[] getNearByRoomNo() {
return nearByRoomNo;
}
public void setNearByRoomNo(int[] nearByRoomNo) {
this.nearByRoomNo = nearByRoomNo;
}
public int getRoonNo4Exit(String e){
for (int i = 0; i < exits.size(); i++) {
if (e.equalsIgnoreCase(exits.get(i))) {
return nearByRoomNo[i]; }}
return -1;
}
}
TEXT ADVENTURES Created By Aung Zay Ya
Match.java file (to begin the Text Adventures)
Page 26 of 41
package pkTxtAdventure;
import java.util.ArrayList;
import java.util.Scanner;
public class Match {
private Client c;
private Room roomArr[];
private int curRoom;
private ParseCommand parcom;
public Match() {
curRoom = (int) (4*Math.random());
c = new Client();
parcom = new ParseCommand();
roomArr = new Room[4];
roomArr[0] = new Room();
roomArr[0].setName("Lounge Room");
roomArr[0].addRoomItem(new PermanentThing("TV", "Watch the news and Watching for Movie"));
roomArr[0].addRoomItem(new PermanentThing("iMac", "Drawing the Graphic Design and Some Art or 3D"));
roomArr[0].addRoomItem(new AvailableThing("Remote", "Control the TV"));
TEXT ADVENTURES Created By Aung Zay Ya
Page 27 of 41
int nr[] = {3, 1};
ArrayList<String> e = new ArrayList<String>();
e.add("West");
e.add("South");
roomArr[0].setExits(e);
roomArr[0].setNearByRoomNo(nr);
roomArr[1] = new Room();
roomArr[1].setName("Kitchen Room");
roomArr[1].addRoomItem(new PermanentThing("Cup", "drink the water"));
roomArr[1].addRoomItem(new PermanentThing("TeaPot", "drink for some tea"));
roomArr[1].addRoomItem(new AvailableThing("WaterCooler", "Provide the hot and cold water"));
ArrayList<String> e1 = new ArrayList<String>();
e1.add("North");
e1.add("West");
int nr1[] = {0,2};
roomArr[1].setNearByRoomNo(nr1);
roomArr[1].setExits(e1);
TEXT ADVENTURES Created By Aung Zay Ya
Page 28 of 41
roomArr[2] = new Room();
roomArr[2].setName("Bathroom");
roomArr[2].addRoomItem(new PermanentThing("WaterTank", "With full water"));
roomArr[2].addRoomItem(new PermanentThing("Soap", "to clean the body."));
roomArr[2].addRoomItem(new AvailableThing("FacialForm", "to clean the face."));
ArrayList<String> e2 = new ArrayList<String>();
e2.add("North");
e2.add("East");
int nr2[] = {3,1};
roomArr[2].setNearByRoomNo(nr2);
roomArr[2].setExits(e2);
roomArr[3] = new Room();
roomArr[3].setName("Bedroom");
roomArr[3].addRoomItem(new PermanentThing("Fan", "Cooling to people"));
roomArr[3].addRoomItem(new PermanentThing("Chair", "Sit and Relax."));
roomArr[3].addRoomItem(new AvailableThing("Guitar", "Playing some music."));
ArrayList<String> e3 = new ArrayList<String>();
e3.add("East");
e3.add("South");
int nr3[] = {0,2};
roomArr[3].setNearByRoomNo(nr3);
roomArr[3].setExits(e3);
}
TEXT ADVENTURES Created By Aung Zay Ya
Page 29 of 41
public void startMatch(){System.out.println(roomArr[curRoom].getDes());String command = "";Scanner input = new Scanner(System.in);while (true) {
command = input.nextLine();System.out.println(parcom.parser(command));
}}public ParseCommand getPc() {
return parcom;}public void setPc(ParseCommand parcom) {
this.parcom = parcom;}public class ParseCommand{
public String parser(String cmd){cmd = cmd.trim();String c = "";String obj = "";String output = "Not accurate command. Please see Support!";int mid = cmd.indexOf(" ");if(mid != -1){
c = cmd.substring(0, mid).trim();obj = cmd.substring(mid +1).trim();if (c.equalsIgnoreCase("find")) {
output = find(obj);}else if (c.equalsIgnoreCase("godown")) {
output = godown(obj);}else if(c.equalsIgnoreCase("choose")){
output = choose(obj);}else if (c.equalsIgnoreCase("move")) {
output = move(obj);}
TEXT ADVENTURES Created By Aung Zay Ya
Page 30 of 41
}else if(cmd.equalsIgnoreCase("find")){output = Look();
}else if(cmd.equalsIgnoreCase("Support")){output = help();
}else if (cmd.equals("end")) {System.exit(0);
}return output;
}public String Look(){
return roomArr[curRoom].getDes();}
public String find(String itm){String temp = null;temp = roomArr[curRoom].lookRoomItem(itm);if (temp == null) {
temp = c.findBagThing(itm);}if (temp == null) {
temp = "Keep typing your text "+ itm + " isn't available.";}return temp;
}public String move(String e){
int i = roomArr[curRoom].getRoonNo4Exit(e);if (i != -1) {
curRoom = i;return roomArr[curRoom].getDes();
}else{return "No exit for "+ e +" loacation.";
}}
TEXT ADVENTURES Created By Aung Zay Ya
Page 31 of 41
public String choose(String itm){Thing i = roomArr[curRoom].giveRoomItem(itm);if (i != null) {
c.addBagThing(i);return "You choose the " + i.getName() + " and put it in the bag.";
}else if (roomArr[curRoom].lookRoomItem(itm) == null){return "No thing as " + itm + ".";
}else{return "You can't choose " + itm + ".";
}}
public String godown(String t){Thing i = c.godownBagThing(t);if(i != null){
roomArr[curRoom].addRoomItem(i);return "You godown " + i.getName() + ".";
}else{return "No thing as " + t + " to go down.";
}}
TEXT ADVENTURES Created By Aung Zay Ya
Page 32 of 41
public String help() {
return "Support!\n"
+ "- The command should be used in the <command> <object name>\n"
+ "- But the command is not case sensitive.\n"
+ "- For Example type 'find remote' to find the remote.\n"
+ "- Available command are:\n"
+ "\t- move\n"
+ "\t- find\n"
+ "\t- choose\n"
+ "\t- godown\n"
+ "- Some can be use with single word such as :\n"
+ "\t- find\n"
+ "\t- support\n"
+ "\t- End";
}
}
}
TEXT ADVENTURES Created By Aung Zay Ya
Task 5
System Implementation
Main (See: Figure 5.1)
(Figure 5.1)
Page 33 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Find (See: Figure 5.2)
(Figure 5.2)
Page 34 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Choose (See: Figure 5.3)
(Figure 5.3)
Page 35 of 41
TEXT ADVENTURES Created By Aung Zay Ya
GoDown (See: Figure 5.4)
(Figure 5.4)
Page 36 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Move (See: Figure 5.5)
(Figure 5.5)
Page 37 of 41
TEXT ADVENTURES Created By Aung Zay Ya
End (See: Figure 5.6)
(Figure 5.6)
Page 38 of 41
TEXT ADVENTURES Created By Aung Zay Ya
Support (See: Figure 5.7)
(Figure 5.7)
Page 39 of 41
TEXT ADVENTURES Created By Aung Zay Ya
ReferencesAnalysis, Design and implementation Textbook by NCC Education.
Design and Developing Object-Oriented Computer Programs Textbook by NCC Education.
Page 40 of 41