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

Implemented character selection

parent 69d9f55e
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
    int chalkscore = 0;
    int totalWrong = 0;
    int totalQuestion = ChalkQuestionAnswer.question.length;
    public int currentQuestionIndex = 0;
    int currentQuestionIndex = 0;
    int sendQuestionIndex = 0;
    String selectedAnswer = "";

    //for pop up intro
@@ -125,6 +126,9 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
    }
    @Override
    public void onClick(View view) {
        //Initializing Access to shared preferences;
        SharedPreferences preferences = getSharedPreferences("MY_PREFS", 0);
        sendQuestionIndex = preferences.getInt("ChalkQuestionIndex", 0);

        ansA.setBackgroundColor(Color.WHITE);
        ansB.setBackgroundColor(Color.WHITE);
@@ -146,6 +150,7 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
                selectedAnswer = "";
                chalkscore++;
                currentQuestionIndex++;
                preferences.edit().putInt("ChalkQuestionIndex", currentQuestionIndex).apply();
                loadNewQuestion();
            } else {
                MediaPlayer wrongSound = MediaPlayer.create(this, R.raw.wrong);
@@ -155,11 +160,19 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
                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);
                spawnGame.putExtra("QuestionCount", currentQuestionIndex);
                spawnGame.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                Log.d("QUESTION", "Starting chalk game...");
                getApplicationContext().startActivity(spawnGame);
                startActivity(spawnGame);
                currentQuestionIndex++;
                preferences.edit().putInt("ChalkQuestionIndex", currentQuestionIndex).apply();
                if(currentQuestionIndex != 4)
                {
                    loadNewQuestion();
                }
                else
                {
                    preferences.edit().putInt("lastChalkScore", chalkscore).apply();
                }
            }
        } else {
            //choices button clicked
@@ -214,8 +227,9 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList

        SharedPreferences preferences = getSharedPreferences("MY_PREFS", 0);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("lastChalkScore",chalkscore);
        editor.apply();
        editor.putInt("lastChalkScore",chalkscore).apply();

        editor.putInt("ChalkQuestionIndex",0).apply();

        Intent intent = new Intent(getApplicationContext(),ChalkResultActivity.class);//
        startActivity(intent);
+22 −8
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ public class ChalkGameClass extends View {
        private int hintX = 1800;
        private int hintY = 20;

    private int chalkIndex;


    public ChalkGameClass(Context context)
    {
@@ -72,9 +74,9 @@ public class ChalkGameClass extends View {

        SharedPreferences 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
        ranGravity = 2;
       ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5

        if(ranGravity%2 ==1)
            normGravity = true; //if ranGravity is odd, normal gravity is used where you jump up but rest at the bottom
@@ -165,7 +167,7 @@ public class ChalkGameClass extends View {
        if(normGravity)
            playerY = playerY + playerSpeed; //makes character jump up and naturally fall down
        else
            playerY = playerY - 2* playerSpeed; //makes character jump down and naturally float up
            playerY = playerY - playerSpeed; //makes character jump down and naturally float up

        if (playerY < minplayerY) {
            playerY = minplayerY;
@@ -231,12 +233,24 @@ public class ChalkGameClass extends View {

            if(chalkPassed == chalkNum * 3)
            {
                chalkX[ii] = chalkX[ii] - 200;
                chalkX[ii] = chalkX[ii] - 800;
                chalkPassed = 0;
                bossMusic.stop();

                if(chalkIndex!=4)
                {
                    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);
                }

            }
            chalkCol = ii;
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class ChalkResultActivity extends AppCompatActivity { //
                winSound.stop();
                // switch back to main activity
                Intent intent = new Intent(ChalkResultActivity.this, ChalkActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }
        });
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public class QuizToChalkActivity extends AppCompatActivity {
            @Override
            public void onClick(View view) {
                Intent Chalktrns = new Intent(QuizToChalkActivity.this,ChalkGameActivity.class);
                Chalktrns.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                Chalktrns.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(Chalktrns);
            }
        });
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@
            <ImageView
                android:layout_width="80sp"
                android:layout_height="80sp"
                android:layout_marginLeft="50sp"
                android:layout_marginLeft="60sp"
                android:background="@drawable/girl_idle_right" />
        </LinearLayout>