1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Building a Math Game App on Android

Building a Math Game App on Android

Contents

keyboard_tab
Building a Math Game App
1
Math Game - Part 1
PREVIEW7m 14s
2
Math Game - Part 2
PREVIEW10m 5s

The course is part of this learning path

Math Game - Part 1
Overview
Difficulty
Intermediate
Duration
1h 24m
Description

This is a highly practical course that walks you through how to create a simple math game for school children on Android. We will make use of the Kotlin components that we covered in the Android App Development with Kotlin learning path, bringing them all together in a real-world app.

Learning Objectives

  • Learn how to use Kotlin and Android development tools to build your own app

Intended Audience

This course is intended for anyone who wants to learn how to start building their own apps on Android.

Prerequisites

To get the most out of this course, you should have some basic knowledge of the fundamentals of Android.

Resources

Course GitHub repos:

Transcript

All right. Hello everyone. We're here in the next video. So, we're going to start our second project right now, and this project is going to be a math game. So, everybody loves a good math game.

So, the main logic of the game is to make the user do some exercises in addition, subtraction, multiplication stuff like that. Is it going to choose a category from the list such as addition? And then, the user will answer questions about addition. All right. You can develop this game for primary school children. If you're thinking, "Hey, that sounds a little too easy for me." Well, yeah. Think about who your audience is going to be. So, if you think of it in terms of that, so you're developing an app for school kids. So, when the question displays, the user is going to answer the question in a specific amount of time. So, the user has lives, let's just say three. And also the user is going to get a point for every correct answer. So, after they write an answer, the user will click the 'OK' button. So, there's going to be another button, and this button is the next question button. So, when the user clicks on this button, another question is going to be asked,  and well, this game will go on forever. So, it's endless. And the game will continue as long as the player answers correctly. Also, it's going to be random. So, you're not going to know which numbers are going to come up, nor will the user. So, it's going to be a lot of fun to play. Why don't we just get started?

Go to Android Studio and we'll create a new project. Now before we get too far into it, I want to show the finished version of this project on a virtual device, because I just want to show you where we're going. All right. So, I'm going to open up the project again. So, you see here is the open project and there are three options: ADDITION, SUBTRACTION, MULTIPLICATION. Of course, you can always add division if you want and square roots, but we're going to skip them. So, when I click on 'ADDITION', a new game will open, and see the question here. So, the user is going to write the answer. When the user clicks on the 'OK' button, it's going to check to see if the user answer is true or false. Now also, this is against the clock, so the players got 60 seconds to answer the question. You can make it two seconds if you want, but just how challenging you want it to be. And the player's got three life. So, if the player gives three wrong answers, well, that's it. The game is going to finish. Now if you were paying attention, earlier you'll know that there is a back button. So, if the user actually clicks this button, the first page is going to open back up. In that way, if users want to, they can select another category during the game every time. So, I'm just going to select the 'ADDITION' category once again, and I've also created a different design for the buttons here. Now again, if you notice the title and the color in the action bar also change according to the activity. So, let's answer this question, 7 + 44 = 101. I'm going to write 101 here. Click on the 'OK' button. So, I click on the 'OK' button, again check the answer and writes in here, congratulations, yay. So, you see this, it adds 10 points to my score. And see how the time gets paused. Did you notice the time clock here? All right. So now, I'll look what's going to happen when I click on the 'NEXT' question button? So, I click on the 'NEXT' question button, the game displays another question. This time I'm going to give it the wrong answer. Now, I'll write the answer and click on the 'OK' button. See, so  it checked my answer and wrote sorry. So, see how my life gets decreased by one? And check it out. The time gets paused again and my score remains the same. So, I'll click on the 'NEXT' question button again. It'll ask me another question and I'll make it correct this time. All right. So, see the game is going to continue this way until I get three wrong answers. So, I'll just give the wrong answers to the questions. All right. So, now my life is zero. And after I click on the 'NEXT' button, the toast message will be displayed, and that message says, "Game over."  But after that a new page will open. So, on this page I can see my score. and check it out here. There are two buttons. So, the first one is PLAY AGAIN,  and if I click on it, guess what? It'll go to the first selection page. Now the second one is the EXIT button. So, if I click on this button, that's going to close her up. All right. So, I'll just click on the 'PLAY AGAIN' button again and there's the first page opened.

Now also, I want to mention to you that when I click on the button, did you notice it takes a little time to open the game on? Because it's not on a real phone, this is a virtual device need I remind you. Obviously, this is not because of the application, it is because of the device. So, with that in mind, let's start to develop this game. Cool. So, we'll first create a new project. I'll click on the 'File', select 'New', 'New Project' options. So, I'm going to choose an 'Empty Activity'. Click on the 'Next' button. And what do you think I'm going to call this project? Well, I'm going to call it Math Game. So, Android Studio will give the package name automatically. I'll change this package name because Google Play doesn't actually accept the example for a package name, so I will write techmania instead of example. And of course, you can just write whatever name you want. Be my guest. All right. So, programming language; Kotlin. Minimum API level can be 16. All right. So, this game will work on all of the Android Devices on the market pretty much, every single one. So, when I click on the 'Finish' button, Android Studio will create the project. Your project opens. All right. So first up, design the app. But I think that's enough for now. We're going to continue in the next video. All right. So, I'll see you then.

 

About the Author
Students
47
Courses
23
Learning Paths
1

Mehmet graduated from the Electrical & Electronics Engineering Department of the Turkish Military Academy in 2014 and then worked in the Turkish Armed Forces for four years. Later, he decided to become an instructor to share what he knew about programming with his students. He’s currently an Android instructor, is married, and has a daughter.

Covered Topics