();
- private Printing print = new Printing();
public GameServer(Game game) {
this.setGame(game);
@@ -41,47 +43,41 @@ public void run() {
socket.receive(packet);
} catch (IOException e) {
e.printStackTrace();
+ break;
}
- this.parsePacket(packet.getData(), packet.getAddress(),
- packet.getPort());
+ this.parsePacket(packet.getData(), packet.getAddress(), packet.getPort());
- // String message = new String(packet.getData());
- // System.out.println("CLIENT ["+packet.getAddress().getHostAddress()+":"+packet.getPort()+"] "+message);
- // if(message.trim().equalsIgnoreCase("ping")){
- // sendData("pong".getBytes(), packet.getAddress(),
- // packet.getPort());
- // }
+ String message = new String(packet.getData());
+ System.out.println("CLIENT [" + packet.getAddress().getHostAddress() + ":" + packet.getPort() + "] " + message);
+ if (message.trim().equalsIgnoreCase("ping")) {
+ sendData("pong".getBytes(), packet.getAddress(), packet.getPort());
+ }
}
}
private void parsePacket(byte[] data, InetAddress address, int port) {
String message = new String(data).trim();
PacketTypes type = Packet.lookupPacket(message.substring(0, 2));
- Packet packet = null;
+ Packet packet;
switch (type) {
- default:
- case INVALID:
- break;
- case LOGIN:
- packet = new Packet00Login(data);
- print.print("[" + address.getHostAddress() + ":" + port
- + "] " + ((Packet00Login) packet).getUsername()
- + " has connected...", PrintTypes.SERVER);
- PlayerMP player = new PlayerMP(Game.getLevel(), 10, 10,
- ((Packet00Login) packet).getUsername(), address, port, Game.getShirtCol(), Game.getFaceCol());
- this.addConnection(player, (Packet00Login) packet);
- break;
- case DISCONNECT:
- packet = new Packet01Disconnect(data);
- print.print("[" + address.getHostAddress() + ":" + port
- + "] " + ((Packet01Disconnect) packet).getUsername()
- + " has disconnected...", PrintTypes.SERVER);
- this.removeConnection((Packet01Disconnect) packet);
- break;
- case MOVE:
- packet = new Packet02Move(data);
- this.handleMove(((Packet02Move) packet));
+ default:
+ case INVALID:
+ break;
+ case LOGIN:
+ packet = new Packet00Login(data);
+ print.print("[" + address.getHostAddress() + ":" + port + "] " + ((Packet00Login) packet).getUsername() + " has connected...", PrintTypes.SERVER);
+ PlayerMP player = new PlayerMP(Game.getLevel(), 10, 10, ((Packet00Login) packet).getUsername(), address, port, Game.getShirtCol(), Game.getFaceCol());
+ this.addConnection(player, (Packet00Login) packet);
+ break;
+ case DISCONNECT:
+ packet = new Packet01Disconnect(data);
+ print.print("[" + address.getHostAddress() + ":" + port + "] " + ((Packet01Disconnect) packet).getUsername() + " has disconnected...", PrintTypes.SERVER);
+ this.removeConnection((Packet01Disconnect) packet);
+ break;
+ case MOVE:
+ packet = new Packet02Move(data);
+ this.handleMove(((Packet02Move) packet));
}
}
@@ -102,8 +98,8 @@ public void addConnection(PlayerMP player, Packet00Login packet) {
boolean alreadyConnected = false;
for (PlayerMP p : this.connectedPlayers) {
if (player.getUsername().equalsIgnoreCase(p.getUsername())) {
- if (p.ipAddess == null) {
- p.ipAddess = player.ipAddess;
+ if (p.ipAddress == null) {
+ p.ipAddress = player.ipAddress;
}
if (p.port == -1) {
@@ -112,10 +108,10 @@ public void addConnection(PlayerMP player, Packet00Login packet) {
alreadyConnected = true;
} else {
- sendData(packet.getData(), p.ipAddess, p.port);
+ sendData(packet.getData(), p.ipAddress, p.port);
packet = new Packet00Login(p.getUsername(), (int) p.getX(), (int) p.getY());
- sendData(packet.getData(), player.ipAddess, player.port);
+ sendData(packet.getData(), player.ipAddress, player.port);
}
}
if (!alreadyConnected) {
@@ -150,8 +146,7 @@ public int getPlayerMPIndex(String username) {
}
public void sendData(byte[] data, InetAddress ipAddress, int port) {
- DatagramPacket packet = new DatagramPacket(data, data.length,
- ipAddress, port);
+ DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, port);
try {
this.socket.send(packet);
} catch (IOException e) {
@@ -161,7 +156,7 @@ public void sendData(byte[] data, InetAddress ipAddress, int port) {
public void sendDataToAllClients(byte[] data) {
for (PlayerMP p : connectedPlayers) {
- sendData(data, p.ipAddess, p.port);
+ sendData(data, p.ipAddress, p.port);
}
}
diff --git a/src/com/redomar/game/net/packets/Packet.java b/src/com/redomar/game/net/packets/Packet.java
index 743784f..938c085 100644
--- a/src/com/redomar/game/net/packets/Packet.java
+++ b/src/com/redomar/game/net/packets/Packet.java
@@ -3,39 +3,15 @@
import com.redomar.game.net.GameClient;
import com.redomar.game.net.GameServer;
+@Deprecated
public abstract class Packet {
- public static enum PacketTypes {
- INVALID(-1), LOGIN(00), DISCONNECT(01), MOVE(02);
-
- private int packetId;
-
- private PacketTypes(int packetId) {
- this.packetId = packetId;
- }
-
- public int getId() {
- return packetId;
- }
- }
-
public byte packetId;
public Packet(int packetId) {
this.packetId = (byte) packetId;
}
- public abstract byte[] getData();
-
- public abstract void writeData(GameClient client);
-
- public abstract void writeData(GameServer server);
-
- public String readData(byte[] data) {
- String message = new String(data).trim();
- return message.substring(2);
- }
-
public static PacketTypes lookupPacket(String packetId) {
try {
return lookupPacket(Integer.parseInt(packetId));
@@ -52,4 +28,29 @@ public static PacketTypes lookupPacket(int id) {
}
return PacketTypes.INVALID;
}
+
+ public abstract byte[] getData();
+
+ public abstract void writeData(GameClient client);
+
+ public abstract void writeData(GameServer server);
+
+ public String readData(byte[] data) {
+ String message = new String(data).trim();
+ return message.substring(2);
+ }
+
+ public enum PacketTypes {
+ INVALID(-1), LOGIN(0x00), DISCONNECT(0x01), MOVE(0x02);
+
+ private final int packetId;
+
+ PacketTypes(int packetId) {
+ this.packetId = packetId;
+ }
+
+ public int getId() {
+ return packetId;
+ }
+ }
}
diff --git a/src/com/redomar/game/net/packets/Packet00Login.java b/src/com/redomar/game/net/packets/Packet00Login.java
index 4e61dc4..6382b83 100644
--- a/src/com/redomar/game/net/packets/Packet00Login.java
+++ b/src/com/redomar/game/net/packets/Packet00Login.java
@@ -3,13 +3,15 @@
import com.redomar.game.net.GameClient;
import com.redomar.game.net.GameServer;
+@Deprecated
public class Packet00Login extends Packet {
- private String username;
- private int x, y;
+ private final String username;
+ private final int x;
+ private final int y;
public Packet00Login(byte[] data) {
- super(00);
+ super(0x00);
String[] dataArray = readData(data).split(",");
this.username = dataArray[0];
this.x = Integer.parseInt(dataArray[1]);
@@ -17,7 +19,7 @@ public Packet00Login(byte[] data) {
}
public Packet00Login(String username, int x, int y) {
- super(00);
+ super(0x00);
this.username = username;
this.x = x;
this.y = y;
diff --git a/src/com/redomar/game/net/packets/Packet01Disconnect.java b/src/com/redomar/game/net/packets/Packet01Disconnect.java
index d95eec5..4ac5e20 100644
--- a/src/com/redomar/game/net/packets/Packet01Disconnect.java
+++ b/src/com/redomar/game/net/packets/Packet01Disconnect.java
@@ -3,17 +3,18 @@
import com.redomar.game.net.GameClient;
import com.redomar.game.net.GameServer;
+@Deprecated
public class Packet01Disconnect extends Packet {
- private String username;
+ private final String username;
public Packet01Disconnect(byte[] data) {
- super(01);
+ super(0x01);
this.username = readData(data);
}
public Packet01Disconnect(String username) {
- super(01);
+ super(0x01);
this.username = username;
}
diff --git a/src/com/redomar/game/net/packets/Packet02Move.java b/src/com/redomar/game/net/packets/Packet02Move.java
index cff6c14..1336ee0 100644
--- a/src/com/redomar/game/net/packets/Packet02Move.java
+++ b/src/com/redomar/game/net/packets/Packet02Move.java
@@ -3,16 +3,18 @@
import com.redomar.game.net.GameClient;
import com.redomar.game.net.GameServer;
+@Deprecated
public class Packet02Move extends Packet {
- private String username;
- private int x, y;
- private int numSteps = 0;
- private boolean isMoving;
- private int movingDir = 1;
+ private final String username;
+ private final int x;
+ private final int y;
+ private final int numSteps;
+ private final boolean isMoving;
+ private final int movingDir;
public Packet02Move(byte[] data) {
- super(02);
+ super(0x02);
String[] dataArray = readData(data).split(",");
this.username = dataArray[0];
this.x = Integer.parseInt(dataArray[1]);
@@ -22,9 +24,8 @@ public Packet02Move(byte[] data) {
this.movingDir = Integer.parseInt(dataArray[5]);
}
- public Packet02Move(String username, int x, int y, int numSteps,
- boolean isMoving, int movingDir) {
- super(02);
+ public Packet02Move(String username, int x, int y, int numSteps, boolean isMoving, int movingDir) {
+ super(0x02);
this.username = username;
this.x = x;
this.y = y;
@@ -35,9 +36,7 @@ public Packet02Move(String username, int x, int y, int numSteps,
@Override
public byte[] getData() {
- return ("02" + this.username + "," + this.x + "," + this.y + ","
- + this.getNumSteps() + "," + (this.isMoving ? 1 : 0) + "," + this
- .getMovingDir()).getBytes();
+ return ("02" + this.username + "," + this.x + "," + this.y + "," + this.getNumSteps() + "," + (this.isMoving ? 1 : 0) + "," + this.getMovingDir()).getBytes();
}
@Override
diff --git a/src/com/redomar/game/objects/Inventory.java b/src/com/redomar/game/objects/Inventory.java
index ad181a5..96a24e1 100644
--- a/src/com/redomar/game/objects/Inventory.java
+++ b/src/com/redomar/game/objects/Inventory.java
@@ -10,7 +10,7 @@ public class Inventory {
public static boolean closing;
public static boolean reset;
public static boolean enabled;
- private static InventoryWindow inv_window = new InventoryWindow();
+ private static final InventoryWindow inv_window = new InventoryWindow();
public static void activate() {
x = (int) Game.getPlayer().getX();
@@ -20,17 +20,14 @@ public static void activate() {
if (enabled) {
if (!open) {
if (!closing) {
- System.out.println("Opened\nInside this Bag their is:"
- + inside());
+ System.out.println("Opened\nInside this Bag their is:" + inside());
open = true;
Game.getPlayer().setMoving(false);
- Game.getInput().untoggle(true);
inv_window.start();
}
} else {
if (closing) {
Game.getPlayer().setMoving(true);
- Game.getInput().untoggle(false);
inv_window.stop();
inv_window.getFrame().setVisible(false);
inv_window.getFrame().stopFrame();
@@ -42,7 +39,7 @@ public static void activate() {
}
}
} else {
- if (open == true || reset == true || closing == true) {
+ if (open || reset || closing) {
reset = false;
open = false;
closing = false;
@@ -53,7 +50,7 @@ public static void activate() {
private static String inside() {
String items = " ";
for (Items item : Items.values()) {
- items = items + item.toString() + ", ";
+ items = String.format("%s%s, ", items, item.toString());
}
return items;
}
diff --git a/src/com/redomar/game/objects/InventoryHandler.java b/src/com/redomar/game/objects/InventoryHandler.java
index 7ee22ca..e7b1cdd 100644
--- a/src/com/redomar/game/objects/InventoryHandler.java
+++ b/src/com/redomar/game/objects/InventoryHandler.java
@@ -1,28 +1,24 @@
package com.redomar.game.objects;
+import com.redomar.game.menu.DedicatedJFrame;
+
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
-import com.redomar.game.menu.DedicatedJFrame;
-
public class InventoryHandler implements WindowListener {
-
- @SuppressWarnings("unused")
- private DedicatedJFrame frame;
-
+
public InventoryHandler(DedicatedJFrame frame) {
- this.frame = frame;
DedicatedJFrame.getFrameStatic().addWindowListener(this);
}
@Override
public void windowActivated(WindowEvent e) {
-
+
}
@Override
public void windowClosed(WindowEvent e) {
-
+
}
public void windowClosing(WindowEvent e) {
@@ -32,22 +28,22 @@ public void windowClosing(WindowEvent e) {
@Override
public void windowDeactivated(WindowEvent e) {
-
+
}
@Override
public void windowDeiconified(WindowEvent e) {
-
+
}
@Override
public void windowIconified(WindowEvent e) {
-
+
}
@Override
public void windowOpened(WindowEvent e) {
-
+
}
}
diff --git a/src/com/redomar/game/objects/InventoryWindow.java b/src/com/redomar/game/objects/InventoryWindow.java
index 617f127..94d7d45 100644
--- a/src/com/redomar/game/objects/InventoryWindow.java
+++ b/src/com/redomar/game/objects/InventoryWindow.java
@@ -1,33 +1,40 @@
package com.redomar.game.objects;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.image.BufferStrategy;
-
import com.redomar.game.menu.DedicatedJFrame;
-public class InventoryWindow implements Runnable{
+import java.awt.*;
+import java.awt.image.BufferStrategy;
+
+public class InventoryWindow implements Runnable {
private static final int WIDTH = 160;
private static final int HEIGHT = (WIDTH / 3 * 2);
private static final int SCALE = 2;
private static final String NAME = "Inventory";
-
+
private static boolean running = false;
-
+
private static DedicatedJFrame frame;
private static InventoryHandler window;
- public synchronized void start(){
+ public static InventoryHandler getWindow() {
+ return window;
+ }
+
+ public static void setWindow(InventoryHandler inventoryHandler) {
+ InventoryWindow.window = inventoryHandler;
+ }
+
+ public synchronized void start() {
running = true;
setFrame(new DedicatedJFrame(WIDTH, HEIGHT, SCALE, NAME));
new Thread(this, NAME).start();
}
-
- public synchronized void stop(){
+
+ public synchronized void stop() {
running = false;
}
-
+
public void run() {
long lastTime = System.nanoTime();
double nsPerTick = 1000000000D / 30D;
@@ -37,8 +44,8 @@ public void run() {
long lastTimer = System.currentTimeMillis();
double delta = 0;
-
- setWindow(new InventoryHandler(getFrame()));
+
+ setWindow(new InventoryHandler(frame));
while (running) {
long now = System.nanoTime();
@@ -65,24 +72,23 @@ public void run() {
if (System.currentTimeMillis() - lastTimer >= 1000) {
lastTimer += 1000;
- getFrame().getFrame().setTitle(
- "Frames: " + frames + " Ticks: " + ticks);
+ frame.getFrame().setTitle("Frames: " + frames + " Ticks: " + ticks);
frames = 0;
ticks = 0;
}
}
}
-
+
private void render() {
- BufferStrategy bs = getFrame().getBufferStrategy();
- if(bs == null){
- getFrame().createBufferStrategy(3);
+ BufferStrategy bs = frame.getBufferStrategy();
+ if (bs == null) {
+ frame.createBufferStrategy(3);
return;
}
-
+
Graphics g = bs.getDrawGraphics();
g.setColor(Color.BLACK);
- g.fillRect(0, 0, WIDTH*SCALE+10, HEIGHT*SCALE+10);
+ g.fillRect(0, 0, WIDTH * SCALE + 10, HEIGHT * SCALE + 10);
g.setColor(Color.WHITE);
g.drawString(NAME, 50, 50);
bs.show();
@@ -96,12 +102,4 @@ public DedicatedJFrame getFrame() {
public static void setFrame(DedicatedJFrame frame) {
InventoryWindow.frame = frame;
}
-
- public static InventoryHandler getWindow() {
- return window;
- }
-
- public static void setWindow(InventoryHandler inventoryHandler) {
- InventoryWindow.window = inventoryHandler;
- }
}
diff --git a/src/com/redomar/game/objects/Items.java b/src/com/redomar/game/objects/Items.java
index f7b5fc8..55f705a 100644
--- a/src/com/redomar/game/objects/Items.java
+++ b/src/com/redomar/game/objects/Items.java
@@ -1,9 +1,5 @@
package com.redomar.game.objects;
public enum Items {
-
- Stick,
- Torch,
- Sword,
- Apple;
+ Stick, Torch, Sword, Apple
}
diff --git a/src/com/redomar/game/scenes/Scene.java b/src/com/redomar/game/scenes/Scene.java
new file mode 100644
index 0000000..2b869c6
--- /dev/null
+++ b/src/com/redomar/game/scenes/Scene.java
@@ -0,0 +1,38 @@
+package com.redomar.game.scenes;
+
+import com.redomar.game.gfx.Screen;
+import com.redomar.game.level.LevelHandler;
+
+public class Scene {
+
+ private int xOffset, yOffset;
+ private final Screen screen;
+ private final LevelHandler level;
+
+ public Scene(int xOffset, int yOffset, Screen screen, LevelHandler level) {
+ this.xOffset = xOffset;
+ this.yOffset = yOffset;
+ this.screen = screen;
+ this.level = level;
+ }
+
+ public void playerScene() {
+ if (xOffset < 0) {
+ xOffset = 0;
+ }
+ if (xOffset > ((level.getWidth() << 10) - screen.getWidth())) {
+ xOffset = ((level.getWidth() << 30) - screen.getWidth());
+ }
+ if (yOffset < 0) {
+ yOffset = 0;
+ }
+ if (yOffset > ((level.getHeight() << 3) - screen.getHeight())) {
+ yOffset = ((level.getHeight() << 3) - screen.getHeight());
+ }
+ for (int y = (yOffset >> 3); y < (yOffset + screen.getHeight() >> 3) + 1; y++) {
+ for (int x = (xOffset >> 3); x < (xOffset + screen.getWidth() >> 3) + 1; x++) {
+ level.getTile(x, y).render(screen, level, x << 3, y << 3);
+ }
+ }
+ }
+}
diff --git a/src/com/redomar/game/script/PrintTypes.java b/src/com/redomar/game/script/PrintTypes.java
deleted file mode 100644
index 7eb2395..0000000
--- a/src/com/redomar/game/script/PrintTypes.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.redomar.game.script;
-
-public enum PrintTypes {
-
- GAME,
- MUSIC,
- ERROR,
- NETWORK,
- SERVER;
-}
diff --git a/src/com/redomar/game/script/Printing.java b/src/com/redomar/game/script/Printing.java
deleted file mode 100644
index 51eca0b..0000000
--- a/src/com/redomar/game/script/Printing.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.redomar.game.script;
-
-import com.redomar.game.lib.Time;
-import com.redomar.game.script.PrintTypes;
-
-public class Printing {
-
- private PrintTypes type;
- private Time time = new Time();
- private String message;
-
- public Printing() {
-
- }
-
- public void print(String message, PrintTypes type) {
- this.type = type;
- setMessage(message);
- printOut();
- }
-
- private void printOut(){
- String msgTime = "[" + time.getTime() + "]";
- String msgType = "[" + type.toString() + "]";
- System.out.println(msgType + msgTime + getMessage());
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-}
diff --git a/test/com/redomar/game/audio/AudioHandlerTest.java b/test/com/redomar/game/audio/AudioHandlerTest.java
new file mode 100644
index 0000000..c17faa7
--- /dev/null
+++ b/test/com/redomar/game/audio/AudioHandlerTest.java
@@ -0,0 +1,43 @@
+package com.redomar.game.audio;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by Mohamed on 28/08/2016.
+ * This file tests the com.redomar.game.audio.AudioHandler class
+ */
+public class AudioHandlerTest {
+
+ @Before
+ public void before() {
+ AudioHandler.musicPrinter.mute();
+ }
+
+ @Test
+ public void bgMusicExists() {
+ File sfx = new File("res/music/Towards The End.mp3");
+ assertTrue(sfx.exists());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void expectReturnExceptionFileEmptyDir() {
+ File empty = new File("");
+ new AudioHandler(empty);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void expectReturnExceptionFileEmptyPath() {
+ new AudioHandler("");
+ }
+
+ @Test()
+ public void tryInitiatingAndPlayingNonExistingFile() {
+ new AudioHandler("//").play();
+ }
+
+}
\ No newline at end of file
diff --git a/test/com/redomar/game/lib/HashTest.java b/test/com/redomar/game/lib/HashTest.java
new file mode 100644
index 0000000..bb5055d
--- /dev/null
+++ b/test/com/redomar/game/lib/HashTest.java
@@ -0,0 +1,64 @@
+package com.redomar.game.lib;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class HashTest {
+
+ private HashGen hashGen;
+
+ @Before
+ public void setUp() throws Exception{
+ hashGen = new HashGen(false,10);
+ }
+
+ @Test
+ public void hashNotEmpty(){
+ assertNotNull(hashGen.getHash());
+ }
+
+ @Test
+ public void hashZeroLengthNotNull(){
+ HashGen hg = new HashGen(false,0);
+ assertNotNull(hg.getHash());
+ }
+
+ @Test
+ public void compareHashAndPrevious(){
+ hashGen.setHexLength(8);
+ assertEquals(hashGen.getHash(), hashGen.getPreviousHash());
+ }
+
+ @Test
+ public void previousShouldNotGenNewHash(){
+ assertEquals(hashGen.getPreviousHash(), hashGen.getPreviousHash());
+ }
+
+ @Test
+ public void hashLengthEqualsZero(){
+ HashGen hg = new HashGen(false, 0);
+ assertEquals(0,hg.getHash().length());
+ }
+
+ @Test
+ public void hashLengthEqualsGivenLength(){
+ HashGen hg = new HashGen(false, 80);
+ assertEquals(80, hg.getHash().length());
+ }
+
+ @Test
+ public void hashLengthEqualsSetLength(){
+ HashGen hg = new HashGen(false, 80);
+ hg.setHexLength(5);
+ assertEquals(5,hg.getHash().length());
+ }
+
+ @Test
+ public void hashPrefix(){
+ HashGen hg = new HashGen(true,0);
+ assertEquals("0x", hg.getHash());
+ }
+
+}
diff --git a/test/com/redomar/game/log/PopUpTest.java b/test/com/redomar/game/log/PopUpTest.java
new file mode 100644
index 0000000..3ccb68d
--- /dev/null
+++ b/test/com/redomar/game/log/PopUpTest.java
@@ -0,0 +1,23 @@
+package com.redomar.game.log;
+
+import com.redomar.game.menu.PopUp;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class PopUpTest {
+ private PopUp popUp;
+
+ @Before
+ public void setUp() {
+ popUp = new PopUp();
+ popUp.active = false;
+ }
+
+ @Test
+ public void warnIntEfflux() {
+ assertEquals(1, popUp.Warn("TEST"));
+ }
+
+}
diff --git a/test/com/redomar/game/log/PrintToLogTest.java b/test/com/redomar/game/log/PrintToLogTest.java
new file mode 100644
index 0000000..f38dda5
--- /dev/null
+++ b/test/com/redomar/game/log/PrintToLogTest.java
@@ -0,0 +1,28 @@
+package com.redomar.game.log;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by Mohamed on 23/08/2016.
+ *
+ * This file tests the com.redomar.game.script.PrintToLog class
+ */
+public class PrintToLogTest {
+
+ private PrintToLog print;
+
+ @Test(expected = NullPointerException.class)
+ public void PrintToLogNullFile() {
+ print = new PrintToLog(null);
+ }
+
+ @Test
+ public void PrintToLogDoesWork() {
+ print = new PrintToLog(".PrintToLogDoesWork.txt");
+ assertTrue(print.getUrl().exists());
+ assertTrue(print.getUrl().delete());
+ }
+
+}
diff --git a/test/com/redomar/game/log/PrinterTest.java b/test/com/redomar/game/log/PrinterTest.java
new file mode 100644
index 0000000..187f524
--- /dev/null
+++ b/test/com/redomar/game/log/PrinterTest.java
@@ -0,0 +1,48 @@
+package com.redomar.game.log;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by Mohamed on 28/08/2016.
+ * This file tests the com.redomar.game.script.Printing class
+ */
+public class PrinterTest {
+
+ private Printer printer;
+
+ @Before
+ public void setUp() {
+ printer = new Printer();
+ }
+
+ @Test
+ public void printToFileWorks() {
+ printer.print("TESTING STRING", PrintTypes.TEST);
+ File file = new File(".PrintType-TEST.txt");
+ assertTrue(file.exists());
+ assertTrue(file.delete());
+ }
+
+ @Test
+ public void getMessageIsNull() {
+ assertNull(printer.getMessage());
+ }
+
+ @Test
+ public void messageShouldBeNullAfterPrinting() {
+ printer.print("Not Null", PrintTypes.TEST);
+ assertNotNull(printer.getMessage());
+ }
+
+ @After
+ public void cleanUp() {
+ printer = null;
+ }
+
+}
\ No newline at end of file
diff --git a/uml/UML.jpg b/uml/UML.jpg
new file mode 100644
index 0000000..8d2259b
Binary files /dev/null and b/uml/UML.jpg differ