Skip to content

Commit

Permalink
Started coursework
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-meades committed Feb 28, 2020
1 parent 7bed05e commit 1cfce8f
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 15 deletions.
File renamed without changes.
10 changes: 10 additions & 0 deletions Assignments/04-Stag/.idea/libraries/libs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Assignments/04-Stag/04-Stag.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/src/libs/dot-parser.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/src/libs/json-parser.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="libs" level="project" />
</component>
</module>
Binary file added Assignments/04-Stag/instructions.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions Assignments/04-Stag/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
default: build

build:
javac -classpath ./libs/dot-parser.jar:./libs/json-parser.jar:. StagServer.java

run: build
java -classpath ./libs/dot-parser.jar:./libs/json-parser.jar:. StagServer data/entities.dot data/actions.json

clean:
rm *.class
36 changes: 36 additions & 0 deletions Assignments/04-Stag/src/ParserClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;

import com.alexmerz.graphviz.ParseException;
import com.alexmerz.graphviz.Parser;
import com.alexmerz.graphviz.objects.Edge;
import com.alexmerz.graphviz.objects.Graph;
import com.alexmerz.graphviz.objects.Id;
import com.alexmerz.graphviz.objects.Node;

public class ParserClass {

public static void main(String[] args) {
FileReader in=null;
File f = new File( "C:\\Users\\Matt\\Documents\\CompSciLinux\\Java\\Assignments\\04-Stag\\src\\data/entities.dot" );

try {
in = new FileReader(f);
Parser p = new Parser();
p.parse(in);
} catch (FileNotFoundException e) {
System.out.println();
} catch (ParseException e) {
// do something if the parser caused a parser error
}

// everything ok
ArrayList<Graph> gl = p.getGraphs();

// do something with the Graph objects
}
}

Binary file added Assignments/04-Stag/src/StagClient.class
Binary file not shown.
35 changes: 35 additions & 0 deletions Assignments/04-Stag/src/StagClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.*;
import java.net.*;

public class StagClient
{
public static void main(String args[])
{
if(args.length != 1) System.out.println("Usage: java StageClient <player-name>");
else {
String playerName = args[0];
BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
while(true) handleNextCommand(commandLine, playerName);
}
}

private static void handleNextCommand(BufferedReader commandLine, String playerName)
{
try {
String incoming;
System.out.print("\n" + playerName + ": ");
String command = commandLine.readLine();
Socket socket = new Socket("127.0.0.1", 8888);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.write(playerName + ": " + command + "\n");
out.flush();
while((incoming = in.readLine()) != null) System.out.println(incoming);
in.close();
out.close();
socket.close();
} catch(IOException ioe) {
System.out.println(ioe);
}
}
}
Binary file added Assignments/04-Stag/src/StagServer.class
Binary file not shown.
45 changes: 45 additions & 0 deletions Assignments/04-Stag/src/StagServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.io.*;
import java.net.*;
import java.util.*;

class StagServer
{
public static void main(String args[])
{
if(args.length != 2) System.out.println("Usage: java StagServer <entity-file> <action-file>");
else new StagServer(args[0], args[1], 8888);
}

public StagServer(String entityFilename, String actionFilename, int portNumber)
{
try {
ServerSocket ss = new ServerSocket(portNumber);
System.out.println("Server Listening");
while(true) acceptNextConnection(ss);
} catch(IOException ioe) {
System.err.println(ioe);
}
}

private void acceptNextConnection(ServerSocket ss)
{
try {
// Next line will block until a connection is received
Socket socket = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
processNextCommand(in, out);
out.close();
in.close();
socket.close();
} catch(IOException ioe) {
System.err.println(ioe);
}
}

private void processNextCommand(BufferedReader in, BufferedWriter out) throws IOException
{
String line = in.readLine();
out.write("You said... " + line + "\n");
}
}
Binary file added Assignments/04-Stag/src/data/.DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions Assignments/04-Stag/src/data/actions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"actions": [

{
"triggers": ["open", "unlock"],
"subjects": ["door", "key"],
"consumed": ["key"],
"produced": ["cellar"],
"narration": "You unlock the door and see steps leading down into a cellar"
},

{
"triggers": ["chop", "cut", "cutdown"],
"subjects": ["tree", "axe"],
"consumed": ["tree"],
"produced": ["log"],
"narration": "You cut down the tree with the axe"
},

{
"triggers": ["drink"],
"subjects": ["potion"],
"consumed": ["potion"],
"produced": ["health"],
"narration": "You drink the potion and your health improves"
},

{
"triggers": ["fight", "hit", "punch", "kick", "slap", "attack", "kill"],
"subjects": ["elf"],
"consumed": ["health"],
"produced": [],
"narration": "You attack the elf, but he fights back and you lose some health"
}
]
}
45 changes: 45 additions & 0 deletions Assignments/04-Stag/src/data/entities.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
digraph layout {
/* ortho splines just makes the arrows into straight lines (rather than curvy ones !) */
splines = ortho;
node [shape = "rect"];

subgraph locations {
subgraph cluster001 {
node [shape = "none"];
start [description = "An empty room"];
subgraph artefacts {
node [shape = "diamond"];
potion [description = "Magic potion"];
}
subgraph furniture {
node [shape = "hexagon"];
door [description = "Wooden door"];
}
}

subgraph cluster002 {
node [shape = "none"];
forest [description = "A dark forest"];
subgraph artefacts {
node [shape = "diamond"];
key [description = "Brass key"];
}
}

subgraph cluster003 {
node [shape = "none"];
cellar [description = "A dusty cellar"]
subgraph characters {
node [shape = "ellipse"];
elf [description = "Angry Elf"];
}
}
}

subgraph paths {
start -> forest;
forest -> start;
cellar -> start;
}

}
Binary file added Assignments/04-Stag/src/data/entities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assignments/04-Stag/src/libs/dot-parser.jar
Binary file not shown.
Binary file added Assignments/04-Stag/src/libs/json-parser.jar
Binary file not shown.
1 change: 1 addition & 0 deletions Personal/Game1/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1cfce8f

Please sign in to comment.