Welcome back.
Let's have a look into if blogs we start.
As always, we take a look at our upside or code.
Then we write our own code and afterwards we analyze our code.
So therefore, let's go.
Here's our total code and we've got our player object.
This player object has lives and yet we patch this value to 999, which was super amazing.
Well done.
But next, we've got this collision detection.
So our player gets hit by an alien.
Shot by an alien by the alien boss, whatever.
The player loses a life.
And now that's our if check our first if statement.
If the player has now less than equal zero lives, we lose the game.
Otherwise the player will respond and wait until the player gets hit again or until the player wins
the game.
So this is our circle, our function code, our flow graph over here.
Now we're going to code this, but only on a high level like we've described this over here.
And then we create our application and we take a look into the smiley part.
How does Control Flow works?
How these if statements are being prepared in this multi code.
So let's have a look.
Let's go.
Okay, here we are now at our Ubuntu VM and let's code this application real quick.
This time we have to do a little bit more Android App Development, but feel free to join me on this.
We code this together, but don't worry, you can also just lean back and watch me coding because I
will provide you the app afterwards.
This is not an app development course.
This is an app hacking course.
I want to give you some insights in the Android app development that you can do certain things.
For example, writing little pieces of code that help you further and analyzing apps or things like
this.
But yeah, as already mentioned, you can also just lean back on this and watch me coding.
Okay, feel free.
Whatever you like.
So let's go.
We go to Tools Android studio bin Bash Studio as.
Alrighty.
The ID is loading.
I will see you in a few moments.
We are back right now and this was the last project we worked on, the smiley one.
And you successfully reverse this method over here.
Congratulations once again to this one.
This is really a great thing and you did a good job on this.
For now, we want to separate them so we create a new project.
You go into file, close project.
Then we can or we click create new project.
MBTI activity and I name this smiley tool.
Language.
Chava and I go back to Marshmallow.
Yes.
Finish, and this might take a while until the graded process has been finished.
So I will see you again in a few moments.
A few moments later, we are back again.
All right.
So the first thing we want to do is we want to create our player class.
We go into comm a pecking smiley to right click new java class and we name this player.
Oops.
All right.
Okay, let's give our player some power level.
So in power equals ten.
Now we need an additional instance field.
We need our lives for this player.
So we've got five lives.
All right?
Now we need to simulate that.
Our player gets it.
We can do this in two ways.
We can write an whole application with nice music, fancy animations, and lots of explosions.
Or we can do this in the lazy way and simply put in a button.
And by pressing this button, our player get hit and going for the lazy heck approach the button way.
But feel free to code your own application game to simulate this task.
It's up to you.
So what we're doing is we create a button in our layout and by pressing this button, the button codes
are function.
And this function simulates that.
Our player got hit by an object.
Let's write this.
The method for this.
So we've got the public void we do not need in return value for this get hit.
I think this describes it in the best way.
So if our player gets hit, we lose a life.
From the start.
Life's minus.
Minus.
Okay, now we need to check if the player can still play the game.
So if we have more than zero life left, zero lives left.
If this dot lives is greater than zero, we can move on.
Otherwise we lose the game.
Or let's say I lose the game because it wasn't your fault.
If you get hit, you lost.
Okay.
Let's also make this capital.
This looks good.
Now we need to introduce a new instance because we need to put some code in here that doesn't blow this
application up and makes it unnecessarily complex.
In my case, I choose a boolean state and we initialize it with true and we say if the state is equals
true, we can move on.
Otherwise this status falls and I lose.
All right.
So this state is equals false.
If we lose the game and here we can set it once again, it wouldn't be necessary, but it doesn't hurt.
OC This method looks fine for me right now for you also.
Okay, nice to hear.
Now we need to place our button in our layout and we have to do this in the main activity because here
we have an activity and activity, some screen content.
Therefore the screen content has layout.
We can find this layout within resources layout activity main.
So this layout is described by this XML file over here we can go into code and then we have the XML
structure.
It looks a little bit complex and overwhelming.
I know, but we will do this together if you are still coding with me.
Otherwise just lean back and enjoy the show.
So here we've got our text field and let's let's make a change.
Let's call this hello UDC.
If you go back we can see this text field over here has now changed.
Hello.
You did it.
All right, let's make this a little bit more.
Yeah, hacking style.
So, Android background, I provide a new background color.
Let's make this black background equals and then 000.
Okay, if you go back, it's black as our text.
Therefore we have no visible text anymore.
Let's make this text white.
We can choose add color, slash slash wide, or we can also put in f, f, f, f, f, by the way,
those let's get back to the add colour stuff.
So if we choose this one, we can see the text as wide and the add colour is our resources dot rc file.
So we find this in values colours and here we have some defined labels.
We can also choose this one, for example, which looks even more hacky.
So let's do this.
Yes.
There we go.
This looks now super hacky.
Okay.
Let's increase this text size a little bit.
30 DPI.
There we go.
All I've done was not really necessary, but it makes the app a little bit more.
Yeah.
Looking nice to me.
So now we go for the real part.
Let's introduce or yeah, let's place our button in there.
We can find this in common button and we simply drag and drop this in.
Now we've got this this alert.
This view is not constrained, which means we have different smartphones with different resolutions,
and this button now gets placed anywhere.
It depends on which resolution you cut.
So it's floating around in our layout.
And this is something we do not want to have, because sometimes this button might be out of our screen
and therefore we cannot click this.
We want to align this button under our text over here, and we can do this with simply drag and drop
from this point.
To this point, it's floating around for a moment, but keep keep clicking, then it will it will stick
to this.
Okay.
Now the button is directly under this, but it's not yet mentioned.
Where is it?
More left.
More right?
It's definitely not centered to send this button, we click on the right side and also drag and drop
this over here.
And we do this for the left side once again.
And now we can be sure.
Okay, this button is now sent out.
This constraint layout is yeah, it's not that new, but before it was way harder, so I'm pretty glad
they introduced this one.
Okay.
Let's go back in the coat because I do not like if those elements stick that hard together.
So Android match in top 34 DPI.
DPI, by the way, is deep and it's some kind of pixel.
But regarding to the resolution.
So that means no matter what.
34 will be 34 on all screen resolutions.
It's like pixel in a better way.
There we go.
This looks now pretty nice.
Let's get back in the main activity.
Okay.
Now we need to connect this button to our method.
And this method needs to be defined over here, because this method has the knowledge about this button.
This button is placed in our activity main layout.
Therefore, we cannot use this method over here, get hit directly because this method does not know
that this button exists over here.
Okay, so this is our layout file.
And here we create now a new method in public void and simulate collision.
Plus.
There we go.
And here we can now call our player got hit method.
Okay to connect the button to this method, we have to do some Android internal stuff.
The first thing we need to do is we need to apply or add this view as a parameter.
So we edge this view as this parameter and this view will be later on our button that gets connected
to this method.
It's yeah, I do not want to go too deep into this because this is not an app development course.
I just want to show you these things that you can write your own applications.
The approach is always the same.
So if you want to simulate or test some things, this can come super handy for you.
And yeah, it's a little bit complicated, but we will go through this together right now.
So we've got our view over here, and this view is now the button.
But the button doesn't know about this right now.
So we also have to tell the button that, yeah, if we click this one, the button should trigger this
method.
This has to be done in the activity main.
Therefore, we go into patent tech and here we say Android on click, and now we can use this function
over here.
Okay.
So if you click this button, this method will be called and this one here is our button that we get.
Yeah, that we get the on click event listener combined together with this method.
Yes, it's a little bit complicated and this is why I also want to show you this right now, because
if you start with Android app development, this is a little bit tough.
In my case, I struggled a lot even by simply changing a simple text in our application.
This was super hard for me.
So we've got our button connected right now.
Let's, let's create our player object and call this method.
So play a new player and here we can now call the player got hit get hit method.
That's changes.
Okay.
If you press this button, this method gets called and this method simulates that.
Our player got hit.
Oops.
All right.
This will work.
I guess I didn't test that right now, but I'm pretty sure it does.
But we need some kind of visual output for this, otherwise we cannot be sure.
And this is where this text field now comes in.
If we go back into our activity main, let's close this one that it's a little bit easier.
Let's use this text over here to displays the actual player lives right now.
Yes, that's a good idea.
Okay.
We go into this one and we create a new text view over here.
Okay.
And this text view needs now to be connected to this one over here.
And therefore we go into this one.
This has an ID, it's called text view, and now it's like within JavaScript.
So we are calling a method that finds this ID and then we can assign this text view over here to this
text view, and then we can use this object to print out the text or make other things.
All right, let's do this.
We need to do this in the on create method because this one is creating our layout.
We need to get the reference over here.
So text view equals how do we get this reference?
Right now there's a method named find view by ID.
And here we have to provide a resource ID this resource ID.
Oops.
Sorry, an activity main is this one over here.
And this one is a reference by the resource class.
So to find this, we have to use the resource class thought ID, and then we've got our IDs in our layout
because this resource class keeps track of our IDs in our layout, we want to have our text view.
Therefore we click this text view ID.
Okay.
To be honest, this is also complicated.
Yes.
But let's let's do this once again.
So we've got our text view over here.
This text view is in this layout and this text view has an ID.
We are creating a new text view object and then we are using this object or we are assigning this object,
this text view in our layout, and we can address this with our ID.
And then the idea of our element we want to address to be 100% sure we should typecast this.
I'm not sure why there's no error message over here, and I'm also not sure if this is nowadays still
common.
But when I did start Android App Development, we had to typecast this.
Okay, now we've got our text view.
This is our object and it's connected to our layout text view.
We can simply write text, view, set text and now lives.
And here we provide our player lives.
That's all right.
Now, this is our Android app development crash course regarding to assigning objects and changing text
of text views.
It's a little bit off topic, but this can come super handy if you want to play around with this.
Therefore, I would like to include it in the course here.
Okay, let's build this application.
All right, we click locate.
Here we have this app.
Let's make our ITB connection already connected.
Let's install this app.
And now we get the screen content of all the time machine.
There we have this app, smiley tool.
We started.
Hello, Udemy.
Now we simulate that our player gets hit.
Nice.
You only having four lives.
Three, two, one, zero.
And we also get negative because we didn't yet do something with our player stage value.
But that's okay.
For now, we want to analyze or learn something about if statements and that's enough to do this.
Okay, let's have a quick look into this.
And in the next video we do a deep dive on this if statement.
So f k to dh.
So here we have two files and we can see we've got a multi multiplexing.
This might be regarding to the FA backwards compatibility of this application, but this doesn't affect
our reverse engineering approach.
Our class might be within this or this.
I would go for the classes two first.
Sorry, classes underscore whatever.
You know what I mean?
Here.
All right, here.
We've got this app hacking.
Let's see, I'm opening this now with wizards to do code.
Smiley to play about.
SMILEY There we go.
He is our class.
Let's enable Java.
All right.
We've got our player class.
We've got a superclass, traveling object, our instance fields.
We do not care about the constructor.
This is our method right now.
And TV can see the first new line.
If there's less equals zero, maybe we zero.
And then this condition we also have to go to and yeah, things like this.
In this video, I wanted to show you how you can write simple Android applications that helps you simulating
certain tasks.
And this can come super handy if you want to play around with the smiley functions.
It was a little bit off topic regarding to the whole development process, but I guess it's helpful
for you.
Therefore, I included it in this video right here.
Okay.
That's all for this video right now.
And the next one, we take a deep look into this file.
So I'm looking forward to see you there.