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

QuizUpActivity bug fixes

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