Commit b7cbf841 authored by Ethan Liang's avatar Ethan Liang
Browse files

chalk quiz: now unable to press submit without selection

parent 73f2640a
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package com.example.game2d;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
@@ -97,19 +98,24 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList

        Button clickedButton = (Button) view;
        if(clickedButton.getId()==R.id.submit_btn){
            if(selectedAnswer.equals(ChalkQuestionAnswer.correctAnswers[currentQuestionIndex])){
            if(selectedAnswer == "") {
                new AlertDialog.Builder(this)
                        .setMessage("Please select an answer")
                        .show();
            }
            else if(selectedAnswer.equals(ChalkQuestionAnswer.correctAnswers[currentQuestionIndex])){
                chalkscore++;
                currentQuestionIndex++;
                loadNewQuestion();
            } else {
                totalWrong++;
                Intent spawnGame = new Intent(getApplicationContext(), ChalkGameActivity.class);
                spawnGame.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                Log.d("QUESTION", "Starting activity...");
                getApplicationContext().startActivity(spawnGame);
            }
                currentQuestionIndex++;
                loadNewQuestion();


            }
        } else {
            //choices button clicked
            selectedAnswer  = clickedButton.getText().toString();
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="20dp"
        android:layout_marginBottom="10dp"
        android:layout_marginBottom="5dp"
        android:text="What is the correct machine code for the following?"
        android:textAlignment="center"
        android:textColor="@color/white"