1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Layouts and Animation for Android Apps

Stop Play and Homework

Start course
Overview
Difficulty
Intermediate
Duration
4h 7m
Students
1
Description

In this course, you'll start experimenting with XML code and diving deeper into layouts, namely linear and constraint layouts. We'll also look at animations and build a few fun features with them. Then, we'll take a deeper dive into the Kotlin programming language and constraint layouts, before building a fully functioning Tic-Tac-Toe game.

On top of that, we'll then build a second app which can play YouTube videos within it, and you'll learn how to work with APIs and API keys.

Intended Audience

This course is intended for beginners to Android app development or anyone who wants to master coding in Kotlin.

Prerequisites

Since this is a beginner-level course, there are no requirements, but any previous experience with coding would be beneficial.

Transcript

Hello, and welcome back. In this video, we'll pick up where we left off in the last video and get started with stopping play once a winner has been detected. So, let's go ahead and add this functionality and we'll do it using a Boolean. All right, we'll track if a game is active. So, right here after winning positions or before active player, wherever, over here I'm going to say var gameActive and I'll set it to true to begin, and then once we have a winner right here, if this combination down here is satisfied, then we're going to set gameActive to be false. All right, that's one but we also have to check this somewhere else. But let's give this a try and make sure it works. All right. We have a winner, but why did this work?

Well, we've set the gameActive to false but we're not checking for it when we are tapping anywhere, right? We have to check for this. So, just setting it to false is not good enough. In order to tap, we want to check that the game is indeed active. So, over here where we are checking for if it's an empty slot, we not only check for if the slot is empty but we have to add in another AND condition here and gameActive. And as you know from before, this means the same as gameActive = true, okay? So, now that we've added that, let's try it out. All right, it worked, let's pull it up. There we go. 

We have a winner, let's try tap somewhere else and it does work, perfect. So, there you have it, we have a working Tic-tac-toe game. And hope you enjoyed building this so far, and the next two little features we'll add to this, I'm going to leave it as a challenge for you and they are the following. You see right now, when the game ends, we can't do anything else. And to play a new game, we have to restart the app, and that can be a bit annoying especially in a game like this where you want to keep playing. So, what we want is an ability to keep on playing once the game has ended. So, your challenge then is to add a 'Play Again' button right here on top of the app screen and once the game is over and the button is clicked, it resets the game and you're able to play all over again. 

And the second bit is once a player wins, in this case crosses have won, our toast just says that a player has won, it doesn't say which player has won. So, the challenge for you is to display either circles have won or crosses have won depending on which player wins. And a hint for this is notice how our active player is either a or 1 conveniently. So, we have either which is a cross or a 1 which is a circle, so you can tell as soon as this pops up who the winner is based on something to do with the active player, right? And that's the hint for you to figure out, okay? So, give it a go. Good luck, and I'll see you in the next video where we walk through the solutions.

 

About the Author

Mashrur is a full-time programming instructor specializing in programming fundamentals, web application development, machine learning and cyber security. He has been a technology professional for over a decade and has degrees in Computer Science and Economics. His niche is building comprehensive career focused technology courses for students entering new, complex, and challenging fields in today's technology space.

Covered Topics