NODE
node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict"
function createGame(side) {
const state = {
players: {},
fruits: {},
screen: {
width: 25,
height: 25
}
}
const observers = [];
function subscribe(observer){
observers.push(observer);
}
function notifyAll(command){
console.log(`[ ${side} ] > Notificando ${observers.length} observers`);
for(const observer of observers){
observer(command);
}
}
function addPlayer(command) {
const playerId = command.playerId;
const playerX = Math.floor(Math.random() * state.screen.width);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run