Jeanine Meyer
The Essential Guide to HTML5 Using Games to Learn HTML5 and JavaScript 2nd ed.
Jeanine Meyer
Purchase, NY, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/9781484241547 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-4154-7 e-ISBN 978-1-4842-4155-4
https://doi.org/10.1007/978-1-4842-4155-4
Library of Congress Control Number: 2018962546
Jeanine Meyer 2018
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
To Annika, Daniel, Aviva, and Anne, and to Esther and Joseph, who are still in our lives
Introduction
There was considerable enthusiasm about the new capabilities of HTML5, and even suggestions that no other technologies or products are necessary to produce dynamic, engrossing, interactive websites. That may be overstating things, but it is true the new features are exciting. HTML is HTML5. It now is possible, using just HTML, Cascading Style Sheets, and JavaScript, to draw lines, arcs, circles, and ovals on the screen and specify events and event handling to produce animation and respond to user actions. You can include video and audio on your website with standard controls, or include the video or audio in your application exactly when and where needed. You can create forms that validate the input and provide immediate feedback to users. You can use a facility similar to cookies to store information on the client computer. And you can use new elements, such as headers and footers, to help structure your documents.
This book is based on my teaching practices and past writings. Delving into the features of a technology or general programming concepts is best done when there is a need and a context. Games, especially familiar and simple ones, supply the context and thus the motivation and much of the explanation. When learning a new programming language, one of my first steps is to program the game of craps. Also, if I can build a ballistics simulation with animation, such as the slingshot game, and make a video or audio clip play when a specific condition occurs, I am happy. If I can construct my own maze of walls, draw a stick figure for hangman, and store information on the players computer, I am ecstatic. And thats what we do in this book. As you see how to build these simple games, youll build your expertise as well.
This goal of this book, developed with considerable help from the Apress staff and the technical reviewer, Takashi Mukoda, is to introduce you to programming, with the motivation of implementing games and building websites to share with others.
At the time of updating this book, browser support for HTML5 features is close to complete. The applications have been tested using Chrome, Firefox, and Safari. However, it is important to keep in mind that browsers can change.
My focus is on plain HTML and JavaScript because it has been my experience that knowledge and experience with the basics is the best introduction. Frameworks and libraries exist and continue to be developed and refined and at some point; these are appropriate to study. The reader can turn to these topics after getting comfortable with the basics. I note that my HTML5 and JavaScript Projects book has been updated and follows this text in complexity.
Who Is This Book For?
This book is for people who want to learn how HTML, JavaScript, and Cascading Style Sheets can serve to build dynamic, exciting websites. Its for you if you know something about programming and want to see what the current version of HTML and JavaScript bring to the table. And its also for you if you have no programming experience whatsoever. Perhaps youre a web designer or website owner and you want to know how to make things happen behind the scenes or how to request features from programmers.
With this book, we want to showcase the new(er) features of HTML5 and demystify the art of programming. Programming is an art and creating appealing games and other applications requires talent and attention to the audience. However, if you can put together words to form sentences and sentences to form paragraphs, and you have some sense of logic, you can program.
How Is This Book Structured?
The book consists of 10 chapters, each organized around a familiar game or similar application. There is considerable redundancy in the chapters so you can skip around if you like, though the games do get more complex. Each chapter starts by listing the technical features that will be covered and describing the application. We look first at the critical requirements in a general sense: what do we need to implement the application, independent of any specific technology. We then focus on the features of HTML5, CSS, JavaScript, or general programming methodology that satisfy the requirements. Finally, we examine the implementation of the application in detail. I break out the code line by line in a table, with comments next to each line. In the cases where multiple versions of a game are described, only the new lines of code are annotated. This isnt to deprive you of information, but to encourage you to see what is similar, what is different, and to demonstrate how you can build applications in stages. It certainly is appropriate to consult the commented programs on an as-needed basis. Each chapter includes suggestions on how to make the application your own, and how to test and upload the application to a website. The summary at the end of each chapter highlights what youve learned and what youll find ahead.