MakerSpace Amiens · Microcontrollers
Kick-off: the game, the network, the organisation
Alban Petit

Everything from the labs is useful: the board, the game loop, the state machine, the display, the joystick.

One Snake, two players, two games
flowchart LR
J1["Player 1: joystick"] --> C["XIAO console: rules and display"]
C <-->|"Wi-Fi + WebSocket"| N["Player 2: browser"]
Player 1 plays Snake on the console. Player 2 joins the game from their phone, on a page served by the console itself.
The two do not play the same game: it is asymmetric multiplayer.

delay()
Ideas, not a list: take one, combine them, or invent your own.
A single rule: their actions must really change the game.


1
Can each player win? A role that is too powerful kills the other’s game.
2
Do both always have something to do? A player who waits drops out.
Two “yes” answers, and your idea holds up. Keep track of your trials: they justify your choice.

Ready since Lab 4
delay()justPressed() and the calibrated joystickThe Snake starts from all of this. Only the game mechanics and the network are new.
Pong on the console Soldering and testing the board

Bringing a browser into the game
flowchart LR
T["Phone: 192.168.4.2"] <-->|Wi-Fi| C["Console: 192.168.4.1"]
As an access point, the console creates its own network: no need for the school Wi-Fi, nor the Internet. The phone connects to it and opens http://192.168.4.1/.
Give your network a unique name in the room.

Sends player 2’s page, once, when it is opened.
The browser asks, the console answers, the connection closes.
Exchanges the game messages, throughout the game.
The line stays open: each side talks whenever it wants.
Wi-Fi, HTTP and WebSocket ESP32, Wi-Fi and WebSocket

The page once, then the messages continuously.

| Direction | Message | Meaning |
|---|---|---|
| Console → browser | STATE:PLAYING |
The game phase changes |
| Console → browser | SCORE:12 |
New score |
| Browser → console | FOOD:12,7 |
Request: an apple at (12, 7) |

sequenceDiagram
participant N as Browser
participant C as Console
N->>C: GET / (HTTP)
C-->>N: the page
N->>C: opening the WebSocket
C->>N: STATE:PLAYING
N->>C: a request from player 2
Note over C: the console validates, then applies
C->>N: the new state
The messages are up to you: only the sequence is imposed.

stateDiagram-v2
[*] --> Waiting
Waiting --> Playing : browser connected
Playing --> Paused : browser lost
Paused --> Playing : browser back
Playing --> End : snake dead
End --> Waiting : START
A phone going to sleep is an event of the state machine, not a surprise.

Eight sessions, five milestones
| Session | Goal |
|---|---|
| P1 | Kick-off, repo, Snake and player 2 on paper |
| P2 | Single-player Snake: grid, movement |
| P3 | Single-player Snake: growth, collisions |
| P4 | The network and the protocol |
| P5 | Player 2: their page, their role |
| P6 | Player 2 integrated into the game |
| P7 | Robustness and tests |
| P8 | Finishing and demonstration |

For the Snake, no tutorial guides you line by line. That is the heart of the project: search, try, compare, choose.
Code found elsewhere (online, AI assistant)? Allowed, if it is understood and cited in your logbook.

| In the repo | Content |
|---|---|
| The board | Taken from Labs 3 and 4: schematic, routing, tests |
| The firmware | Code in modules, state machine, protocol |
| The tests | Each requirement checked, with its result |
| The logbook | One entry per session, with your sources |
| The presentation | A short video or a poster |
And a live demonstration: a complete game, including a browser disconnection.
Project brief Project Methodology

30 %
the labs, board included, already validated in session
70 %
the project: game, player 2, code, repo and demo
A mark shared by the pair: each of you must be able to explain the whole project, including what you did not code.


Goal for the next session: a snake moving on the console.
Creating your repo from the template Project brief
