Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sdk/webpubsub-chat-client/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

# Temporary: Use MyGet feed for @azure scoped packages during preview.
# This will be removed once the package is published to npm.
npmScopes:
azure:
npmRegistryServer: "https://www.myget.org/F/azure-signalr-dev/npm/"
5 changes: 5 additions & 0 deletions sdk/webpubsub-chat-client/examples/battleship/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nodeLinker: node-modules

npmScopes:
azure:
npmRegistryServer: "https://www.myget.org/F/azure-signalr-dev/npm/"
37 changes: 37 additions & 0 deletions sdk/webpubsub-chat-client/examples/battleship/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Battleship

Multiplayer real-time naval combat. Each player gets a grid with randomly placed ships. Attack any opponent's grid — hits and misses appear instantly for all players. Last fleet standing wins.

## How it works

| Feature | Chat SDK API |
|---|---|
| Login | `ChatClient.start(url)` |
| Create game & invite players | `createRoom(title, playerList)` |
| Join game via invitation | `onRoomJoined` |
| Deploy fleet / Fire at opponent | `sendToRoom(roomId, json)` |
| Real-time attack updates | `onMessage` |
| Restore game state on rejoin | `listRoomMessages` |
| See who joined | `onMemberJoined` |

## Prerequisites

1. An Azure Web PubSub resource
2. Node.js 18+

## Run

```bash
cd examples/battleship
yarn install
node server.js "<your-connection-string>"
```

Open **multiple browser tabs** at `http://localhost:3000`, login as different users, and start a game.

## How to Play

- Ships are placed **randomly** when you join a game
- **Free-for-all**: no turns — click any cell on an opponent's board to attack
- A player is **eliminated** when all their ship cells are hit
- Last player alive **wins**
16 changes: 16 additions & 0 deletions sdk/webpubsub-chat-client/examples/battleship/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "battleship-example",
"version": "1.0.0",
"description": "Real-time multiplayer battleship using Web PubSub Chat SDK",
"type": "module",
"scripts": {
"start": "node server.js"
},
"author": "Microsoft",
"license": "MIT",
"dependencies": {
"@azure/web-pubsub": "^1.2.0",
"@azure/web-pubsub-chat-client": "1.0.0-beta.1",
"express": "^5.2.1"
}
}
Loading
Loading