diff --git a/Back end/Client test/Server test/.classpath b/Back end/Client test/Server test/.classpath new file mode 100644 index 00000000..fb501163 --- /dev/null +++ b/Back end/Client test/Server test/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Back end/Client test/Server test/.idea/.gitignore b/Back end/Client test/Server test/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/Back end/Client test/Server test/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Back end/Client test/Server test/.idea/misc.xml b/Back end/Client test/Server test/.idea/misc.xml new file mode 100644 index 00000000..ebe01736 --- /dev/null +++ b/Back end/Client test/Server test/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Back end/Client test/Server test/.idea/modules.xml b/Back end/Client test/Server test/.idea/modules.xml new file mode 100644 index 00000000..115acf5a --- /dev/null +++ b/Back end/Client test/Server test/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Back end/Client test/Server test/.idea/runConfigurations.xml b/Back end/Client test/Server test/.idea/runConfigurations.xml new file mode 100644 index 00000000..797acea5 --- /dev/null +++ b/Back end/Client test/Server test/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Back end/Client test/Server test/.idea/vcs.xml b/Back end/Client test/Server test/.idea/vcs.xml new file mode 100644 index 00000000..c2365ab1 --- /dev/null +++ b/Back end/Client test/Server test/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Back end/Client test/Server test/.project b/Back end/Client test/Server test/.project new file mode 100644 index 00000000..2d4ffe46 --- /dev/null +++ b/Back end/Client test/Server test/.project @@ -0,0 +1,17 @@ + + + Server test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Back end/Client test/Server test/Server test.iml b/Back end/Client test/Server test/Server test.iml new file mode 100644 index 00000000..26db12c9 --- /dev/null +++ b/Back end/Client test/Server test/Server test.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Back end/Client test/Server test/bin/ClientTest/Client.class b/Back end/Client test/Server test/bin/ClientTest/Client.class new file mode 100644 index 00000000..423b1ada Binary files /dev/null and b/Back end/Client test/Server test/bin/ClientTest/Client.class differ diff --git a/Back end/Client test/Server test/bin/ClientTest/QuestionBlock.class b/Back end/Client test/Server test/bin/ClientTest/QuestionBlock.class new file mode 100644 index 00000000..b3301a66 Binary files /dev/null and b/Back end/Client test/Server test/bin/ClientTest/QuestionBlock.class differ diff --git a/Back end/Client test/Server test/src/ClientTest/Client.java b/Back end/Client test/Server test/src/ClientTest/Client.java new file mode 100644 index 00000000..274c078c --- /dev/null +++ b/Back end/Client test/Server test/src/ClientTest/Client.java @@ -0,0 +1,35 @@ +package ClientTest; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.net.Socket; +import java.util.ArrayList; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.net.ServerSocket; +import java.util.Scanner; +public class Client { + + static ArrayList questionBlock = new ArrayList(); + + + public static void main(String[]args) throws IOException, ClassNotFoundException { + String Host = "localhost"; + int port = 9696; + + //Connecting and printing proof + Socket socket = new Socket(Host, port); + DataInputStream input = new DataInputStream(socket.getInputStream()); + System.out.println("Amogus"); + //Function for printing out questions + for(int i = 0; i < 4; i++) { + questionBlock.add(new QuestionBlock(input.readUTF(),input.readUTF(),input.readInt(),input.readInt())); + System.out.println(questionBlock.get(i).toString()); + } + + } + + } + + diff --git a/Back end/Client test/Server test/src/ClientTest/QuestionBlock.java b/Back end/Client test/Server test/src/ClientTest/QuestionBlock.java new file mode 100644 index 00000000..78a21f1f --- /dev/null +++ b/Back end/Client test/Server test/src/ClientTest/QuestionBlock.java @@ -0,0 +1,53 @@ +package ClientTest; + + + public class QuestionBlock { + public String answer; + public String question; + public int value; + public int categoryId; + public boolean notUsed; + + //Constructor of questionBlock + public QuestionBlock(String answer, String question, int value, int categoryId) { + this.answer = answer; + this.question = question; + this.value = value; + this.categoryId = categoryId; + } + + //Getters and Setters + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + @Override + public String toString() { + return "QuestionBlock{" + + "answer='" + answer + '\'' + + ", question='" + question + '\'' + + ", value=" + value + '\'' + + ", categoryId=" + categoryId + '\'' + ; + } + } \ No newline at end of file diff --git a/Back end/MiniprojectServer/.idea/.gitignore b/Back end/MiniprojectServer/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/Back end/MiniprojectServer/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Back end/MiniprojectServer/.idea/misc.xml b/Back end/MiniprojectServer/.idea/misc.xml new file mode 100644 index 00000000..c3dfb300 --- /dev/null +++ b/Back end/MiniprojectServer/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Back end/MiniprojectServer/.idea/modules.xml b/Back end/MiniprojectServer/.idea/modules.xml new file mode 100644 index 00000000..4d9cd6de --- /dev/null +++ b/Back end/MiniprojectServer/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Back end/MiniprojectServer/.idea/runConfigurations.xml b/Back end/MiniprojectServer/.idea/runConfigurations.xml new file mode 100644 index 00000000..797acea5 --- /dev/null +++ b/Back end/MiniprojectServer/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Back end/MiniprojectServer/.idea/vcs.xml b/Back end/MiniprojectServer/.idea/vcs.xml new file mode 100644 index 00000000..b2bdec2d --- /dev/null +++ b/Back end/MiniprojectServer/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Back end/MiniprojectServer/MiniprojectServer.iml b/Back end/MiniprojectServer/MiniprojectServer.iml new file mode 100644 index 00000000..c90834f2 --- /dev/null +++ b/Back end/MiniprojectServer/MiniprojectServer.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Back end/MiniprojectServer/blocksText.xlsx b/Back end/MiniprojectServer/blocksText.xlsx new file mode 100644 index 00000000..134d8ee2 Binary files /dev/null and b/Back end/MiniprojectServer/blocksText.xlsx differ diff --git a/Back end/MiniprojectServer/lol.csv b/Back end/MiniprojectServer/lol.csv new file mode 100644 index 00000000..b4a8fedd --- /dev/null +++ b/Back end/MiniprojectServer/lol.csv @@ -0,0 +1,5 @@ +Landet er nabo til både Svarige og Rusland, Hvad er Finland?,1,3, +Landet er verdens største ø, Hvad er grønland?,2,3, +Kanalen bliver bestyret af Egypten, Hvad er Suez-kanalen?,3,3, +Roulade kommer fra dette land, Hvad er Ungarn?,4,3, +Landets hovedstad hedder Prishtina, Hvad er Kosovo?,5,3 \ No newline at end of file diff --git a/Back end/MiniprojectServer/out/production/MiniprojectServer/ClientTask.class b/Back end/MiniprojectServer/out/production/MiniprojectServer/ClientTask.class new file mode 100644 index 00000000..74f02212 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/MiniprojectServer/ClientTask.class differ diff --git a/Back end/MiniprojectServer/out/production/MiniprojectServer/Game.class b/Back end/MiniprojectServer/out/production/MiniprojectServer/Game.class new file mode 100644 index 00000000..8ac28de3 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/MiniprojectServer/Game.class differ diff --git a/Back end/MiniprojectServer/out/production/MiniprojectServer/Host.class b/Back end/MiniprojectServer/out/production/MiniprojectServer/Host.class new file mode 100644 index 00000000..d687090a Binary files /dev/null and b/Back end/MiniprojectServer/out/production/MiniprojectServer/Host.class differ diff --git a/Back end/MiniprojectServer/out/production/MiniprojectServer/Main.class b/Back end/MiniprojectServer/out/production/MiniprojectServer/Main.class new file mode 100644 index 00000000..98e0971e Binary files /dev/null and b/Back end/MiniprojectServer/out/production/MiniprojectServer/Main.class differ diff --git a/Back end/MiniprojectServer/out/production/MiniprojectServer/Player.class b/Back end/MiniprojectServer/out/production/MiniprojectServer/Player.class new file mode 100644 index 00000000..33151ca1 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/MiniprojectServer/Player.class differ diff --git a/Back end/MiniprojectServer/out/production/MiniprojectServer/QuestionBlock.class b/Back end/MiniprojectServer/out/production/MiniprojectServer/QuestionBlock.class new file mode 100644 index 00000000..370b0261 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/MiniprojectServer/QuestionBlock.class differ diff --git a/Back end/MiniprojectServer/out/production/VictorsServer/Game.class b/Back end/MiniprojectServer/out/production/VictorsServer/Game.class new file mode 100644 index 00000000..1a9f422f Binary files /dev/null and b/Back end/MiniprojectServer/out/production/VictorsServer/Game.class differ diff --git a/Back end/MiniprojectServer/out/production/VictorsServer/Host.class b/Back end/MiniprojectServer/out/production/VictorsServer/Host.class new file mode 100644 index 00000000..2fee3480 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/VictorsServer/Host.class differ diff --git a/Back end/MiniprojectServer/out/production/VictorsServer/Main.class b/Back end/MiniprojectServer/out/production/VictorsServer/Main.class new file mode 100644 index 00000000..b1efe907 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/VictorsServer/Main.class differ diff --git a/Back end/MiniprojectServer/out/production/VictorsServer/Player.class b/Back end/MiniprojectServer/out/production/VictorsServer/Player.class new file mode 100644 index 00000000..33151ca1 Binary files /dev/null and b/Back end/MiniprojectServer/out/production/VictorsServer/Player.class differ diff --git a/Back end/MiniprojectServer/out/production/VictorsServer/QuestionBlock.class b/Back end/MiniprojectServer/out/production/VictorsServer/QuestionBlock.class new file mode 100644 index 00000000..1d4a673c Binary files /dev/null and b/Back end/MiniprojectServer/out/production/VictorsServer/QuestionBlock.class differ diff --git a/Back end/MiniprojectServer/out/production/VictorsServer/QuestionReader.class b/Back end/MiniprojectServer/out/production/VictorsServer/QuestionReader.class new file mode 100644 index 00000000..81c4110b Binary files /dev/null and b/Back end/MiniprojectServer/out/production/VictorsServer/QuestionReader.class differ diff --git a/Back end/MiniprojectServer/src/ClientTask.java b/Back end/MiniprojectServer/src/ClientTask.java new file mode 100644 index 00000000..01be8f89 --- /dev/null +++ b/Back end/MiniprojectServer/src/ClientTask.java @@ -0,0 +1,41 @@ +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; + +public class ClientTask implements Runnable { + + Socket socket = null; + String serverText = ""; + Game game; + + InetAddress inetAddress; + + ClientTask(Socket socket, Game game, String serverText) { + this.socket = socket; + this.game = game; + this.serverText = serverText; + inetAddress = socket.getInetAddress(); + } + + @Override + public void run() { + //> The loan will be calculated in here + try { + //Creating input and output streams + DataInputStream input = new DataInputStream(socket.getInputStream()); + DataOutputStream output = new DataOutputStream(socket.getOutputStream()); + + //Sending all the questionblock variables + game.transferBlockOut(socket, output); + + //Receiving name of the first user + //game.loadPlayerInfo(socket, input); + + } catch (IOException e) { + e.printStackTrace(); + System.out.println("Some in-/output went wrong!"); + } + } +} \ No newline at end of file diff --git a/Back end/MiniprojectServer/src/Game.java b/Back end/MiniprojectServer/src/Game.java new file mode 100644 index 00000000..63647a08 --- /dev/null +++ b/Back end/MiniprojectServer/src/Game.java @@ -0,0 +1,91 @@ +import java.io.*; +import java.net.Socket; +import java.util.ArrayList; +import java.util.Scanner; + +public class Game { + //Player variables + ArrayList players = new ArrayList(); + public int playerId = 0; + public String name; + public int points; + public boolean isActive; + + + //QuestionBlock Variables + static ArrayList questionBlock = new ArrayList(); + public static String question; + public static String answer; + public static int value; + public static int categoryId; + + //Player voids + public void loadPlayerInfo(Socket socket, DataInputStream input) throws IOException { + name = input.readUTF(); + players.add(new Player(playerId, name, 0, false)); + + } + + + //QuestionBlock voids + //Load questions from document + public void loadQuestions() { + //Creating a scanner for reading the questionblocks from a file + Scanner sc = null; + //Try Catch to find file + try { + sc = new Scanner(new File("C:\\Users\\mikke\\OneDrive\\Dokumenter\\GitHub\\PCSS-G301\\Back end\\MiniprojectServer\\lol.csv")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.out.println("COULD NOT FIND FILE OF QUESTIONS"); + } + + sc.useDelimiter(",");//sets the delimiter pattern + + //Set a while loop for reading data as long as there is more data + while(sc.hasNext()) { + //A for loop for every questionBlock + for (int i = 0; i < 4; i++) + { + if (i == 0) { + question = sc.next(); + } + if (i == 1) { + answer = sc.next(); + } + if (i == 2) { + value = Integer.parseInt(sc.next()); + } + if (i == 3) { + categoryId = Integer.parseInt(sc.next()); + } + } + questionBlock.add(new QuestionBlock(question, answer, value, categoryId)); + } + sc.close(); //closes the scanner + + //Printing out all the info in the console + for(int i = 0; i < questionBlock.size(); i++) { + System.out.println(questionBlock.get(i).toString()); + } + + + + } + + //Transfer questionblocks out to clients + public void transferBlockOut(Socket socket, DataOutputStream output) throws IOException { + //Letting client know how many loops it needs to run + System.out.println(questionBlock.size()); + //For loop sending information from questionblocks + for(int i = 0; i < questionBlock.size(); i++) { + output.writeUTF(questionBlock.get(i).getQuestion()); + output.writeUTF(questionBlock.get(i).getAnswer()); + output.writeInt(questionBlock.get(i).getValue()); + output.writeInt(questionBlock.get(i).getCategoryId()); + } + } + + + +} \ No newline at end of file diff --git a/Back end/MiniprojectServer/src/Host.java b/Back end/MiniprojectServer/src/Host.java new file mode 100644 index 00000000..43f1f501 --- /dev/null +++ b/Back end/MiniprojectServer/src/Host.java @@ -0,0 +1,34 @@ +public class Host { + public String name; + public String ip; + boolean isCorrect; + int points; + + + +//Host function + public int chooseCorrect(int points, boolean isCorrect) { + + this.points = points; + + if (isCorrect = false) { + points = -1*points; + } + return points; + } + + +//Getters and Setters + public String getIp() { + return ip; + } + public void setIp(String ip) { + this.ip = ip; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } +} diff --git a/Back end/MiniprojectServer/src/Main.java b/Back end/MiniprojectServer/src/Main.java new file mode 100644 index 00000000..ca792527 --- /dev/null +++ b/Back end/MiniprojectServer/src/Main.java @@ -0,0 +1,35 @@ +import java.io.*; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +public class Main implements Serializable { + + public static void main(String args[]) throws IOException { + + int numberOfClients = 0; + + //Creatin an object for the gam + Game game = new Game(); + game.loadQuestions(); + + //Hosting the server + String host = "172.20.10.2"; + int port = 9696; + ServerSocket server = new ServerSocket(port); + while (true) { + Socket socket = server.accept(); + numberOfClients++; + + InetAddress inetAddress = socket.getInetAddress(); + + System.out.println("\nClient number " + numberOfClients + " joined!"); + System.out.println("Client " + numberOfClients + "'s host name is: " + inetAddress.getHostName()); + System.out.println("Client " + numberOfClients + "'s IP-address is: " + inetAddress.getHostAddress() + "\n"); + + new Thread( + new ClientTask(socket, game, "Multithreaded Server") + ).start(); + } + } +} diff --git a/Back end/MiniprojectServer/src/Player.java b/Back end/MiniprojectServer/src/Player.java new file mode 100644 index 00000000..db9bd321 --- /dev/null +++ b/Back end/MiniprojectServer/src/Player.java @@ -0,0 +1,48 @@ +public class Player { + + public int playerId; + public String name; + public int points; + public boolean isActive; + + //Constructor of player + public Player(int playerId, String name, int points, boolean isActive) { + this.playerId = playerId; + this.name = name; + this.points = points; + this.isActive = isActive; + } + + //Getters and Setters for the variables + public int getPlayerId() { + return playerId; + } + + public void setPlayerId(int playerId) { + this.playerId = playerId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean active) { + isActive = active; + } +} diff --git a/Back end/MiniprojectServer/src/QuestionBlock.java b/Back end/MiniprojectServer/src/QuestionBlock.java new file mode 100644 index 00000000..39117106 --- /dev/null +++ b/Back end/MiniprojectServer/src/QuestionBlock.java @@ -0,0 +1,67 @@ +public class QuestionBlock { + public String answer; + public String question; + public int value; + public int categoryId; + public boolean isUsed; + +//Constructor of questionBlock + public QuestionBlock(String answer, String question, int value, int categoryId) { + this.answer = answer; + this.question = question; + this.value = value; + this.categoryId = categoryId; + } + + //Getters and Setters + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public int getCategoryId() { + return categoryId; + } + + public void setCategoryId(int categoryId) { + this.categoryId = categoryId; + } + + public boolean isNotUsed() { + return isUsed; + } + + public void toggleUsed() { + isUsed = true; + } + + @Override + public String toString() { + return "QuestionBlock{" + + "answer='" + answer + '\'' + + ", question='" + question + '\'' + + ", value=" + value + '\'' + + ", categoryId=" + categoryId + '\'' + + "not used=" + isUsed + + '}'; + } +} diff --git a/Back end/mem.png b/Back end/mem.png new file mode 100644 index 00000000..33a115d8 Binary files /dev/null and b/Back end/mem.png differ diff --git a/Front end/test.txt b/Front end/test.txt new file mode 100644 index 00000000..e8e4106d --- /dev/null +++ b/Front end/test.txt @@ -0,0 +1 @@ +blabla \ No newline at end of file