Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f73d94b0ec
|
@ -1,28 +1,78 @@
|
||||||
package com.example.alzapp;
|
package com.example.alzapp;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class QuickQuizStart extends AppCompatActivity {
|
public class QuickQuizStart extends AppCompatActivity {
|
||||||
|
|
||||||
|
private static final int REQUEST_CODE_QUIZ = 1;
|
||||||
|
|
||||||
|
public static final String SHARED_PREFS = "sharedPrefs";
|
||||||
|
public static final String KEY_HIGHSCORE = "keyHighScore";
|
||||||
|
|
||||||
|
private TextView textViewHighScore;
|
||||||
|
private int highScore;
|
||||||
|
|
||||||
private Button quiz_start;
|
private Button quiz_start;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_quick_quiz_start);
|
setContentView(R.layout.activity_quick_quiz_start);
|
||||||
|
|
||||||
|
textViewHighScore = findViewById(R.id.quiz_highScore);
|
||||||
|
loadHighScore();
|
||||||
|
|
||||||
quiz_start = findViewById(R.id.start_quiz);
|
quiz_start = findViewById(R.id.start_quiz);
|
||||||
quiz_start.setOnClickListener(new View.OnClickListener() {
|
quiz_start.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(QuickQuizStart.this,QuizQuestionPage.class);
|
Intent intent = new Intent(QuickQuizStart.this,QuizQuestionPage.class);
|
||||||
startActivity(intent);
|
startActivityForResult(intent,REQUEST_CODE_QUIZ);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
if(requestCode == REQUEST_CODE_QUIZ){
|
||||||
|
if(resultCode == RESULT_OK){
|
||||||
|
int score = data.getIntExtra(QuizQuestionPage.EXTRA_SCORE,0);
|
||||||
|
if(score > highScore){
|
||||||
|
updateHighScore(score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateHighScore(int highScoreNew){
|
||||||
|
highScore = highScoreNew;
|
||||||
|
textViewHighScore.setText("Highscore: "+ highScore);
|
||||||
|
|
||||||
|
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putInt(KEY_HIGHSCORE, highScore);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void loadHighScore(){
|
||||||
|
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS,MODE_PRIVATE);
|
||||||
|
highScore = prefs.getInt(KEY_HIGHSCORE,0);
|
||||||
|
textViewHighScore.setText("Highscore: "+ highScore);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,13 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
import com.example.alzapp.QuizContract.* ;
|
import com.example.alzapp.QuizContract.* ;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class QuizDbHelper extends SQLiteOpenHelper {
|
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "Quiz.db";
|
public class QuizDbHelper extends SQLiteOpenHelper {
|
||||||
|
private static final String DATABASE_NAME = "MyAwesomeQuiz.db";
|
||||||
private static final int DATABASE_VERSION = 1;
|
private static final int DATABASE_VERSION = 1;
|
||||||
|
|
||||||
private SQLiteDatabase db;
|
private SQLiteDatabase db;
|
||||||
|
@ -24,7 +25,6 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
|
||||||
final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " +
|
final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " +
|
||||||
|
@ -38,9 +38,7 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
||||||
")";
|
")";
|
||||||
|
|
||||||
db.execSQL(SQL_CREATE_QUESTIONS_TABLE);
|
db.execSQL(SQL_CREATE_QUESTIONS_TABLE);
|
||||||
|
|
||||||
fillQuestionsTable();
|
fillQuestionsTable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,51 +47,54 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillQuestionsTable(){
|
private void fillQuestionsTable() {
|
||||||
Question q1 = new Question("A is correct", "A", "B", "C", 1);
|
Question q1 = new Question("What is 2+2?", "4", "12", "17", 1);
|
||||||
addQuestion(q1);
|
addQuestion(q1);
|
||||||
|
Question q2 = new Question("Which letter comes after A,B,C,D in the english alphabet series?", "F", "E", "D", 2);
|
||||||
Question q2 = new Question("B is correct", "A", "B", "C", 2);
|
|
||||||
addQuestion(q2);
|
addQuestion(q2);
|
||||||
|
Question q3 = new Question("How many letters are present in the english alphabet?", "28", "25", "26", 3);
|
||||||
Question q3 = new Question("C is correct", "A", "B", "C", 3);
|
|
||||||
addQuestion(q3);
|
addQuestion(q3);
|
||||||
|
Question q4 = new Question("8,16,24, __ Which number should come in the blank space ?", "34", "32", "48", 2);
|
||||||
Question q4 = new Question("A is correct again", "A", "B", "C", 1);
|
|
||||||
addQuestion(q4);
|
addQuestion(q4);
|
||||||
|
Question q5 = new Question("In tossing of a fair coin, what is the probability of getting a head? ", "50%", "40%", "55%", 1);
|
||||||
Question q5 = new Question("B is correct again", "A", "B", "C", 2);
|
|
||||||
addQuestion(q5);
|
addQuestion(q5);
|
||||||
|
Question q6 = new Question("The total number of states present in India is", "27", "28", "29", 2);
|
||||||
|
addQuestion(q6);
|
||||||
|
Question q7 = new Question("The Hindi film industry is better known as ", "Bollywood", "Tollywood", "Sandalwood", 1);
|
||||||
|
addQuestion(q7);
|
||||||
|
Question q8 = new Question("Which city is also known as the Silicon Valley of Asia ?", "Mumbai", "Abu Dhabi", "Bangalore", 3);
|
||||||
|
addQuestion(q8);
|
||||||
|
Question q9 = new Question("Total number of bones present in the human body is ", "204", "205", "206", 3);
|
||||||
|
addQuestion(q9);
|
||||||
|
Question q10 = new Question("Novak Djokovic is a famous player associated with the game of ", "Basketball", "Tennis", "Cricket", 1);
|
||||||
|
addQuestion(q10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQuestion(Question question){
|
private void addQuestion(Question question) {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(QuestionsTable.COLUMN_QUESTION, question.getQuestion());
|
cv.put(QuestionsTable.COLUMN_QUESTION, question.getQuestion());
|
||||||
cv.put(QuestionsTable.COLUMN_OPTION1, question.getOption1());
|
cv.put(QuestionsTable.COLUMN_OPTION1, question.getOption1());
|
||||||
cv.put(QuestionsTable.COLUMN_OPTION1, question.getOption1());
|
|
||||||
cv.put(QuestionsTable.COLUMN_OPTION2, question.getOption2());
|
cv.put(QuestionsTable.COLUMN_OPTION2, question.getOption2());
|
||||||
cv.put(QuestionsTable.COLUMN_OPTION3, question.getOption3());
|
cv.put(QuestionsTable.COLUMN_OPTION3, question.getOption3());
|
||||||
cv.put(QuestionsTable.COLUMN_ANSWER_NR, question.getAnswerNr());
|
cv.put(QuestionsTable.COLUMN_ANSWER_NR, question.getAnswerNr());
|
||||||
|
|
||||||
db.insert(QuestionsTable.TABLE_NAME, null, cv);
|
db.insert(QuestionsTable.TABLE_NAME, null, cv);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Question> getAllQuestions() {
|
||||||
public List<Question> getAllQuestions(){
|
|
||||||
List<Question> questionList = new ArrayList<>();
|
List<Question> questionList = new ArrayList<>();
|
||||||
db = getReadableDatabase();
|
db = getReadableDatabase();
|
||||||
Cursor c = db.rawQuery("SELECT * FROM " + QuestionsTable.TABLE_NAME, null);
|
Cursor c = db.rawQuery("SELECT * FROM " + QuestionsTable.TABLE_NAME, null);
|
||||||
|
|
||||||
if(c.moveToFirst()){
|
if (c.moveToFirst()) {
|
||||||
do{
|
do {
|
||||||
Question question = new Question();
|
Question question = new Question();
|
||||||
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
|
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
|
||||||
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
|
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
|
||||||
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
|
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
|
||||||
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
|
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
|
||||||
question.setAnswerNr(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NR)));
|
question.setAnswerNr(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NR)));
|
||||||
|
questionList.add(question);
|
||||||
} while (c.moveToNext());
|
} while (c.moveToNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,30 @@
|
||||||
package com.example.alzapp;
|
package com.example.alzapp;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class QuizQuestionPage extends AppCompatActivity {
|
public class QuizQuestionPage extends AppCompatActivity {
|
||||||
|
|
||||||
|
public static final String EXTRA_SCORE = "extraScore";
|
||||||
|
private static final long COUNT_DOWN_MILLIS = 10000;
|
||||||
|
|
||||||
private TextView textViewQuestion;
|
private TextView textViewQuestion;
|
||||||
private TextView textViewScore;
|
private TextView textViewScore;
|
||||||
private TextView textViewQuestionCount ;
|
private TextView textViewQuestionCount;
|
||||||
private TextView textViewCountDown;
|
private TextView textViewCountDown;
|
||||||
private RadioGroup rbGroup;
|
private RadioGroup rbGroup;
|
||||||
private RadioButton rb1;
|
private RadioButton rb1;
|
||||||
|
@ -25,7 +33,10 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
private Button buttonConfirmNext;
|
private Button buttonConfirmNext;
|
||||||
|
|
||||||
private ColorStateList textColorDefaultRb;
|
private ColorStateList textColorDefaultRb;
|
||||||
|
private ColorStateList textColorDefaultCd;
|
||||||
|
|
||||||
|
private CountDownTimer countDownTimer;
|
||||||
|
private long timeLeftInMillis;
|
||||||
|
|
||||||
private List<Question> questionList;
|
private List<Question> questionList;
|
||||||
private int questionCounter;
|
private int questionCounter;
|
||||||
|
@ -35,6 +46,8 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
private int score;
|
private int score;
|
||||||
private boolean answered;
|
private boolean answered;
|
||||||
|
|
||||||
|
private long backPressedTime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -50,6 +63,10 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
rb3 = findViewById(R.id.radioButton32);
|
rb3 = findViewById(R.id.radioButton32);
|
||||||
buttonConfirmNext = findViewById(R.id.quiz_confirm_next);
|
buttonConfirmNext = findViewById(R.id.quiz_confirm_next);
|
||||||
|
|
||||||
|
|
||||||
|
textColorDefaultRb = rb1.getTextColors();
|
||||||
|
textColorDefaultCd = textViewCountDown.getTextColors();
|
||||||
|
|
||||||
QuizDbHelper dbHelper = new QuizDbHelper(this);
|
QuizDbHelper dbHelper = new QuizDbHelper(this);
|
||||||
questionList = dbHelper.getAllQuestions();
|
questionList = dbHelper.getAllQuestions();
|
||||||
questionCountTotal = questionList.size();
|
questionCountTotal = questionList.size();
|
||||||
|
@ -57,15 +74,29 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
|
|
||||||
showNextQuestion();
|
showNextQuestion();
|
||||||
|
|
||||||
|
buttonConfirmNext.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (!answered) {
|
||||||
|
if (rb1.isChecked() || rb2.isChecked() || rb3.isChecked()) {
|
||||||
|
checkAnswer();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(QuizQuestionPage.this, "Please select an answer", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showNextQuestion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showNextQuestion(){
|
private void showNextQuestion() {
|
||||||
rb1.setTextColor(textColorDefaultRb);
|
rb1.setTextColor(textColorDefaultRb);
|
||||||
rb2.setTextColor(textColorDefaultRb);
|
rb2.setTextColor(textColorDefaultRb);
|
||||||
rb3.setTextColor(textColorDefaultRb);
|
rb3.setTextColor(textColorDefaultRb);
|
||||||
rbGroup.clearCheck();
|
rbGroup.clearCheck();
|
||||||
|
|
||||||
if ( questionCounter < questionCountTotal){
|
if (questionCounter < questionCountTotal) {
|
||||||
currentQuestion = questionList.get(questionCounter);
|
currentQuestion = questionList.get(questionCounter);
|
||||||
|
|
||||||
textViewQuestion.setText(currentQuestion.getQuestion());
|
textViewQuestion.setText(currentQuestion.getQuestion());
|
||||||
|
@ -74,13 +105,120 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
rb3.setText(currentQuestion.getOption3());
|
rb3.setText(currentQuestion.getOption3());
|
||||||
|
|
||||||
questionCounter++;
|
questionCounter++;
|
||||||
textViewQuestionCount.setText("Question: "+ questionCounter + "/" + questionCountTotal);
|
textViewQuestionCount.setText("Question: " + questionCounter + "/" + questionCountTotal);
|
||||||
answered = false;
|
answered = false;
|
||||||
buttonConfirmNext.setText("Confirm");
|
buttonConfirmNext.setText("Confirm");
|
||||||
|
|
||||||
|
timeLeftInMillis = COUNT_DOWN_MILLIS;
|
||||||
|
startCountdown();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
finishQuiz();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void startCountdown(){
|
||||||
|
countDownTimer = new CountDownTimer(timeLeftInMillis,1000) {
|
||||||
|
@Override
|
||||||
|
public void onTick(long millisUntilFinished) {
|
||||||
|
timeLeftInMillis = millisUntilFinished;
|
||||||
|
updateCountDownText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
timeLeftInMillis = 0;
|
||||||
|
updateCountDownText();
|
||||||
|
checkAnswer();
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCountDownText(){
|
||||||
|
int minutes = (int) (timeLeftInMillis / 1000) /60;
|
||||||
|
int seconds = (int) (timeLeftInMillis / 1000) %60;
|
||||||
|
|
||||||
|
String timeFormatted = String.format(Locale.getDefault(),"%02d:%02d",minutes,seconds);
|
||||||
|
textViewCountDown.setText(timeFormatted);
|
||||||
|
|
||||||
|
|
||||||
|
if(timeLeftInMillis < 5000){
|
||||||
|
textViewCountDown.setTextColor(Color.GREEN);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
textViewCountDown.setTextColor(textColorDefaultCd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkAnswer() {
|
||||||
|
answered = true;
|
||||||
|
|
||||||
|
countDownTimer.cancel();
|
||||||
|
|
||||||
|
RadioButton rbSelected = findViewById(rbGroup.getCheckedRadioButtonId());
|
||||||
|
int answerNr = rbGroup.indexOfChild(rbSelected) + 1;
|
||||||
|
|
||||||
|
if (answerNr == currentQuestion.getAnswerNr()) {
|
||||||
|
score++;
|
||||||
|
textViewScore.setText("Score: " + score);
|
||||||
|
}
|
||||||
|
|
||||||
|
showSolution();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSolution() {
|
||||||
|
/** rb1.setTextColor(Color.RED);
|
||||||
|
rb2.setTextColor(Color.RED);
|
||||||
|
rb3.setTextColor(Color.RED); **/
|
||||||
|
|
||||||
|
switch (currentQuestion.getAnswerNr()) {
|
||||||
|
case 1:
|
||||||
|
// rb1.setTextColor(Color.GREEN);
|
||||||
|
textViewQuestion.setText("Answer 1 is correct");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// rb2.setTextColor(Color.GREEN);
|
||||||
|
textViewQuestion.setText("Answer 2 is correct");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// rb3.setTextColor(Color.GREEN);
|
||||||
|
textViewQuestion.setText("Answer 3 is correct");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (questionCounter < questionCountTotal) {
|
||||||
|
buttonConfirmNext.setText("Next");
|
||||||
|
} else {
|
||||||
|
buttonConfirmNext.setText("Finish");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishQuiz() {
|
||||||
|
Intent resultIntent = new Intent();
|
||||||
|
resultIntent.putExtra(EXTRA_SCORE,score);
|
||||||
|
setResult(RESULT_OK,resultIntent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if(backPressedTime + 2000 > System.currentTimeMillis()){
|
||||||
|
finishQuiz();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.makeText(this,"Press back again to finish",Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
backPressedTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if(countDownTimer != null){
|
||||||
|
countDownTimer.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Chronometer;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -38,7 +39,8 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
img201,img202,img203,img204,img205,img206,img207,img208,
|
img201,img202,img203,img204,img205,img206,img207,img208,
|
||||||
firstCard,secondCard,clickedFirst,clickedSecond,cardNumber=1,playerMoves=0;
|
firstCard,secondCard,clickedFirst,clickedSecond,cardNumber=1,playerMoves=0;
|
||||||
|
|
||||||
|
private Chronometer chronometer;
|
||||||
|
public boolean running;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -46,6 +48,9 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
setContentView(R.layout.activity_tile_matching);
|
setContentView(R.layout.activity_tile_matching);
|
||||||
counter=(TextView) findViewById(R.id.counter1);
|
counter=(TextView) findViewById(R.id.counter1);
|
||||||
|
|
||||||
|
chronometer = findViewById(R.id.tileMatching_chronometer);
|
||||||
|
|
||||||
|
|
||||||
i11=(ImageView) findViewById(R.id.i11);
|
i11=(ImageView) findViewById(R.id.i11);
|
||||||
i12=(ImageView) findViewById(R.id.i12);
|
i12=(ImageView) findViewById(R.id.i12);
|
||||||
i13=(ImageView) findViewById(R.id.i13);
|
i13=(ImageView) findViewById(R.id.i13);
|
||||||
|
@ -222,8 +227,6 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Button back = (Button) findViewById(R.id.back);
|
Button back = (Button) findViewById(R.id.back);
|
||||||
|
|
||||||
back.setOnClickListener(new View.OnClickListener() {
|
back.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -233,9 +236,16 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Game timer **/
|
||||||
|
if(!running){
|
||||||
|
chronometer.start();
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void doStuff(ImageView img,int card){
|
private void doStuff(ImageView img,int card){
|
||||||
if(cardsArray[card]==101){
|
if(cardsArray[card]==101){
|
||||||
img.setImageResource(img101);
|
img.setImageResource(img101);
|
||||||
|
@ -495,9 +505,14 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
i44.getVisibility()==View.INVISIBLE
|
i44.getVisibility()==View.INVISIBLE
|
||||||
){
|
){
|
||||||
AlertDialog.Builder message= new AlertDialog.Builder(TileMatchingActivity.this);
|
AlertDialog.Builder message= new AlertDialog.Builder(TileMatchingActivity.this);
|
||||||
message.setMessage("GAME OVER!!\nMOVES= "+counter)
|
message.setMessage("GAME OVER!!\nMOVES= "+counter);
|
||||||
.setCancelable(false)
|
/** Timer end **/
|
||||||
.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
|
if(running){
|
||||||
|
chronometer.stop();
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
message.setCancelable(false);
|
||||||
|
message.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -15,9 +15,10 @@
|
||||||
android:textColor="@android:color/black" />
|
android:textColor="@android:color/black" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/quiz_highScore"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="High Score"
|
android:text="Highscore : 0"
|
||||||
android:textSize="20dp"
|
android:textSize="20dp"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginTop="160dp"
|
android:layout_marginTop="160dp"
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
android:id="@+id/quiz_confirm_next"
|
android:id="@+id/quiz_confirm_next"
|
||||||
android:layout_width="160dp"
|
android:layout_width="160dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:text="next"
|
android:text="confirm"
|
||||||
android:background="@drawable/button_menu"
|
android:background="@drawable/button_menu"
|
||||||
android:layout_below="@id/quiz_radio_group"
|
android:layout_below="@id/quiz_radio_group"
|
||||||
android:layout_marginTop="50dp"
|
android:layout_marginTop="50dp"
|
||||||
|
|
|
@ -43,6 +43,15 @@
|
||||||
android:text="MOVES= 0"
|
android:text="MOVES= 0"
|
||||||
android:textSize="20sp"/>
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
|
<Chronometer
|
||||||
|
android:id="@+id/tileMatching_chronometer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:textSize="24sp"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in New Issue