• Complain

John Horton [John Horton] - Learning Java by Building Android Games

Here you can read online John Horton [John Horton] - Learning Java by Building Android Games full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2015, publisher: Packt Publishing, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

John Horton [John Horton] Learning Java by Building Android Games

Learning Java by Building Android Games: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Learning Java by Building Android Games" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Get ready for a fun-filled experience of learning Java by developing games for the Android platform

In Detail

Android is the fastest growing operating system (OS) with one of the largest installed bases of any mobile OS. Android uses one of the most popular programming languages, Java, as the primary language for building apps of all types. So, you should first obtain a solid grasp of the Java language and its foundation APIs to improve the chances of succeeding as an Android app developer.

This book will show you how to get your Android development environment set up and you will soon have your first working game. The difficulty level grows steadily with the introduction of key Java topics such as loops, methods, and OOP. Youll then use them in the development of games. You will learn how to build a math test game, a Simon-like memory game, a retro pong-style game, and for the grand finale, a Snake-style, retro arcade game with real Google Play leaderboards and achievements. The book has a hands-on approach and is packed with screenshots.

What You Will Learn

  • Set up an efficient, professional game development environment in Android Studio
  • Build your very own Android UI using easy to-use tools in Android Studio
  • Add real-time interaction with Java threads and implement locking/handling screen rotation, pixel graphics, clicks, animation, sound FX, and many other features in your games
  • Explore object-oriented programming (OOP) and design scalable, reliable, and well-written Java games or apps on almost any Android device
  • Build and deploy a graphical pong-style game using advanced OOP concepts
  • Explore APIs and implement advanced features such as online leaderboards and achievements using Google game services
  • Make your game compelling to be the next big hit on Google Play market with a content update strategy and in-game marketing

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

John Horton [John Horton]: author's other books


Who wrote Learning Java by Building Android Games? Find out the surname, the name of the author of the book and a list of all author's works by series.

Learning Java by Building Android Games — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Learning Java by Building Android Games" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Appendix A. Self-test Questions and Answers

Here, we have included some questions you could ask yourself to see whether you have understood each chapter. Don't worry! The answers are also included.

Chapter 2

Q1) What should you do if all this talk of life cycles, classes, and methods is a bit confusing?

A) Don't worry about them. Understanding comes a bit at a time, and if they are not entirely clear at this stage, it will not hold you back from thoroughly learning Java, and all will become clearer as we progress.

Q2) What exactly is a Java class?

A) Classes are a fundamental building block of Java programs. They are like containers for our Java code, and we can even use other people's classes to simplify the programs we write, even without seeing or understanding the code contained within those classes.

Q3) What is the difference between a method and a class?

A) Methods are contained within classes and represent the specific functionality of the class, like another container within a container. As an example from a game, we might have a Tank class with shoot, drive, and selfDestruct methods. We can use a class and its methods by making our own class, as we will in , OOP Using Other People's Hard Work , or by using the @import statement as we did earlier in this chapter.

Q4) Take a look at the Android developer site and its more technical explanation of the lifecycle phases, at http://developer.android.com/reference/android/app/Activity.html. Can you see the phase and its related method that we haven't discussed? When would it be triggered in an app? What is the precise pathway an activity takes from creation to destruction?

A) It's the restarting phase. Its corresponding method is onRestart. It is triggered when an app has been stopped and then restarted. We won't need the onRestart method in this book, but this exercise hopefully helped clarify the concept of life cycles. The precise pathway will vary; we just need to handle the phases that are relevant to our game. So far, we have just tinkered with onCreate.

Chapter 3

Q1) What does this code do?

// setContentView(R.layout.activity_main);

A) Nothing, because it is commented out with //.

Q2) Which of these lines causes an error?

String a = "Hello";String b = " Vinton Cerf";int c = 55;a = a + bc = c + c + 10;a = a + c;c = c + a;

A) The fourth line, a = a + b, has no semicolon, so it will cause an error. The last line, c = c + a;, will also cause an error because you cannot assign a string to an int value.

Q3) We talked a lot about operators and how different operators can be used together to build complicated expressions. Expressions, at a glance, can sometimes make code look complicated. However, when looked at closely, they are not as tough as they seem. Usually, it is just a case of splitting the expressions into smaller pieces to work out what is going on. Here is an expression that is more convoluted than anything else you will ever meet in this book. As a challenge, can you work out what x will be?

int x = 10;int y = 9;boolean isTrueOrFalse = false;isTrueOrFalse = (((x <=y)||(x == 10))&&((!isTrueOrFalse) || (isTrueOrFalse)));

A) You can run the SelfTestC3Q3 project in the Chapter3 folder of the code bundle to check out the answer in the console, but isTrueOrFalse evaluates to true; here's why.

First, let's break down the nasty line into manageable sections defined by the brackets:

((x <=y)||(x == 10))

Previously, we were asking the question, "is x less than or equal to y or is x exactly equal to 10?". Clearly, x is not equal to or less than y but x is exactly equal to 10, so our use of the logical OR operator, ||, in the middle causes the entire part of the expression to evaluate to true.

&&

Both sides of an && operator must evaluate to true for the overall expression to be true. So let's look at the other side:

((!isTrueOrFalse) || (isTrueOrFalse)))

Well, isTrueOrFalse is a Boolean. It can only be true or false so this part of the expression must be true because we are essentially asking, "is isTrueOrFalse false or is isTrueOrFalse true?". It must be one or the other. So, regardless of how we initialized isTrueOrFalse, the last part of the expression will be true.

So the overall expression evaluates to true, and true is assigned to isTrueOrFalse.

Chapter 4

Q1) What is wrong with this method?

void doSomething(){ return 4;}

A) It returns a value but has a void return type.

Q2) What will x be equal to at the end of this code snippet?

int x=19;do{ x=11; x++;}while(x<20)

A) Okay, this was a slightly tricky question. Regardless of the value of x, the do block always executes at least once. Then x is set to 11, and after that, it is incremented to 12. So when the while expression is evaluated, it is true and the do block executes again. Once more, x is set to 11 and then incremented to 12. The program is stuck in a never-ending (infinite) loop. This code is most likely a bug.

Chapter 5

Q1) Suppose we wanted to have a quiz where the question could be about naming the president, the capital city, and so on. How would we do this with multidimensional arrays?

A) We would just make the inner array hold three strings, perhaps like this:

String[][] countriesCitiesAndPresidents;//now allocate like thiscountriesAndCities = new String[5][3];//and initialize like thiscountriesCitiesAndPresidents [0][0] = "United Kingdom";countriesCitiesAndPresidents [0][1] = "London";countriesCitiesAndPresidents [0][3] = "Cameron";//at time of writing

Q2) In our persistence example, we saved a continually updating string to a file so that it persisted after the app had , Getting Started with Android , can you think of a way to save the string without saving it by the button click but just when the user quits the app?

A) Override the onPause life cycle method and put the code to save the string in there, like this:

@Override protected void onPause() { editor.putString(stringName, currentString); editor.commit(); }

Q3) Other than increasing the difficulty level, how could we make the memory game harder?

A) We could simply alter the pause in our thread execution to mention a lower number, giving the player less thinking time, like this:

myHandler.sendEmptyMessageDelayed(0, 450);//This halves the players thinking time

Q4) Using the plain Android UI with the dull grey buttons isn't very exciting. Take a look at the UI elements in the visual designer. Can you work out how to use an image for our button background?

A) Simply add some .png graphics to the drawable-mdpi folder and then find the background property in the Properties window while your button is selected. Click to edit the property in the usual way and choose the graphic you added to the drawable-mdpi folder.

Chapter 6

Q1) What is encapsulation?

A) Encapsulation is the way we pack our variables, code, and methods in a manner that exposes just the parts and functionality we want to the parts of our app (or any app that uses our classes) that we want.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Learning Java by Building Android Games»

Look at similar books to Learning Java by Building Android Games. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Learning Java by Building Android Games»

Discussion, reviews of the book Learning Java by Building Android Games and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.