First, code the server logic.
Open
servergame.js
. Add the following function to the file that handles user messages:Room.prototype.handleOnUserMessage = function(user) { var room = this; user.socket.on("message", function(message){ console.log("Receive message from " + user.id + ": " + message); }); };
Add the following code inside the
Room.prototype.addUser
method that calls our newly created function:this.handleOnUserMessage(user);
Now, move on to the
client
folder.Open the
index.html
file and add the following markup in thebody
section. This provides inputs for the user to type and send messages to the server:<input type="text" id="chat-input" autocomplete="off"> <input type="button" value="Send" id="send">
Then, add the following code to the
html5games.websocket.js
JavaScript file. This sends the message to the server when the user clicks on thesend
button or presses the Enter key:$("#send").click...
HTML5 Game Development by Example: Beginner's Guide
By :
HTML5 Game Development by Example: Beginner's Guide
By:
Overview of this book
Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
Introducing HTML5 Games
Getting Started with DOM-based Game Development
Building a Card-matching Game in CSS3
Building the Untangle Game with Canvas and the Drawing API
Building a Canvas Game's Masterclass
Adding Sound Effects to Your Games
Saving the Game's Progress
Building a Multiplayer Draw-and-Guess Game with WebSockets
Building a Physics Car Game with Box2D and Canvas
Deploying HTML5 Games
Pop Quiz Answers
Index
Customer Reviews