Commit 189c6d35 authored by fpeterfalvi's avatar fpeterfalvi
Browse files

QuizUpActivity bug fixes

parent 201e2c79
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
<activity <activity
android:name=".GameActivity" android:name=".GameActivity"
android:screenOrientation="portrait"></activity> android:screenOrientation="portrait"></activity>
<activity android:name=".QuizUpActivity"></activity> <activity android:name=".QuizUpActivity"
android:screenOrientation="portrait"></activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".GameActivity" /> <activity android:name=".GameActivity" />
<activity android:name=".QuizUpActivity"></activity> <activity android:name=".QuizUpActivity">
</activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -53,6 +53,8 @@ public class GameActivity extends AppCompatActivity { ...@@ -53,6 +53,8 @@ public class GameActivity extends AppCompatActivity {
String questionString; String questionString;
TextView correctAnswerTextView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -88,6 +90,7 @@ public class GameActivity extends AppCompatActivity { ...@@ -88,6 +90,7 @@ public class GameActivity extends AppCompatActivity {
answerTextViews.add((TextView) findViewById(R.id.Answer2TextView)); answerTextViews.add((TextView) findViewById(R.id.Answer2TextView));
answerTextViews.add((TextView) findViewById(R.id.Answer3TextView)); answerTextViews.add((TextView) findViewById(R.id.Answer3TextView));
answerTextViews.add((TextView) findViewById(R.id.Answer4TextView)); answerTextViews.add((TextView) findViewById(R.id.Answer4TextView));
correctAnswerTextView = (TextView) findViewById(R.id.CorrectAnswerTextView);
final LinearLayout playerAnswersLinearLayout = (LinearLayout) findViewById(R.id.PlayerAnswers); final LinearLayout playerAnswersLinearLayout = (LinearLayout) findViewById(R.id.PlayerAnswers);
numberOfPlayers = ClientHolder.size(); numberOfPlayers = ClientHolder.size();
...@@ -122,6 +125,7 @@ public class GameActivity extends AppCompatActivity { ...@@ -122,6 +125,7 @@ public class GameActivity extends AppCompatActivity {
MultipleChoiceQuestion question = questions.get(questionIndex); MultipleChoiceQuestion question = questions.get(questionIndex);
questionString = question.getQuestionText(); questionString = question.getQuestionText();
questionText.setText(questionString); questionText.setText(questionString);
correctAnswerTextView.setText("Correct answer: " + question.getCorrectAnswer());
for (int i=0;i<numberOfPlayers;i++) { for (int i=0;i<numberOfPlayers;i++) {
playerAnswers[i] = -1; playerAnswers[i] = -1;
......
...@@ -18,6 +18,7 @@ import android.util.Log; ...@@ -18,6 +18,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
...@@ -105,18 +106,22 @@ public class LobbyActivity extends AppCompatActivity { ...@@ -105,18 +106,22 @@ public class LobbyActivity extends AppCompatActivity {
startGameBtn.setOnClickListener(new View.OnClickListener() { startGameBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
exit = false; if (gameMode.equals("quizup") && (clients.size() != 2)) {
serverThread.interrupt(); Toast.makeText(getApplicationContext(), "QuizUp mode requires exactly 2 players!", Toast.LENGTH_LONG).show();
commThread.interrupt();
ClientHolder.addAll(clients);
Intent intent;
if (gameMode.equals("normal")) {
intent = new Intent(getApplicationContext(), GameActivity.class);
} else { } else {
intent = new Intent(getApplicationContext(), QuizUpActivity.class); exit = false;
serverThread.interrupt();
commThread.interrupt();
ClientHolder.addAll(clients);
Intent intent;
if (gameMode.equals("normal")) {
intent = new Intent(getApplicationContext(), GameActivity.class);
} else {
intent = new Intent(getApplicationContext(), QuizUpActivity.class);
}
intent.putExtra("QUESTION_FILE_NAME", questionFileName);
startActivity(intent);
} }
intent.putExtra("QUESTION_FILE_NAME", questionFileName);
startActivity(intent);
} }
}); });
} }
......
...@@ -5,9 +5,7 @@ import android.support.v7.app.AppCompatActivity; ...@@ -5,9 +5,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -44,13 +42,14 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -44,13 +42,14 @@ public class QuizUpActivity extends AppCompatActivity {
private final List<TextView> playerScoreTextViews = new ArrayList<>(); private final List<TextView> playerScoreTextViews = new ArrayList<>();
private TextView questionText; private TextView questionText;
private List<TextView> answerTextViews; private List<TextView> answerTextViews;
private TextView correctAnswerTextView;
private Handler updateConversationHandler; private Handler updateConversationHandler;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game); setContentView(R.layout.activity_quiz_up);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
...@@ -82,6 +81,7 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -82,6 +81,7 @@ public class QuizUpActivity extends AppCompatActivity {
answerTextViews.add((TextView) findViewById(R.id.Answer2TextView)); answerTextViews.add((TextView) findViewById(R.id.Answer2TextView));
answerTextViews.add((TextView) findViewById(R.id.Answer3TextView)); answerTextViews.add((TextView) findViewById(R.id.Answer3TextView));
answerTextViews.add((TextView) findViewById(R.id.Answer4TextView)); answerTextViews.add((TextView) findViewById(R.id.Answer4TextView));
correctAnswerTextView = (TextView) findViewById(R.id.CorrectAnswerTextView);
final LinearLayout playerAnswersLinearLayout = (LinearLayout) findViewById(R.id.PlayerAnswers); final LinearLayout playerAnswersLinearLayout = (LinearLayout) findViewById(R.id.PlayerAnswers);
numberOfPlayers = ClientHolder.size(); numberOfPlayers = ClientHolder.size();
...@@ -126,7 +126,6 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -126,7 +126,6 @@ public class QuizUpActivity extends AppCompatActivity {
newthread.start(); newthread.start();
} }
sendNextQuestionDelayed(5000);
sendTextMessageDelayed("Round 1", 3500); sendTextMessageDelayed("Round 1", 3500);
sendNextQuestionDelayed(5000); sendNextQuestionDelayed(5000);
} }
...@@ -154,6 +153,8 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -154,6 +153,8 @@ public class QuizUpActivity extends AppCompatActivity {
} }
} }
correctAnswerTextView.setText("The correct answer: ");
for (int i=0;i<outputs.size();i++) { for (int i=0;i<outputs.size();i++) {
playerAnswerTextViews.get(i).setText("The answer of the " + Integer.toString(i + 1) + ". player: "); playerAnswerTextViews.get(i).setText("The answer of the " + Integer.toString(i + 1) + ". player: ");
String message = "question##" + Integer.toString(playerScores[i]) + "##" String message = "question##" + Integer.toString(playerScores[i]) + "##"
...@@ -206,6 +207,7 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -206,6 +207,7 @@ public class QuizUpActivity extends AppCompatActivity {
} }
private void sendResults() { private void sendResults() {
updateConversationHandler.post(new QuizUpActivity.updateUIThread(-1, "")); //show correct answer
for (int i=0;i<outputs.size();i++) { for (int i=0;i<outputs.size();i++) {
String message = "answer##" + Integer.toString(playerScores[i]) + "##" String message = "answer##" + Integer.toString(playerScores[i]) + "##"
+ Integer.toString(playerScores[1-i]) + "##" + questionString + Integer.toString(playerScores[1-i]) + "##" + questionString
...@@ -261,7 +263,7 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -261,7 +263,7 @@ public class QuizUpActivity extends AppCompatActivity {
playerAnswers[index] = answerInt; playerAnswers[index] = answerInt;
if (playerAnswers[index] == correctAnswer) { if (playerAnswers[index] == correctAnswer) {
int gainedScore = (int) (21 - Double.parseDouble(strings[1])); int gainedScore = (int) (21 - Double.parseDouble(strings[1]));
if (round < 6 ) { if (round < 7 ) {
playerScores[index] += gainedScore; playerScores[index] += gainedScore;
} else { } else {
playerScores[index] += 2 * gainedScore; playerScores[index] += 2 * gainedScore;
...@@ -298,9 +300,13 @@ public class QuizUpActivity extends AppCompatActivity { ...@@ -298,9 +300,13 @@ public class QuizUpActivity extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
playerAnswerTextViews.get(index).setText("The answer of the " + Integer.toString(index + 1) + ". player: " + msg); if (index == -1) {
playerScoreTextViews.get(index).setText( correctAnswerTextView.setText("The correct answer: " + answers.get(correctAnswer));
"The score of the " + Integer.toString(index + 1) + ". player: " + Integer.toString(playerScores[index])); } else {
playerAnswerTextViews.get(index).setText("The answer of the " + Integer.toString(index + 1) + ". player: " + msg);
playerScoreTextViews.get(index).setText(
"The score of the " + Integer.toString(index + 1) + ". player: " + Integer.toString(playerScores[index]));
}
} }
} }
......
...@@ -14,38 +14,39 @@ ...@@ -14,38 +14,39 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="The place of the question."
android:id="@+id/QuestionText" android:id="@+id/QuestionText"
android:textSize="30sp"/> android:textSize="30sp"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Answer1"
android:id="@+id/Answer1TextView" android:id="@+id/Answer1TextView"
android:textSize="30sp"/> android:textSize="30sp"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Answer2"
android:id="@+id/Answer2TextView" android:id="@+id/Answer2TextView"
android:textSize="30sp"/> android:textSize="30sp"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Answer3"
android:id="@+id/Answer3TextView" android:id="@+id/Answer3TextView"
android:textSize="30sp"/> android:textSize="30sp"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Answer4"
android:id="@+id/Answer4TextView" android:id="@+id/Answer4TextView"
android:textSize="30sp"/> android:textSize="30sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CorrectAnswerTextView"
android:textSize="30sp"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -41,6 +41,12 @@ ...@@ -41,6 +41,12 @@
android:id="@+id/Answer4TextView" android:id="@+id/Answer4TextView"
android:textSize="30sp"/> android:textSize="30sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CorrectAnswerTextView"
android:textSize="30sp"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
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