Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Back end/Client test/Server test/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
8 changes: 8 additions & 0 deletions Back end/Client test/Server test/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions Back end/Client test/Server test/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions Back end/Client test/Server test/.idea/modules.xml

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

10 changes: 10 additions & 0 deletions Back end/Client test/Server test/.idea/runConfigurations.xml

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

6 changes: 6 additions & 0 deletions Back end/Client test/Server test/.idea/vcs.xml

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

17 changes: 17 additions & 0 deletions Back end/Client test/Server test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Server test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions Back end/Client test/Server test/Server test.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
</component>
</module>
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions Back end/Client test/Server test/src/ClientTest/Client.java
Original file line number Diff line number Diff line change
@@ -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> questionBlock = new ArrayList<QuestionBlock>();


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());
}

}

}


53 changes: 53 additions & 0 deletions Back end/Client test/Server test/src/ClientTest/QuestionBlock.java
Original file line number Diff line number Diff line change
@@ -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 + '\''
;
}
}
3 changes: 3 additions & 0 deletions Back end/MiniprojectServer/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions Back end/MiniprojectServer/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions Back end/MiniprojectServer/.idea/modules.xml

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

10 changes: 10 additions & 0 deletions Back end/MiniprojectServer/.idea/runConfigurations.xml

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

6 changes: 6 additions & 0 deletions Back end/MiniprojectServer/.idea/vcs.xml

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

11 changes: 11 additions & 0 deletions Back end/MiniprojectServer/MiniprojectServer.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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" />
</component>
</module>
Binary file added Back end/MiniprojectServer/blocksText.xlsx
Binary file not shown.
5 changes: 5 additions & 0 deletions Back end/MiniprojectServer/lol.csv
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions Back end/MiniprojectServer/src/ClientTask.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
}
91 changes: 91 additions & 0 deletions Back end/MiniprojectServer/src/Game.java
Original file line number Diff line number Diff line change
@@ -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<Player> players = new ArrayList<Player>();
public int playerId = 0;
public String name;
public int points;
public boolean isActive;


//QuestionBlock Variables
static ArrayList<QuestionBlock> questionBlock = new ArrayList<QuestionBlock>();
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());
}
}



}
Loading