Loading app/src/main/java/com/example/game2d/ChalkActivity.java +29 −34 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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(){ Loading @@ -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(); Loading app/src/main/java/com/example/game2d/ChalkGameClass.java +15 −22 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading @@ -55,7 +56,6 @@ public class ChalkGameClass extends View { private int lifecounter; private int lifeXstart; private int lifeY; private Handler handler; private Bitmap pauseButton; Loading @@ -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) Loading @@ -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 Loading Loading @@ -136,7 +135,9 @@ public class ChalkGameClass extends View { pauseButton = BitmapFactory.decodeResource(getResources(), R.drawable.pause_new); chalkXSpeed = 20; // boss music start bossMusic.start(); } Loading @@ -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(); Loading Loading @@ -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 Loading Loading @@ -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; Loading Loading @@ -368,4 +356,9 @@ public class ChalkGameClass extends View { bossMusic.pause(); } } private void finishFunction() { Activity activity = (Activity)getContext(); activity.finish(); } } app/src/main/java/com/example/game2d/ChalkToQuizActivity.java +18 −4 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading @@ -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, Loading @@ -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 app/src/main/java/com/example/game2d/QuizToChalkActivity.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading app/src/main/res/layout/activity_chalk_to_quiz.xml +1 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
app/src/main/java/com/example/game2d/ChalkActivity.java +29 −34 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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(){ Loading @@ -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(); Loading
app/src/main/java/com/example/game2d/ChalkGameClass.java +15 −22 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading @@ -55,7 +56,6 @@ public class ChalkGameClass extends View { private int lifecounter; private int lifeXstart; private int lifeY; private Handler handler; private Bitmap pauseButton; Loading @@ -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) Loading @@ -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 Loading Loading @@ -136,7 +135,9 @@ public class ChalkGameClass extends View { pauseButton = BitmapFactory.decodeResource(getResources(), R.drawable.pause_new); chalkXSpeed = 20; // boss music start bossMusic.start(); } Loading @@ -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(); Loading Loading @@ -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 Loading Loading @@ -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; Loading Loading @@ -368,4 +356,9 @@ public class ChalkGameClass extends View { bossMusic.pause(); } } private void finishFunction() { Activity activity = (Activity)getContext(); activity.finish(); } }
app/src/main/java/com/example/game2d/ChalkToQuizActivity.java +18 −4 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading @@ -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, Loading @@ -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
app/src/main/java/com/example/game2d/QuizToChalkActivity.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading
app/src/main/res/layout/activity_chalk_to_quiz.xml +1 −1 Original line number Diff line number Diff line Loading @@ -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 Loading