HTML5 Guidelines for Web Developers

(coco) #1

246 Chapter 9—WebSockets


Figure 9.5 “Battleships!” in demo mode

In case of a hit (isShip is true) , the relevant button on the player’s own play area
is assigned the class hit, coloring it red according to the stylesheet instruction.
If a ship is hit but is not yet completely destroyed, the opponent receives an ap-
propriate message:

wsMessage({
task : 'private',
request : 'thisFieldIs',
result : 'hit',
field : msg.field,
client : game.you.id
});

If the request part of the message is thisFieldIs, the field is treated accordingly
for the opponent:

else if (msg.request == 'thisFieldIs') {
if (msg.result == 'water') {
Free download pdf