Commit f4cb7ef0 authored by Ankita Tiwari's avatar Ankita Tiwari
Browse files

Documented for ChalkActivity and fixed transitions from ChalkGameActivity to ChalkResult Activity

parent 165caf5c
Loading
Loading
Loading
Loading
+29 −34
Original line number Diff line number Diff line
@@ -152,10 +152,10 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
                        Log.d("QUESTION", "totalWrong++");
                currentQuestionIndex++;
                Intent spawnGame = new Intent(getApplicationContext(), QuizToChalkActivity.class);
                spawnGame.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                spawnGame.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                spawnGame.putExtra("QuestionCount", currentQuestionIndex);
                        Log.d("QUESTION", "Starting chalk game...");
                getApplicationContext().startActivity(spawnGame);
                startActivity(spawnGame);
                loadNewQuestion();
            }
        } else {
@@ -177,16 +177,33 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList

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

        int[] randomized = randomizeOrders();
        // Randomize orders of choices displayed
        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);

        ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[0]]);
        ansB.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[1]]);
        ansC.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[2]]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[3]]);
        /*ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][0]);
            // 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]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][3]);*/
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][3]);
    }

    void finishQuiz(){
@@ -203,28 +220,6 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
        finish();
    }

    public int[] randomizeOrders() {
        int[] randomized = { 0, 1, 2, 3 };

        // Randomize orders[]
        Random rand = new Random();

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

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

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

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

        return randomized;
    }
    protected void onPause() {
        super.onPause();
        backgroundMusic.stop();
+15 −22
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package com.example.game2d;

import static android.content.Intent.getIntent;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -47,7 +48,7 @@ public class ChalkGameClass extends View {
        private int chalkCol;
        private int[] chalkX = new int[chalkNum];
        private int[] chalkY = new int[chalkNum];
        private int chalkXSpeed = 20;
        private int chalkXSpeed;
        private int chalkPassed;

    //HEALTH SYSTEM
@@ -55,7 +56,6 @@ public class ChalkGameClass extends View {
        private int lifecounter;
        private int lifeXstart;
        private int lifeY;
        private Handler handler;


    private Bitmap pauseButton;
@@ -63,7 +63,7 @@ public class ChalkGameClass extends View {
        private int pauseY = 20;
    private boolean pauseTouch = false;

    private int chalkIndex;
    SharedPreferences preferences;


    public ChalkGameClass(Context context)
@@ -74,9 +74,8 @@ public class ChalkGameClass extends View {
        oof = MediaPlayer.create(getContext(), R.raw.oof);
        bossMusic = MediaPlayer.create(getContext(), R.raw.aramid);

        SharedPreferences preferences = getContext().getSharedPreferences("MY_PREFS", 0);
        preferences = getContext().getSharedPreferences("MY_PREFS", 0);
        selectedShortHair = preferences.getBoolean("shortHairSelection", false);
        chalkIndex = preferences.getInt("ChalkQuestionIndex", 0);

       ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5

@@ -136,7 +135,9 @@ public class ChalkGameClass extends View {

        pauseButton = BitmapFactory.decodeResource(getResources(), R.drawable.pause_new);


        chalkXSpeed = 20;
        // boss music start
        bossMusic.start();

    }

@@ -150,10 +151,7 @@ public class ChalkGameClass extends View {
        // Use the same Matrix over and over again to minimize
        // allocation in onDraw.

        // boss music start
        bossMusic.start();

        //getting the question index

        Matrix matrix = new Matrix();

@@ -194,6 +192,7 @@ public class ChalkGameClass extends View {
            if(!normGravity)
            {
                playerSpeed = 125;
                bonk.start();
            }
        }       //limiting the player's y tot he bottom of the screen

@@ -242,27 +241,16 @@ public class ChalkGameClass extends View {

            if(chalkPassed == chalkNum * 3)
            {
                chalkXSpeed = 0;
                chalkPassed = 0;
                bossMusic.stop();

                if(chalkIndex!=4)
                {
                    bossMusic.stop();
                    Intent returnQuiz = new Intent(getContext(), ChalkToQuizActivity.class);
                    returnQuiz.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                    getContext().startActivity(returnQuiz);
                }
                else
                {
                    SharedPreferences preferences = getContext().getSharedPreferences("MY_PREFS", 0);
                    preferences.edit().putInt("ChalkQuestionIndex", 0).apply();
                    Intent endQuiz = new Intent(getContext(), ChalkResultActivity.class);
                    endQuiz.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    getContext().startActivity(endQuiz);
                }
                    finishFunction();

            }

            bossMusic.start();
            chalkCol = ii;
            while(chalkCol > 4) //keeping chalkCol between 0 and 4;
@@ -368,4 +356,9 @@ public class ChalkGameClass extends View {
            bossMusic.pause();
        }
    }

    private void finishFunction() {
        Activity activity = (Activity)getContext();
        activity.finish();
    }
}
+18 −4
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.example.game2d;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
@@ -12,7 +13,8 @@ import android.widget.Button;

public class ChalkToQuizActivity extends AppCompatActivity {
    private Button resButton;

    private int chalkIndex;
    SharedPreferences preferences;
    MediaPlayer victorySound;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -22,6 +24,9 @@ public class ChalkToQuizActivity extends AppCompatActivity {
        setContentView(R.layout.activity_chalk_to_quiz);
        resButton = findViewById(R.id.ChalktoQuizResume);

        preferences = getSharedPreferences("MY_PREFS",0);
        chalkIndex = preferences.getInt("ChalkQuestionIndex", 0);

        Window window = getWindow();
        window.setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
@@ -32,10 +37,19 @@ public class ChalkToQuizActivity extends AppCompatActivity {
            @Override
            public void onClick(View view) {
                victorySound.stop();
                if(chalkIndex != 4) {
                    Intent Quiztrns = new Intent(ChalkToQuizActivity.this, ChalkActivity.class);
                    Quiztrns.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                    startActivity(Quiztrns);
                }
                else
                {
                    preferences.edit().putInt("ChalkQuestionIndex", 0).apply();
                    Intent endQuiz = new Intent(ChalkToQuizActivity.this, ChalkResultActivity.class);
                    endQuiz.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(endQuiz);
                }
            }
        });
    }
}
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.example.game2d;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
@@ -12,6 +13,7 @@ import android.widget.Button;
public class QuizToChalkActivity extends AppCompatActivity {
    private Button resButton;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@
            android:layout_marginTop="10dp"
            android:layout_marginEnd="20dp"

            android:text="Get ready for more questions now!"
            android:text="Click the button below to continue!"
            android:textSize="18sp" />

        <Button