aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2022-01-14 20:33:02 +0100
committerThomas Voss <thomasvoss@live.com> 2022-01-14 20:33:02 +0100
commit2c9ea26d5deff4737fee842a4a753c9e257cc470 (patch)
tree75c1544d75dabe9373cd8189d761d0daf8bd5922
parentc8218c35f88eb9addfac6aad605b8e98349a987b (diff)
Add support for the game actually ending
-rw-r--r--draughts/public/javascripts/game.js6
-rw-r--r--draughts/public/javascripts/messages.js1
2 files changed, 7 insertions, 0 deletions
diff --git a/draughts/public/javascripts/game.js b/draughts/public/javascripts/game.js
index 20cceb8..dd0e9a2 100644
--- a/draughts/public/javascripts/game.js
+++ b/draughts/public/javascripts/game.js
@@ -167,6 +167,12 @@ ws.addEventListener("message", ({ data }) => {
gameHistory = data.body.history
drawHistory()
break
+ case Messages.START:
+ alert("The opponent has joined, you can make your first move.")
+ break
+ case Messages.GAMEOVER:
+ alert(data.body == colorPrefix ? "Congratulations, you have won!"
+ : "Unfortunately, you have lost...")
break
}
})
diff --git a/draughts/public/javascripts/messages.js b/draughts/public/javascripts/messages.js
index c7c2ee1..04a96e9 100644
--- a/draughts/public/javascripts/messages.js
+++ b/draughts/public/javascripts/messages.js
@@ -5,4 +5,5 @@
exports.MOVED = 3 // S <-> C :: Inform the server/opponent that the client has moved a piece
exports.WELCOME = 4 // S --> C :: Inform the client of their color when they join the game
exports.START = 5 // s --> C :: Inform the blue player that they can make the first move
+ exports.GAMEOVER = 6 // S --> C :: Inform the clients that the game is over
})(typeof(exports) == "undefined" ? (this.Messages = {}) : exports)