Learning Java by Building Android Games
eBook - ePub

Learning Java by Building Android Games

John Horton

Partager le livre
  1. 392 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Learning Java by Building Android Games

John Horton

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Learning Java by Building Android Games est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Learning Java by Building Android Games par John Horton en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Object Oriented Programming. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2015
ISBN
9781784398859

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 ...

Table des matiĂšres