Commit dae42bf0 authored by fpeterfalvi's avatar fpeterfalvi
Browse files

Server/LobbyActivity bugfix

In Server/LobbyActivity communication thread is also closed with a boolean variable when new activity is started.

At the end of the game, QuizUpActivity displays the outcome to the players.
parent dffe1427
......@@ -7,21 +7,15 @@ import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.WindowManager;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.Date;
public class QuizUpActivity extends AppCompatActivity implements MultipleChoiceFragment.OnFragmentInteractionListener {
......@@ -44,6 +38,7 @@ public class QuizUpActivity extends AppCompatActivity implements MultipleChoiceF
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_up);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
updateConversationHandler = new Handler();
......@@ -108,11 +103,11 @@ public class QuizUpActivity extends AppCompatActivity implements MultipleChoiceF
private void replaceFragment(String[] strings) {
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
if (Integer.parseInt(strings[8]) == -1) {
questionReceivedDate = new Date();
}
Fragment frag;
if (strings[0].equals("question")) {
if (Integer.parseInt(strings[8]) == -1) {
questionReceivedDate = new Date();
}
frag = MultipleChoiceFragment.newInstance(
strings[3], strings[4], strings[5], strings[6], strings[7],
Integer.parseInt(strings[8]), Integer.parseInt(strings[9]), Integer.parseInt(strings[10]));
......
......@@ -257,7 +257,7 @@ public class LobbyActivity extends AppCompatActivity {
}
}
public void run() {
while (!Thread.currentThread().isInterrupted()) {
while (!Thread.currentThread().isInterrupted() && exit) {
try {
if(clientSocket.isConnected()) {
......
......@@ -6,6 +6,7 @@ import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
......@@ -53,6 +54,8 @@ public class QuizUpActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Bundle extras = getIntent().getExtras();
String questionFileName = extras.getString("QUESTION_FILE_NAME", null);
......@@ -141,17 +144,33 @@ public class QuizUpActivity extends AppCompatActivity {
for (int i=0;i<outputs.size();i++) {
playerAnswerTextViews.get(i).setText("The answer of the " + Integer.toString(i + 1) + ". player: ");
outputs.get(i).println("question##" + Integer.toString(playerScores[i]) + "##"
String message = "question##" + Integer.toString(playerScores[i]) + "##"
+ Integer.toString(playerScores[1-i]) + "##" + questionString
+ "##" + answers.get(0) + "##" + answers.get(1)
+ "##" + answers.get(2) + "##" + answers.get(3) + "##-1##-1##-1" );
+ "##" + answers.get(2) + "##" + answers.get(3) + "##-1##-1##-1";
outputs.get(i).println(message);
Log.d("KvizServer", Integer.toString(i) + "-es kliensnek küldött üzenet: " + message);
}
round++;
} else {
questionText.setText("No more questions.");
questionText.setText("Játék vége.");
for (int i=0;i<4;i++) {
answerTextViews.get(i).setText("");
}
String[] messageForPlayers = new String[2];
for (int i=0;i<2;i++) {
messageForPlayers[i] = "message##" + Integer.toString(playerScores[i]) + "##" + Integer.toString(playerScores[1-i]) + "##";
}
if (playerScores[0] > playerScores[1]) {
outputs.get(0).println(messageForPlayers[0] + "Nyertél!");
outputs.get(1).println(messageForPlayers[1] + "Vesztettél!");
} else if (playerScores[1] > playerScores[0]) {
outputs.get(1).println(messageForPlayers[1] + "Nyertél!");
outputs.get(0).println(messageForPlayers[0] + "Vesztettél!");
} else {
outputs.get(0).println(messageForPlayers[0] + "Döntetlen!");
outputs.get(1).println(messageForPlayers[1] + "Döntetlen!");
}
}
}
});
......@@ -160,11 +179,13 @@ public class QuizUpActivity extends AppCompatActivity {
@Override
public void onClick(View view) {
for (int i=0;i<outputs.size();i++) {
outputs.get(i).println("question##" + Integer.toString(playerScores[i]) + "##"
String message = "question##" + Integer.toString(playerScores[i]) + "##"
+ Integer.toString(playerScores[1-i]) + "##" + questionString
+ "##" + answers.get(0) + "##" + answers.get(1)
+ "##" + answers.get(2) + "##" + answers.get(3) + "##" + Integer.toString(playerAnswers[i])
+ "##" + "-1" + "##" + Integer.toString(correctAnswer) );
+ "##" + Integer.toString(playerAnswers[1-i]) + "##" + Integer.toString(correctAnswer);
outputs.get(i).println(message);
Log.d("KvizServer", Integer.toString(i) + "-es kliensnek küldött üzenet: " + message);
}
}
});
......@@ -195,7 +216,7 @@ public class QuizUpActivity extends AppCompatActivity {
try {
String read = input.readLine();
if (read != null && !read.equals("$$$$")) {
Log.d("GameActivity", "Klienstől kapott üzenet: " + read);
Log.d("GameActivity", Integer.toString(index) + "-es klienstől kapott üzenet: " + read);
String[] strings = read.split("##");
for (int i=0;i<4;i++) {
if (strings[0].equals(answers.get(i))) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment