

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
In this course, we'll be building out components of "Peril" - a make-believe clone of the classic game "Risk". The only difference is that it's online and real-time!

Pub/Sub (publish/subscribe) systems are particularly useful when many events are happening in real-time and disparate parts of the system need to react to those events.
While Pub/Sub is an architecture that often refers to messages being sent between programs, or sometimes even between machines on a network, let's start with a simple pub/sub system that runs in a single program.
In "Peril", users control armies, represented as a slice of pieces: []piece. When a piece moves to a location that contains a piece owned by another player, a battle occurs. Whenever a player makes a "move", we need to publish a message telling the game that a move has occurred.
Read the doBattles function. Note that it's expecting messages to come in from the publishCh channel.
Complete the march method. It should publish a move message to the publishCh channel.
Focus Editor
ctrl+j
Next Tab
ctrl+shift+j
Login to Submit
Login to Run
Login to view solution