Skip to content

Commit

Permalink
Updated PIT report, class diagram. Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matoking committed Jan 29, 2015
1 parent f744f26 commit de279e9
Show file tree
Hide file tree
Showing 34 changed files with 7,769 additions and 1,842 deletions.
Binary file modified DungeonCrawler/resources/img/floor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions DungeonCrawler/resources/messages/key_pickup.txt
@@ -0,0 +1,14 @@
# This is a comment
# This is a comment as well
# These are all comments
# and
# they
# shouldn't
# show
# up
# in-game!
You picked up a golden key!
You are now in possession of a golden key!
You found a shiny golden key!
You now hold a fancy golden key!
You now have a golden key!
5 changes: 0 additions & 5 deletions DungeonCrawler/resources/text/key_pickup.txt

This file was deleted.

Expand Up @@ -16,8 +16,6 @@ public GameLog(GameState gameState) {
this.gameState = gameState;

this.messages = new ArrayList<String>();

this.messages.add(GameMessages.getGameStartMessage());
}

/**
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void generateMap() {
this.setTile(5, 5, TileType.FLOOR);

int generatedKeys = 0;
while (generatedKeys < 5) {
while (generatedKeys < 1000) {
int x = random.nextInt(length);
int y = random.nextInt(length);

Expand Down
Expand Up @@ -34,12 +34,19 @@ static public String getMessageFromList(String list) {

try {
File file = new File(String.format("%s%s", System.getProperty("user.dir"),
String.format("/resources/text/%s.txt", list)));
String.format("/resources/messages/%s.txt", list)));

Scanner scanner = new Scanner(file);

while (scanner.hasNextLine()) {
String message = scanner.nextLine();

// If the message starts with a #,
// skip it
if (message.charAt(0) == '#') {
continue;
}

messages.add(message);
}

Expand Down
Expand Up @@ -14,6 +14,23 @@ public GameState() {
this.gameLog = new GameLog(this);

this.player = new Player(this.gameMap, 5, 5);

this.startGame();
}

/**
* Starts a new game
*/
public void startGame() {
this.gameMap = null;
this.gameMap = new GameMap(this);

this.player = null;
this.player = new Player(this.gameMap, 5, 5);

this.gameLog.clearMessages();

this.gameLog.addMessage(GameMessages.getGameStartMessage());
}

/**
Expand Down
Expand Up @@ -38,11 +38,6 @@ public boolean move(Direction direction) {
return false;
}

if (newX < 0 || newX > this.gameMap.getWidth()-1 ||
newY < 0 || newY > this.gameMap.getHeight()-1) {
return false;
}

this.x = newX;
this.y = newY;

Expand Down
@@ -0,0 +1,66 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.matoking.dungeoncrawler.state;

import java.util.ArrayList;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author matoking
*/
public class GameLogTest {
public GameLog gameLog;

public GameLogTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
this.gameLog = new GameLog(new GameState());
}

@After
public void tearDown() {
}

@Test
public void testLogsCreatedCorrectly() {
this.gameLog.addMessage("Test message One");
this.gameLog.addMessage("Test message Two");

ArrayList<String> messages = this.gameLog.getMessages();

assertEquals(messages.get(0), "Test message One");
assertEquals(messages.get(1), "Test message Two");
}

@Test
public void testLogsTruncatedCorrectly() {
for (int i=0; i < 25; i++) {
this.gameLog.addMessage(String.format("%d", i));
}

ArrayList<String> messages = this.gameLog.getMessages();

assertEquals(messages.get(0), "5");
assertEquals(messages.get(19), "24");
}

}
Expand Up @@ -5,6 +5,7 @@
*/
package com.matoking.dungeoncrawler.state;

import com.matoking.dungeoncrawler.state.entities.Key;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -17,7 +18,7 @@
* @author matoking
*/
public class GameMapTest {

public GameState gameState;
public GameMap gameMap;

public GameMapTest() {
Expand All @@ -33,7 +34,8 @@ public static void tearDownClass() {

@Before
public void setUp() {
this.gameMap = new GameMap();
this.gameState = new GameState();
this.gameMap = this.gameState.getGameMap();

this.gameMap.isTileBlocked(0, 0);
}
Expand Down Expand Up @@ -91,4 +93,46 @@ public void testNullReturnedOnInvalidTile() {

assertEquals(null, this.gameMap.getTile(this.gameMap.getWidth(), this.gameMap.getHeight()));
}

@Test
public void testGetEntitiesWorksCorrectly() {
this.gameMap.addEntity(new Key(this.gameState, 0, 5));
this.gameMap.addEntity(new Key(this.gameState, 2, 5));
this.gameMap.addEntity(new Key(this.gameState, 4, 6));

assertEquals(this.gameMap.getEntities().size(), 3);
}

@Test
public void testGetEntitiesAtReturnsCorrectEntities() {
this.gameMap.addEntity(new Key(this.gameState, 10, 10));
this.gameMap.addEntity(new Key(this.gameState, 10, 10));

this.gameMap.addEntity(new Key(this.gameState, 20, 25));
this.gameMap.addEntity(new Key(this.gameState, 20, 25));
this.gameMap.addEntity(new Key(this.gameState, 20, 25));
this.gameMap.addEntity(new Key(this.gameState, 20, 25));
this.gameMap.addEntity(new Key(this.gameState, 20, 25));


assertEquals(this.gameMap.getEntitiesAt(10, 10).size(), 2);
assertEquals(this.gameMap.getEntitiesAt(20, 25).size(), 5);
}

@Test
public void testRemoveEntityWorksCorrectly() {
Key keyOne = new Key(this.gameState, 5, 5);
Key keyTwo = new Key(this.gameState, 5, 5);

this.gameMap.addEntity(keyOne);
this.gameMap.addEntity(keyTwo);

assertEquals(true, this.gameMap.getEntities().contains(keyOne));
assertEquals(true, this.gameMap.getEntities().contains(keyTwo));

this.gameMap.removeEntity(keyOne);

assertEquals(false, this.gameMap.getEntities().contains(keyOne));
assertEquals(true, this.gameMap.getEntities().contains(keyTwo));
}
}
Expand Up @@ -5,6 +5,7 @@
*/
package com.matoking.dungeoncrawler.state;

import com.matoking.dungeoncrawler.state.entities.Key;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -49,4 +50,33 @@ public void testPlayerCreatedWithinMapBoundaries() {
this.gameState.getPlayer().getY() < this.gameState.getGameMap().getHeight());
}

@Test
public void testStartGameClearsLog() {
this.gameState.startGame();

this.gameState.getGameLog().addMessage("aaa");
this.gameState.getGameLog().addMessage("aaa");
this.gameState.getGameLog().addMessage("aaa");

this.gameState.startGame();

// When game is started, game log should have only one message
assertEquals(this.gameState.getGameLog().getMessages().size(), 1);
}

@Test
public void playerInteractsWithNonSolidEntity() {
this.gameState.getPlayer().setX(5);
this.gameState.getPlayer().setY(5);

this.gameState.getGameMap().addEntity(new Key(this.gameState, 5, 6));

assertEquals(this.gameState.getPlayer().getKeys(), 0);

this.gameState.performMove(Direction.DOWN);

assertEquals(this.gameState.getGameMap().getEntities().size(), 0);
assertEquals(this.gameState.getPlayer().getKeys(), 1);
}

}
Expand Up @@ -17,7 +17,7 @@
* @author matoking
*/
public class PlayerTest {

public GameState gameState;
public GameMap gameMap;
public Player player;

Expand All @@ -34,7 +34,8 @@ public static void tearDownClass() {

@Before
public void setUp() {
this.gameMap = new GameMap();
this.gameState = new GameState();
this.gameMap = this.gameState.getGameMap();

this.player = new Player(this.gameMap, 5, 5);
}
Expand Down
1 change: 1 addition & 0 deletions docs/.~lock.ClassDiagram.odt#
@@ -0,0 +1 @@
,matoking,matoking-Z87-HD3,29.01.2015 17:07,file:///home/matoking/.config/libreoffice/4;
Binary file modified docs/ClassDiagram.odt
Binary file not shown.
Binary file modified docs/ClassDiagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de279e9

Please sign in to comment.