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

paused chalk music; debug last chalk question begin; randomize orders...

paused chalk music; debug last chalk question begin; randomize orders implemented but commented out;
parent abec2a29
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -13,7 +13,8 @@
        tools:targetApi="31">
        <activity
            android:name=".QuizToChalkActivity"
            android:exported="false" />
            android:exported="false"
            android:screenOrientation="landscape"/>
        <activity
            android:name=".ChalkIntroActivity"
            android:exported="false"
+38 −9
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ package com.example.game2d;
import static java.security.AccessController.getContext;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Random;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -23,6 +23,7 @@ import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ChalkActivity extends AppCompatActivity implements View.OnClickListener{

@@ -38,7 +39,7 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
    int chalkscore = 0;
    int totalWrong = 0;
    int totalQuestion = ChalkQuestionAnswer.question.length;
    int currentQuestionIndex = 0;
    public int currentQuestionIndex = 0;
    String selectedAnswer = "";

    //for pop up intro
@@ -57,7 +58,7 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
        // BGM
        backgroundMusic = MediaPlayer.create(this,R.raw.tanpopo);
        backgroundMusic.setLooping(true);
        backgroundMusic.start();
        //backgroundMusic.start();

        //for pop up intro
        layout = findViewById(R.id.chalkActivity); // relative is the id of the layout of the page
@@ -133,11 +134,12 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
        Button clickedButton = (Button) view;
        if(clickedButton.getId()==R.id.submit_btn){
            if(selectedAnswer == "") {
                Toast.makeText(getApplicationContext(),"none", Toast.LENGTH_SHORT).show();
                new AlertDialog.Builder(this)
                        .setMessage("Please select an answer")
                        .show();
            }
            else if(selectedAnswer.equals(ChalkQuestionAnswer.correctAnswers[currentQuestionIndex])){
            } else if(selectedAnswer.equals(ChalkQuestionAnswer.correctAnswers[currentQuestionIndex])){
                Toast.makeText(getApplicationContext(),"correct", Toast.LENGTH_SHORT).show();
                //SFX
                MediaPlayer correctSound = MediaPlayer.create(this, R.raw.correct);
                correctSound.start();
@@ -149,14 +151,18 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
                MediaPlayer wrongSound = MediaPlayer.create(this, R.raw.wrong);
                wrongSound.start();
                selectedAnswer = "";
                Log.d("QUESTION", "selectedAnswer clear");
                totalWrong++;
                Log.d("QUESTION", "totalWrong++");
                Intent spawnGame = new Intent(getApplicationContext(), QuizToChalkActivity.class);
                spawnGame.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                Log.d("QUESTION", "Starting activity...");
                Log.d("QUESTION", "Starting chalk game...");
                getApplicationContext().startActivity(spawnGame);
                currentQuestionIndex++;
                if (currentQuestionIndex != 4) {
                    loadNewQuestion();
                }
            }
        } else {
            //choices button clicked
            selectedAnswer  = clickedButton.getText().toString();
@@ -166,15 +172,38 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList

    void loadNewQuestion(){
        // log question numbers
        Log.d("QUESTION", "current: " + String.valueOf(currentQuestionIndex));
        Log.d("QUESTION", "current question index: " + String.valueOf(currentQuestionIndex));
        //Log.d("QUESTION", String.valueOf(currentQuestionIndex));
        if(currentQuestionIndex == totalQuestion ){
            Log.d("QUESTION", "finishing...");
            Log.d("QUESTION", "finishing quiz...");
            finishQuiz();
            return;
        }

        questionTextView.setText(ChalkQuestionAnswer.question[currentQuestionIndex]);

        int[] orders = new int[]{0, 1, 2, 3};
        // Randomize orders[]
        Random rand = new Random();

        for (int i = 0; i < orders.length; i++) {
            // Switch i and randomIndexToSwap
            int randomIndexToSwap = rand.nextInt(orders.length);

            // temp vars to store element at randomIndex
            int tempOrder = orders[randomIndexToSwap];

            // element at randomIndex is now element at i (2 i duplicates)
            orders[randomIndexToSwap] = orders[i];

            // element at i is now element at randomIndex (via temp vars)
            orders[i] = tempOrder;
        }

        /*ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[0]]);
        ansB.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[1]]);
        ansC.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[2]]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[3]]);*/
        ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][0]);
        ansB.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][1]);
        ansC.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][2]);
+3 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class ChalkGameClass extends View {
    private Bitmap backgroundImage ;

    //MEDIA
    MediaPlayer bonk;
    MediaPlayer bonk, oof;

    //CHALK
    private Bitmap chalk[] = new Bitmap[5];
@@ -102,6 +102,7 @@ public class ChalkGameClass extends View {
        canvasHeight = canvas.getHeight();

        bonk = MediaPlayer.create(getContext(), R.raw.bonk);
        oof = MediaPlayer.create(getContext(), R.raw.oof);

        if (backgroundImage == null) return;
        // Use the same Matrix over and over again to minimize
@@ -160,6 +161,7 @@ public class ChalkGameClass extends View {
            if (hitChalkChecker(chalkX[ii], chalkY[ii])) //if player collides with chalk
            {
                chalkX[ii] = chalkX[ii] - 200; //makes chalk disappear
                oof.start();
                lifecounter--; //reduces health;

                if(lifecounter == 0)  //if all lives used up
+1 −32
Original line number Diff line number Diff line
package com.example.game2d;
import java.util.Random;

public class ChalkQuestionAnswer {
    public static void shuffleQuestions() {

        Random rand = new Random();

        for (int i = 0; i < question.length; i++) {
            // Switch i and randomIndexToSwap

            int randomIndexToSwap = rand.nextInt(question.length);

            // temp vars to store element at randomIndex
            String tempQuestion = question[randomIndexToSwap];
            String[] tempChoices = choices[randomIndexToSwap];
            String tempAnswers = correctAnswers[randomIndexToSwap];

            // element at randomIndex is now element at i (2 i duplicates)
            question[randomIndexToSwap] = question[i];
            choices[randomIndexToSwap] = choices[i];
            correctAnswers[randomIndexToSwap] = correctAnswers[i];

            // element at i is now element at randomIndex (via temp vars)
            question[i] = tempQuestion;
            choices[i] = tempChoices;
            correctAnswers[i] = tempAnswers;
        }
    }

    public static String[] question =  {
        "mov R0, 27\nmov R1, 57\nmov [R0], R1",
@@ -38,7 +12,7 @@ public class ChalkQuestionAnswer {
    public static String[][] choices = {
        {"501B507970010000", "501C507570010000", "501C50757001", "501B50797001"},
        {"C0017001C00170010000", "B0017001D00170010000", "C0017001C0017001", "B0017001D0018001"},
        {"5000504b509470400000", "5000504a509470400000", "5000504a50947040", "5000504b50947040"},
        {"5000504a509470400000", "5000504b509470400000", "5000504a50947040", "5000504b50947040"},
        {"c000c0014042d7fc0000", "c000d0014042d7fc", "c000d0014042d7fb0000", "c000c0014042d7fc"},
    };

@@ -48,9 +22,4 @@ public class ChalkQuestionAnswer {
        "5000504a509470400000",
        "c000c0014042d7fc0000"
    };

    public static void main(String[] args) {
        shuffleQuestions();
    }

}
+18 −1
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@ import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@@ -29,6 +31,8 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe
    TextView nameTextView;
    Button yes, no, exit;

    MediaPlayer correct, wrong, backgroundMusic;

    ImageButton pauseBtn;

    int score=0;
@@ -51,6 +55,10 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe
                WindowManager.LayoutParams.FLAG_FULLSCREEN
        );

        correct = MediaPlayer.create(this, R.raw.correct);
        wrong = MediaPlayer.create(this, R.raw.gasp);
        backgroundMusic = MediaPlayer.create(this, R.raw.kahoot_music);

        //for pop up intro
        layout = findViewById(R.id.nameActivity); // relative is the id of the layout of the page
        CreatepopUpwindow();
@@ -67,7 +75,8 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe
        QuestionAnswer QA = new QuestionAnswer(); // Create an instance of MyClass
        QA.run(this); // Call the run method on myObject, passing in the context object


        backgroundMusic.start();
        backgroundMusic.setLooping(true);

        yes.setOnClickListener(this);
        no.setOnClickListener(this);
@@ -127,10 +136,13 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe
        else
            choice = false;


        if(choice == QuestionAnswer.tfArray[currentQuestionIndex]) {
            score++;
            correct.start();
            clickedButton.setBackgroundColor(Color.GREEN);
        }else{
            wrong.start();
            clickedButton.setBackgroundColor(Color.RED);
        }

@@ -191,4 +203,9 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe
        loadNewQuestion();
    }

    protected void onPause() {
        super.onPause();
        backgroundMusic.stop();
    }

}
 No newline at end of file