├── README.md └── mathgame ├── MainActivity.kt ├── ResultActivity.kt ├── GameActivity.kt ├── GameActivity1.kt └── GameActivity2.kt /README.md: -------------------------------------------------------------------------------- 1 | # Math_Game_for_Kids 2 | I have created an app which is for kids and have also put this app on play store for study purpose. If there is any problem, please commit. 3 | -------------------------------------------------------------------------------- /mathgame/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.lkrd.mathgame 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Intent 5 | import androidx.appcompat.app.AppCompatActivity 6 | import android.os.Bundle 7 | import android.widget.Button 8 | 9 | class MainActivity : AppCompatActivity() { 10 | 11 | lateinit var addition:Button 12 | lateinit var subtraction:Button 13 | lateinit var multi:Button 14 | 15 | @SuppressLint("MissingInflatedId") 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | setContentView(R.layout.activity_main) 19 | 20 | addition=findViewById(R.id.buttonAdd) 21 | subtraction=findViewById(R.id.buttonSub) 22 | multi=findViewById(R.id.buttonMulti) 23 | 24 | addition.setOnClickListener { 25 | 26 | var intent=Intent(this,GameActivity::class.java) 27 | startActivity(intent) 28 | } 29 | subtraction.setOnClickListener { 30 | val intent=Intent(this,GameActivity1::class.java) 31 | startActivity(intent) 32 | 33 | } 34 | multi.setOnClickListener { 35 | val intent=Intent(this,GameActivity2::class.java) 36 | startActivity(intent) 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /mathgame/ResultActivity.kt: -------------------------------------------------------------------------------- 1 | package com.lkrd.mathgame 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.widget.Button 7 | import android.widget.TextView 8 | 9 | class ResultActivity : AppCompatActivity() { 10 | 11 | lateinit var result: TextView 12 | lateinit var playAgain: Button 13 | lateinit var exit: Button 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | setContentView(R.layout.activity_result) 18 | 19 | result=findViewById(R.id.textViewResult) 20 | playAgain=findViewById(R.id.buttonAgain) 21 | exit=findViewById(R.id.buttonExit) 22 | 23 | val score = intent.getIntExtra("score",0) 24 | result.text= "Your score: " + score 25 | 26 | playAgain.setOnClickListener { 27 | 28 | var intent = Intent(this,MainActivity::class.java) 29 | startActivity(intent) 30 | finish() 31 | } 32 | exit.setOnClickListener { 33 | var intent = Intent(Intent.ACTION_MAIN) 34 | intent.addCategory(Intent.CATEGORY_HOME) 35 | intent.flags= Intent.FLAG_ACTIVITY_NEW_TASK 36 | startActivity(intent) 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /mathgame/GameActivity.kt: -------------------------------------------------------------------------------- 1 | package com.lkrd.mathgame 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.os.CountDownTimer 7 | import android.widget.Button 8 | import android.widget.EditText 9 | import android.widget.TextView 10 | import android.widget.Toast 11 | import java.util.Locale 12 | import kotlin.random.Random 13 | 14 | class GameActivity : AppCompatActivity() { 15 | 16 | lateinit var textScore:TextView 17 | lateinit var textLife:TextView 18 | lateinit var textTime:TextView 19 | 20 | lateinit var textQuestion:TextView 21 | lateinit var editTextAnswer:EditText 22 | 23 | lateinit var buttonOk:Button 24 | lateinit var buttonNext:Button 25 | 26 | var correctAnswer = 0 27 | var userScore= 0 28 | var userLife= 3 29 | 30 | lateinit var timer : CountDownTimer 31 | private val startTimerMillis : Long =40000 32 | var timeLeftInMillis : Long = startTimerMillis 33 | 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | setContentView(R.layout.activity_game) 37 | 38 | supportActionBar?.title = "Addition" 39 | 40 | textScore = findViewById(R.id.textViewScore) 41 | textLife = findViewById(R.id.textViewLife) 42 | textTime = findViewById(R.id.textViewTime) 43 | textQuestion = findViewById(R.id.textViewQuestion) 44 | editTextAnswer = findViewById(R.id.editTextAnswer) 45 | buttonOk = findViewById(R.id.buttonOk) 46 | buttonNext = findViewById(R.id.buttonNext) 47 | 48 | gameContinue() 49 | 50 | buttonOk.setOnClickListener { 51 | 52 | var input = editTextAnswer.text.toString() 53 | if (input == "") { 54 | Toast.makeText( 55 | this, "Please write an answer or click the next button", 56 | Toast.LENGTH_SHORT 57 | ).show() 58 | } else { 59 | 60 | pauseTimer() 61 | 62 | val userAnswer = input.toInt() 63 | 64 | if (userAnswer == correctAnswer) { 65 | userScore = userScore + 10 66 | textQuestion.text = "Congratulation,your answer is correct" 67 | textScore.text = userScore.toString() 68 | } else { 69 | userLife-- 70 | textQuestion.text = "Sorry, your answer is wrong " 71 | textLife.text = userLife.toString() 72 | } 73 | } 74 | } 75 | buttonNext.setOnClickListener { 76 | 77 | pauseTimer() 78 | resetTimer() 79 | editTextAnswer.setText("") 80 | 81 | if (userLife == 0) { 82 | 83 | Toast.makeText(this, "Game Over", Toast.LENGTH_SHORT).show() 84 | val intent = Intent(this, ResultActivity::class.java) 85 | intent.putExtra("score", userScore) 86 | startActivity(intent) 87 | finish() 88 | 89 | } else { 90 | gameContinue() 91 | } 92 | } 93 | }fun gameContinue(){ 94 | 95 | var number1= Random.nextInt(0,100) 96 | var number2= Random.nextInt(0,50) 97 | 98 | textQuestion.text="$number1 + $number2" 99 | 100 | correctAnswer= number1 + number2 101 | 102 | startTimer() 103 | } 104 | 105 | fun startTimer() 106 | { 107 | timer = object : CountDownTimer(timeLeftInMillis,1000){ 108 | override fun onTick(millisUntilFinished : Long) { 109 | 110 | timeLeftInMillis = millisUntilFinished 111 | updateText() 112 | } 113 | override fun onFinish() { 114 | 115 | pauseTimer() 116 | resetTimer() 117 | updateText() 118 | 119 | userLife-- 120 | textLife.text= userLife.toString() 121 | textQuestion.text = "Sorry,Time is up!" 122 | 123 | } 124 | }.start() 125 | 126 | } 127 | fun updateText(){ 128 | var remainingTime: Int = (timeLeftInMillis/1000).toInt() 129 | textTime.text = String.format(Locale.getDefault(),"%02d",remainingTime) 130 | } 131 | fun pauseTimer(){ 132 | timer.cancel() 133 | 134 | } 135 | fun resetTimer(){ 136 | timeLeftInMillis = startTimerMillis 137 | updateText() 138 | } 139 | } 140 | 141 | -------------------------------------------------------------------------------- /mathgame/GameActivity1.kt: -------------------------------------------------------------------------------- 1 | package com.lkrd.mathgame 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Intent 5 | import androidx.appcompat.app.AppCompatActivity 6 | import android.os.Bundle 7 | import android.os.CountDownTimer 8 | import android.widget.Button 9 | import android.widget.EditText 10 | import android.widget.TextView 11 | import android.widget.Toast 12 | import java.util.Locale 13 | import kotlin.random.Random 14 | 15 | class GameActivity1 : AppCompatActivity() { 16 | 17 | lateinit var textScore: TextView 18 | lateinit var textLife: TextView 19 | lateinit var textTime: TextView 20 | 21 | lateinit var textQuestion: TextView 22 | lateinit var editTextAnswer: EditText 23 | 24 | lateinit var buttonOk: Button 25 | lateinit var buttonNext: Button 26 | 27 | var correctAnswer = 0 28 | var userScore= 0 29 | var userLife= 3 30 | 31 | lateinit var timer : CountDownTimer 32 | private val startTimerMillis : Long =40000 33 | var timeLeftInMillis : Long = startTimerMillis 34 | 35 | @SuppressLint("MissingInflatedId") 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | setContentView(R.layout.activity_game1) 39 | 40 | supportActionBar?.title = "Subtraction" 41 | 42 | textScore = findViewById(R.id.textViewScore) 43 | textLife = findViewById(R.id.textViewLife) 44 | textTime = findViewById(R.id.textViewTime) 45 | textQuestion = findViewById(R.id.textViewQuestion) 46 | editTextAnswer = findViewById(R.id.editTextAnswer) 47 | buttonOk = findViewById(R.id.buttonOk) 48 | buttonNext = findViewById(R.id.buttonNext) 49 | 50 | gameContinue() 51 | 52 | buttonOk.setOnClickListener { 53 | 54 | var input = editTextAnswer.text.toString() 55 | if (input == "") { 56 | Toast.makeText( 57 | this, "Please write an answer or click the next button", 58 | Toast.LENGTH_SHORT 59 | ).show() 60 | } else { 61 | 62 | pauseTimer() 63 | 64 | val userAnswer = input.toInt() 65 | 66 | if (userAnswer == correctAnswer) { 67 | userScore = userScore + 10 68 | textQuestion.text = "Congratulation,your answer is correct" 69 | textScore.text = userScore.toString() 70 | } else { 71 | userLife-- 72 | textQuestion.text = "Sorry, your answer is wrong " 73 | textLife.text = userLife.toString() 74 | } 75 | } 76 | } 77 | buttonNext.setOnClickListener { 78 | 79 | pauseTimer() 80 | resetTimer() 81 | editTextAnswer.setText("") 82 | 83 | if (userLife == 0) { 84 | 85 | Toast.makeText(this, "Game Over", Toast.LENGTH_SHORT).show() 86 | val intent = Intent(this, ResultActivity::class.java) 87 | intent.putExtra("score", userScore) 88 | startActivity(intent) 89 | finish() 90 | 91 | } else { 92 | gameContinue() 93 | } 94 | } 95 | }fun gameContinue(){ 96 | 97 | var number1= Random.nextInt(0,100,) 98 | var number2= Random.nextInt(0,40) 99 | 100 | textQuestion.text="$number1 - $number2" 101 | 102 | correctAnswer= number1 - number2 103 | 104 | startTimer() 105 | } 106 | 107 | fun startTimer() 108 | { 109 | timer = object : CountDownTimer(timeLeftInMillis,1000){ 110 | override fun onTick(millisUntilFinished : Long) { 111 | 112 | timeLeftInMillis = millisUntilFinished 113 | updateText() 114 | } 115 | override fun onFinish() { 116 | 117 | pauseTimer() 118 | resetTimer() 119 | updateText() 120 | 121 | userLife-- 122 | textLife.text= userLife.toString() 123 | textQuestion.text = "Sorry,Time is up!" 124 | 125 | } 126 | }.start() 127 | 128 | } 129 | fun updateText(){ 130 | var remainingTime: Int = (timeLeftInMillis/1000).toInt() 131 | textTime.text = String.format(Locale.getDefault(),"%02d",remainingTime) 132 | } 133 | fun pauseTimer(){ 134 | timer.cancel() 135 | 136 | } 137 | fun resetTimer(){ 138 | timeLeftInMillis = startTimerMillis 139 | updateText() 140 | } 141 | } -------------------------------------------------------------------------------- /mathgame/GameActivity2.kt: -------------------------------------------------------------------------------- 1 | package com.lkrd.mathgame 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Intent 5 | import androidx.appcompat.app.AppCompatActivity 6 | import android.os.Bundle 7 | import android.os.CountDownTimer 8 | import android.widget.Button 9 | import android.widget.EditText 10 | import android.widget.TextView 11 | import android.widget.Toast 12 | import java.util.Locale 13 | import kotlin.random.Random 14 | 15 | class GameActivity2 : AppCompatActivity() { 16 | 17 | lateinit var textScore: TextView 18 | lateinit var textLife: TextView 19 | lateinit var textTime: TextView 20 | 21 | lateinit var textQuestion: TextView 22 | lateinit var editTextAnswer: EditText 23 | 24 | lateinit var buttonOk: Button 25 | lateinit var buttonNext: Button 26 | 27 | var correctAnswer = 0 28 | var userScore= 0 29 | var userLife= 3 30 | 31 | lateinit var timer : CountDownTimer 32 | private val startTimerMillis : Long =40000 33 | var timeLeftInMillis : Long = startTimerMillis 34 | 35 | @SuppressLint("MissingInflatedId") 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | setContentView(R.layout.activity_game2) 39 | 40 | supportActionBar?.title = "Multiplication" 41 | 42 | textScore = findViewById(R.id.textViewScore) 43 | textLife = findViewById(R.id.textViewLife) 44 | textTime = findViewById(R.id.textViewTime) 45 | textQuestion = findViewById(R.id.textViewQuestion) 46 | editTextAnswer = findViewById(R.id.editTextAnswer) 47 | buttonOk = findViewById(R.id.buttonOk) 48 | buttonNext = findViewById(R.id.buttonNext) 49 | 50 | gameContinue() 51 | 52 | buttonOk.setOnClickListener { 53 | 54 | var input = editTextAnswer.text.toString() 55 | if (input == "") { 56 | Toast.makeText( 57 | this, "Please write an answer or click the next button", 58 | Toast.LENGTH_SHORT 59 | ).show() 60 | } else { 61 | 62 | pauseTimer() 63 | 64 | val userAnswer = input.toInt() 65 | 66 | if (userAnswer == correctAnswer) { 67 | userScore = userScore + 10 68 | textQuestion.text = "Congratulation,your answer is correct" 69 | textScore.text = userScore.toString() 70 | } else { 71 | userLife-- 72 | textQuestion.text = "Sorry, your answer is wrong " 73 | textLife.text = userLife.toString() 74 | } 75 | } 76 | } 77 | buttonNext.setOnClickListener { 78 | 79 | pauseTimer() 80 | resetTimer() 81 | editTextAnswer.setText("") 82 | 83 | if (userLife == 0) { 84 | 85 | Toast.makeText(this, "Game Over", Toast.LENGTH_SHORT).show() 86 | val intent = Intent(this, ResultActivity::class.java) 87 | intent.putExtra("score", userScore) 88 | startActivity(intent) 89 | finish() 90 | 91 | } else { 92 | gameContinue() 93 | } 94 | } 95 | }fun gameContinue(){ 96 | 97 | var number1= Random.nextInt(0,20,) 98 | var number2= Random.nextInt(0,20) 99 | 100 | textQuestion.text="$number1 * $number2" 101 | 102 | correctAnswer= number1 * number2 103 | 104 | startTimer() 105 | } 106 | 107 | fun startTimer() 108 | { 109 | timer = object : CountDownTimer(timeLeftInMillis,1000){ 110 | override fun onTick(millisUntilFinished : Long) { 111 | 112 | timeLeftInMillis = millisUntilFinished 113 | updateText() 114 | } 115 | override fun onFinish() { 116 | 117 | pauseTimer() 118 | resetTimer() 119 | updateText() 120 | 121 | userLife-- 122 | textLife.text= userLife.toString() 123 | textQuestion.text = "Sorry,Time is up!" 124 | 125 | } 126 | }.start() 127 | 128 | } 129 | fun updateText(){ 130 | var remainingTime: Int = (timeLeftInMillis/1000).toInt() 131 | textTime.text = String.format(Locale.getDefault(),"%02d",remainingTime) 132 | } 133 | fun pauseTimer(){ 134 | timer.cancel() 135 | 136 | } 137 | fun resetTimer(){ 138 | timeLeftInMillis = startTimerMillis 139 | updateText() 140 | } 141 | } --------------------------------------------------------------------------------