Assign 2
Assign 2
Assign 2
Prepared by
Yang Li (30319191)
Date: 3/06/2017
ITECH7201 Software Engineering: Analysis and Design Assignment 2
Table of Contents
1 Introduction 3
2. Statement of contribution 3
3. Group part – Maze Game map 4
4. Group part – Environment introduce 4
5. Group part – Move/Look command 4
5.1 Move command ............................................................................................................................... 4
2
ITECH7201 Software Engineering: Analysis and Design Assignment 2
1 Introduction
2. Statement of contribution
3
ITECH7201 Software Engineering: Analysis and Design Assignment 2
When the command is entered, the play moves from current location to another
one, and everything at the new location will be displayed. If there is no exit in the
direction which entered by the user, an error message will be displayed and the
player still stay at current location.
Source code:
package mazegame.control;
import mazegame.entity.Exit;
import mazegame.entity.Player;
import mazegame.entity.Exit;
import mazegame.entity.Player;
5
ITECH7201 Software Engineering: Analysis and Design Assignment 2
thePlayer.getCurrentLocation().getExitCollection().getExit((String)argument);
return new CommandResponse(theExit.getDescription());
}
}
return response;
}
}
import mazegame.entity.Player;
/**
* Created by sola2 on 30/05/2017.
*/
public class ListCommand implements Command {
@Override
public CommandResponse execute(ParsedInput userInput, Player thePlayer) {
return new CommandResponse(thePlayer.getInventory().toString());
}
}
import mazegame.entity.Item;
import mazegame.entity.Player;
/**
* Created by sola2 on 31/05/2017.
*/
public class GetCommand implements Command {
@Override
public CommandResponse execute(ParsedInput userInput, Player thePlayer) {
if (userInput.getArguments().size() == 0){
return new CommandResponse("What do you want to get?");
}
if (itemOnLocation == null){
return new CommandResponse("There is no " + itemLabel + " at this place...");
}
//successfully added
boolean successAdd = thePlayer.getInventory().addItem(itemOnLocation);
if (successAdd){
thePlayer.getCurrentLocation().getInventory().removeItem(itemLabel);
return new CommandResponse("You picked up a " + itemLabel);
}
//failed to add
return new CommandResponse("It's too heavy!");
}
}
import mazegame.entity.Item;
import mazegame.entity.Player;
/**
* Created by sola2 on 31/05/2017.
*/
public class DropCommand implements Command {
@Override
7
ITECH7201 Software Engineering: Analysis and Design Assignment 2
if (userInput.getArguments().size() == 0){
return new CommandResponse("What do you want to drop?");
}
if (itemInInventory == null){
return new CommandResponse("There is no " + itemLabel + " in your
inventory...");
}
//successfully dropped
boolean successDrop =
thePlayer.getCurrentLocation().getInventory().addItem(itemInInventory);
if(successDrop) {
thePlayer.getInventory().removeItem(itemLabel);
return new CommandResponse(itemLabel + " is dropped on the location");
}
return new CommandResponse(itemLabel + " not found..");
import mazegame.entity.Item;
import mazegame.entity.Player;
if (userInput.getArguments().size() == 0){
return new CommandResponse("What do you want to buy?");
}
//enough money
if (thePlayer.getInventory().getGold() >= itemToBuy.getValue())
{
boolean successBuy = thePlayer.getInventory().addItem(itemToBuy);
if (successBuy)
{
thePlayer.getInventory().removeMoney(itemToBuy.getValue());
return new CommandResponse("You bought " + itemLabel);
}
else
return new CommandResponse("It's too heavy!");
}
return new CommandResponse("Not enough money!");
}
}
import mazegame.entity.Item;
import mazegame.entity.Player;
if (userInput.getArguments().size() == 0)
return new CommandResponse("What do you want to sell?");
if (itemToSell == null) {
return new CommandResponse("You do not have a " + itemLabel);
} else {
thePlayer.getInventory().removeItem(itemLabel);
thePlayer.getInventory().addMoney(itemToSell.getValue());
return new CommandResponse("You sold " + itemLabel + " and get " +
itemToSell.getValue() + " pieces of gold!");
}
}
}
9
ITECH7201 Software Engineering: Analysis and Design Assignment 2
import mazegame.entity.Player;
if (userInput.getArguments().size() == 0){
return new CommandResponse("Who do you want to attack?");
}
else
{
System.out.println("You attacked " +
thePlayer.getCurrentLocation().getNpc().getName() + " for "
+ thePlayer.getStrength() + " life points!");
thePlayer.getCurrentLocation().getNpc().setLifePoints(thePlayer.getCurrentLocation().getNpc
().getLifePoints() -
thePlayer.getStrength());
//NPC is dead
if (thePlayer.getCurrentLocation().getNpc().getLifePoints() <= 0){
System.out.println(thePlayer.getCurrentLocation().getNpc().getName() + " is
dead...");
thePlayer.getCurrentLocation().removeNpc();
return new CommandResponse("");
}
points!");
thePlayer.setLifePoints(thePlayer.getLifePoints() -
thePlayer.getCurrentLocation().getNpc().getStrength());
System.out.println(thePlayer.getCurrentLocation().getNpc().getName() + "'s
current life point: " +
thePlayer.getCurrentLocation().getNpc().getLifePoints());
//player died
if (thePlayer.getLifePoints() <= 0){
return new CommandResponse("You died!",true);
}
return new CommandResponse("");
}
}
// return new CommandResponse ("You entered the attack command");
}
}
import mazegame.entity.Player;
/**
* Created by sola2 on 1/06/2017.
*/
public class PotionCommand implements Command {
@Override
public CommandResponse execute(ParsedInput userInput, Player thePlayer) {
if(thePlayer.getPotions() == 0){
return new CommandResponse("You do not have any more potions!");
}
else{
thePlayer.setLifePoints(thePlayer.getLifePoints() + 10);
thePlayer.usePotions();
System.out.println("You use a potion to restore 10 life points!");
return new CommandResponse("Your current life point: " +
thePlayer.getLifePoints());
}
}
}
11
ITECH7201 Software Engineering: Analysis and Design Assignment 2
Test section:
Test with Junit4 based on the Junit framework.
Test item:
lookCommand class and attackCommand class in control package.
Operation process:
In the same package, selected the chosen class, right click and choose new test class, input
test condition preset code in the setup method of @before identification, such as set the
location, player, command. test methods corresponding to the class under test method in the
input identification method of @test, finally,through running those test classes, in test
interface we can see the relevant test result.
Test code:
LookCommand:
package mazegame.control;
@Before
public void setUp() throws Exception {
playerInput = new ParsedInput("look", argument1);
thePlayer = new Player("tester");
location2 = new Location("a lecture room", "Room202");
12
ITECH7201 Software Engineering: Analysis and Design Assignment 2
@Test
public void testlookifNoA() {
assertSame(location2, thePlayer.getCurrentLocation());
CommandResponse response = lookcommand.execute(playerInput, thePlayer);
assertFalse(response.isFinishedGame());
assertTrue(response.getMessage().contains(location2.getDescription()));
@Test
public void testlookifcannotfind(){
argument1.add("randomletterfortest");
playerInput.setArguments(argument1);
CommandResponse response = lookcommand.execute(playerInput, thePlayer);
assertFalse(response.isFinishedGame());
assertTrue(response.getMessage().contains("Can't find that to look at here!"));
}
@Test
public void testlookiflookatNorth()
{
argument1.add("north");
playerInput.setArguments(argument1);
CommandResponse response = lookcommand.execute(playerInput, thePlayer);
assertFalse(response.isFinishedGame());
assertTrue(response.getMessage().contains(northExit.getDescription()));
}
@Test
public void TestLookHandler()
{
AttackCommand:
package mazegame.control;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import junit.framework.Assert;
import mazegame.control.*;
import mazegame.entity.*;
public class AttackCommandTest {
private ParsedInput playerInput;
13
ITECH7201 Software Engineering: Analysis and Design Assignment 2
@Before
public void setUp() throws Exception {
playerInput = new ParsedInput("attack", argument1);
thePlayer = new Player("tester");
location2 = new Location("a lecture room", "Room202");
Location testarea = new Location("this place is used for test", "testarea");
northExit = new Exit("you see a mound of paper to the south", testarea);
location2.getExitCollection().addExit("north", northExit);
thePlayer.setCurrentLocation(location2);
handler = new CommandHandler();
attack =new AttackCommand();
}
@Test
public void testifNoTarget() {
location2.setupNpc(null, 0);
CommandResponse response = attack.execute(playerInput, thePlayer);
assertFalse(response.isFinishedGame());
assertTrue(response.getMessage().contains("Nobody is here!"));
}
@Test
public void testifnohostile(){
location2.setupNpc("Iamnotenemy",20);
argument1.add("Iamnotenemy");
CommandResponse response = attack.execute(playerInput, thePlayer);
assertFalse(response.isFinishedGame());
assertTrue(response.getMessage().contains((thePlayer.getCurrentLocation().getNpc().getName(
) + " is not a hostile!")));
}
@Test
public void testifhostile(){
location2.setupNpc("PleaseHitme",20,"hostile");
argument1.add("PleaseHitme");
CommandResponse response = attack.execute(playerInput, thePlayer);
}
@Test
public void testifplayerdied(){
14
ITECH7201 Software Engineering: Analysis and Design Assignment 2
location2.setupNpc("PleaseHitme",100,"hostile");
argument1.add("PleaseHitme");
CommandResponse response = attack.execute(playerInput, thePlayer);
assertTrue(response.getMessage().contains("You died!"));
}
}
Test result:
lookCommand:
According to the picture ,4 test methods have been run,there is no error in the test
methods, and all the method passed.It means lookMethod Class is no issues.
Attackmethod:
According to the picture ,5 test methods have been run,there is no error in the test
methods, 3 test methods passed and 2 test methods failed. The failed method is testifhostile
and testifNobody. The type of failed is assrtionError, this may be due to the fact that the
statement of conditional judgment is not valid and that the problem is caused by nonstandard
output.
15
ITECH7201 Software Engineering: Analysis and Design Assignment 2
16
ITECH7201 Software Engineering: Analysis and Design Assignment 2
ID STORY
002 Look: player can input look command to get information about
the current location, props, information, and directions for
moving
004 Move + direction: player can move to one direction, get the
information about the new place. The system describes the
location of the player movement, and hints at the relevant
operations that player can do, as well as hints about the
direction of the starting central region. If just input
move ,system will ask player which direction he/she will go.
005 Get item: every location may have items on the ground. Player
can pick up it. money also can get as items.
006 List item: player can list all the item he have.
008 Buy item: players can buy some item, like weapon ,if they have
enough money. This command only available in shop.
009 Sell item: players can sell their items. This command only
available in shop.
010 Attack Npc: player can attack NPC when they look at them in
one location. If the type of Npc is not hostile, players can not
attack; if the type of Npc is hostile, player can attack the npc,
a battle description will be showed.
012
013
014
17
ITECH7201 Software Engineering: Analysis and Design Assignment 2
18
ITECH7201 Software Engineering: Analysis and Design Assignment 2
19
ITECH7201 Software Engineering: Analysis and Design Assignment 2
20
ITECH7201 Software Engineering: Analysis and Design Assignment 2
Those two files: HardCodeData.java and SimpleConsoleClient were showed in “All of class in
Lab 7”
21
ITECH7201 Software Engineering: Analysis and Design Assignment 2
22
ITECH7201 Software Engineering: Analysis and Design Assignment 2
23
ITECH7201 Software Engineering: Analysis and Design Assignment 2
24
ITECH7201 Software Engineering: Analysis and Design Assignment 2
25
ITECH7201 Software Engineering: Analysis and Design Assignment 2
26
ITECH7201 Software Engineering: Analysis and Design Assignment 2
27
ITECH7201 Software Engineering: Analysis and Design Assignment 2
28
ITECH7201 Software Engineering: Analysis and Design Assignment 2
References
There is no specific reference in this report.
29