Learning Java by Building Android Games
eBook - ePub

Learning Java by Building Android Games

John Horton

Buch teilen
  1. 392 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Learning Java by Building Android Games

John Horton

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Learning Java by Building Android Games als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Learning Java by Building Android Games von John Horton im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Object Oriented Programming. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Learning Java by Building Android Games


Table of Contents

Learning Java by Building Android Games
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Why Java, Android, and Games?
Is this book for me?
If you just want to learn pure Java
If Android is your focus
Where this book will take you
Why build games to learn to program?
Why Android and Java?
Android is the fastest evolving and growing OS ever
Android developers have great prospects
Android is open source
Java is here to stay
Java is not just for Android
Java is fast and easy to use
A summary of Java and Android
Setting up our development environment
Installing the JDK
Android Studio
Installing Android Studio
Summary
2. Getting Started with Android
Our first game project
Preparing Android Studio
Building the project
Exploring Android Studio
Using the Android Studio visual designer
Android UI types
TextView
Layout elements
ImageView widgets
ButtonView
Using the sample code
Making our game menu
Structuring our code for Android
Life cycle phases – what we need to know
Life cycle phases – what we need to do
Dividing our game into activities
Our first look at Java
Cleaning up our code
Building and installing our game
Emulators and devices
Creating an emulator
Running the emulator
Running our game on the emulator
Building our game
Installing the setup to a device
Future projects
Self-test questions
Summary
3. Speaking Java – Your First Game
Java syntax
The compiler
Making code clear with comments
Storing data and using it with variables
Types of variables
Reference types
Declaration
Initialization
Changing variables with operators
Expressing yourself in Java
Math game – asking a question
Creating the new game activity
Laying out the game screen UI
Coding a question in Java
Linking our game from the main menu
Decisions in Java
More operators
Decision 1 – If they come over the bridge, shoot them
Decision 2 – Else, do this
Switching to make decisions
Math game – getting and checking the answer
Self-test questions
Summary
4. Discovering Loops and Methods
Looping with loops
While loops
Breaking out of a loop
The continue keyword
Do-while loops
For loops
Random numbers in Java
Methods
The structure of a method
Modifier
Return type
Name of a method
Parameters
Getting things done in the method body
Using methods
A working method
Exploring method overloading
Enhancing our math game
Enhancing the UI
The new Java code
Amending GameActivity
The methods
The setQuestion method
The updateScoreAndLevel method
The isCorrect method
Calling our new methods
Finishing touches
Going full screen and locking orientation
Adding a custom image (instead of the Android icon)
Self-test questions
Summary
5. Gaming and Java Essentials
Java arrays – an array of variables
Arrays are objects
A simple example of an array
Getting dynamic with arrays
Dynamic array example
Entering the nth dimension with arrays
An example of a multidimensional array
Array-out-of-bounds exceptions
Timing with threads
A simple thread timer example with the Handler class
Beeps n buzzes – Android sound
Creating sound FX
Playing sounds in Android
Life after destruction – persistence
An example of persistence
The memory game
Phase 1 – the UI and the basics
Phase 2 – preparing our variables and presenting the pattern
Phase 3 – the player's response
Phase 4 – preserving the high score
Animating our game
UI animation in Android
Phase 5 – animating the UI
Self-test questions
Summary
6. OOP – Using Other People's Hard Work
What is OOP?
Why do it like this?
Our first class and first object
Basic classes
More things we can do with our first class
Encapsulation
Controlling the use of classes with access modifiers
Class access in a nutshell
Controlling the use of variables with access modifiers
Variable access in a nutshell
Methods have access modifiers too
Method access in a nutshell
Accessing private variables with the getter and setter methods
Setting up our objects with constructors
Variables revisited
The stack and the heap
A quick break to throw out the trash
Access, scope, this, static, and constructors demo
A quick summary on stack and heap
Inheritance
An example of inheritance
Polymorphism
Abstract classes
Interfaces
More about OOP and classes
Inner classes
Self-test questions
Summary
7. Retro Squash Game
Drawing with Android Canvas
The Android coordinate system
Animating our pixels
Getting started with Canvas and Paint
Android Canvas demo app
Detecting touches on the screen
Preparing to make the retro squash game
The design of the game
The UI
Physics
The structure of the code
The four implementation phases in detail
Phase 1 – MainActivity and onCreate
Phase 1 code explained
Phase 2 – SquashCourtView part 1
Phase 2 code explained
Phase 3 – SquashCourtView part 2
Phase 3 code explained
Phase 4 – Remaining lifecycle methods
Good object-oriented design
Self-test questions
Summary
8. The Snake Game
Game design
The coordinate system
Keeping track of the snake segments
Detecting collisions
Drawing the snake
The code structure
MainActivity
GameActivity
Tidying up onCreate
Animation, sprite sheets, and the Snake home screen
Animating with sprite sheets
Implementing the Snake home screen
Implementing the Snake game activity
Enhancing the game
Self-test questions
Summary
9. Making Your Game the Next Big Thing
How to publish your app
Marketing your app
Adding leaderboards and achievements
Planning the Snake achievements
Step-by-step leaderboards and achievements
Installing the Google Play Services API on your PC
Configuring the Google Play developer console
Implementing the leaderboard in the Google Play developer console
Implementing the achievements in the Google Play developer console
Setting up the Snake project ready for implementation
Implementing the player's sign-in, achievements, and leaderboard buttons
Implementing the leaderboards in code
Implementing the achievements in code
Uploading the updated Snake game to Google Play
What next?
Getting a programmer's job
Building bigger and better games
Self-test questions
Summary
A. Self-test Questions and Answers
Chapter ...

Inhaltsverzeichnis