Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users...

26
Codewords: A Massively Multiplayer Board Game built with Angular

Transcript of Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users...

Page 1: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Codewords:A Massively Multiplayer Board Game built with Angular

Page 2: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Hi! I’m Mike.

2

Page 3: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Hi! I’m Mike.

3

I like board games.

Page 4: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

4

A LOT

Page 5: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

In late 2017 I wanted to..

◂ Learn Angular 4 + WebSockets

◂ See how Django Channels would fit into my current back-end stack. Channels is neat, it’s Django+WebSockets. Not important for this talk.

5

Page 6: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

What are WebSockets?

◂ “[...] make it possible to open an interactive communication session between the user's browser and a server. [...] You can send messages to a server and receive event-driven responses without having to poll the server for a reply.” – MDN Web Docs

6

Page 7: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Standard HTTP Request/Response

1. The client connects to a server.2. The client sends a request:

GET /thing/ HTTP/1.1

<headers>

3. The server responds: HTTP/1.1 200 OK

<headers>

<content>

4. The connection is closed (maybe)

7

Page 8: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

WebSockets Request/Response

1. The client connects to a server that supports WebSockets.

2. The client sends an Upgrade request:GET /thing/ HTTP/1.1Host: <server>Connection: UpgradeUpgrade: websocket

3. The server responds:HTTP/1.1 101 Switching ProtocolsConnection: UpgradeUpgrade: websocket

4. The client and server can now send messages to each other.

8

Page 9: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

“ Learning WebSockets? You should write a chat app!– Every Tutorial, Ever

9

Page 10: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

NO.JUST NO.

10

Page 11: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Why not a chat app?

◂ Mostly, it’s boring. I’d lose interest and

wouldn’t finish.

◂ I like to learn by building something that

people will use.

11

Page 12: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

I decided to build a Massively Multiplayer Online Board Game Instead

◂ Based on Vlaada Chvátil’s extremely

popular game Codenames.

◂ Many, many people know how to play it.

◂ Easily adapted into an MMOBG

12

Page 13: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Four Weeks.Four weeks to learn TypeScript, Angular, RxJS, Bootstrap 4, build the back-end, build the front-end, write the FAQ, and stream a game on Twitch.

13

Page 14: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Angular & RxJS were great to work with for this project.

◂ I won’t get into the nitty gritty of the code

but I’d like to give you an idea of just how

well suited RxJS and Angular Services are

to working with WebSockets.

14

Page 15: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

15

How play CodenamesPlayers are split into two teams (red and blue.) Each team chooses one player to be their team's spymaster; the others players are the field agents.

Twenty-five word cards are laid out on the table in a 5×5 grid.

The spymasters are given a game key showing a 5×5 grid of colored squares, each corresponding to one of the cards on the table.

The goal of the game is to reveal all the cards of your team’s color before the other team is able to reveal thiers.

To do that, spymasters take turns giving clues consisting of one word and one number to their agents.

The agents work together to figure out which of the 25 cards in front of them the clue is referring to and select cards to reveal one at a time. If they reveal a card of their color, they keep revealing cards up to the clue’s number. If they reveal a card of any color other than their own, their turn is over.. Unless it was the black Assassin card.

If the Assassin is revealed the revealing team loses. Immediately.

Page 16: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Want big impact?Use big image.

16

Massively Multiplayer?

codewords.io/angular

Page 17: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Most WebSocket example projects are messy..

17

Page 18: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Angular and RxJS made it easy to keep things organized.

◂ Encapsulate complexity. The UI layer doesn’t even need to be aware that you’re using WebSockets.

◂ Angular Services and RxJS Observables are great for this.

18

Page 19: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

19

Codewords Architecture

Page 20: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

What happens when a user “votes” on a card?

◂ From browser to server and back

(maybe.)

◂ One pitfall. (This is the maybe.)

20

Page 21: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

21

Vote Flow

Page 22: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

A standard HTTP Request is like a phone call.

◂ The client makes the call.◂ The server picks up or doesn’t.◂ The server responds immediately with

either a message or an error.

The client will know, more or less, immediately if there was an error.

22

Page 23: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

Sending a message over a WebSocket is like sending a certified letter to a person at a big company

◂ The client sends a letter.◂ The letter is accepted and delivered to the

mail room (or it isn’t.)◂ Once the letter is in the mail room there’s

no guarantee that it’ll make it to the specific person it was addressed to.

◂ You may need the recipient to call you to tell you that they received your letter.

23

Page 24: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

24

The Weeping Forest of Silent Errors

Page 25: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

It was a good experience.

◂ Fun. Learned a lot.◂ Took just under 4 weeks. ◂ 287 mailing list subscribers the first day.◂ 69.78% open rate on new game notifications.◂ The Twitch stream turned into an international

call-in show with guest Spymasters from all over the world.

25

Page 26: Angular Game built with Multiplayer Board A Massively ...... · Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like.. Form validation

It was a good experience. (cont)

Building a demo app for real users pushed me to touch parts of Angular earlier than I might have. Like..

◂ Form validation◂ @angular/material (Dialogs) ◂ Nice to haves like:

◂ Loading spinner◂ Responsive design

26