Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd2d9ec309 | ||
|
|
7edf93b707 | ||
|
|
f537b04829 | ||
|
|
0f20ad6e92 |
No files matched your search
-34
@@ -1,34 +0,0 @@
|
||||
# dependencies (bun install)
|
||||
node_modules
|
||||
|
||||
# output
|
||||
out
|
||||
dist
|
||||
*.tgz
|
||||
|
||||
# code coverage
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# logs
|
||||
logs
|
||||
_.log
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# caches
|
||||
.eslintcache
|
||||
.cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
@@ -1,15 +1,30 @@
|
||||
# escape
|
||||
## Daily Survival Goals:
|
||||
|
||||
To install dependencies:
|
||||
To survive on the island, players must have 8 fish and 4 pieces of lumber at the end of each day.
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
Students must choose how many hours they will spend doing different activities at the beginning of the day. They have 16 total hours to work with. They may engage in trade at the end of that if they have met other players who are willing to trade.
|
||||
|
||||
To run:
|
||||
### Time can be spent on:
|
||||
- Fishing
|
||||
- Gathering Wood
|
||||
- Exploring to find other players (1 leisure hour unlocks 3 new players)
|
||||
- Improving their fishing skills/equipment (8 leisure hours improves the next day’s fishing production by 1 per hour)
|
||||
- Improving their gathering wood skills/equipment (8 leisure hours improves the next day’s wood production by 1 per hour)
|
||||
- Build a fish preserver (requires 8 leisure hours and 25 stockpiled wood)
|
||||
- Building a boat (requires a total of 16 hours and 100 stockpiled wood)
|
||||
|
||||
```bash
|
||||
bun run index.ts
|
||||
```
|
||||
### Starting Production Possibilities:
|
||||
- 1 fish per hour and 2 wood per hour or 2 fish per hour and 1 wood per hour
|
||||
|
||||
This project was created using `bun init` in bun v1.4.0. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
||||
### Turn Order:
|
||||
- Set hours of production - Produces fish and lumber.
|
||||
- Trading Phase - You can only trade with “known” players
|
||||
- Survival and Stockpiling - Remove required amount for survival, remaining lumber is stockpiled, the fish goes bad until you build a fish preserver
|
||||
|
||||
### Winning Conditions:
|
||||
- You must have a boat, and 24 fish stockpiled at the beginning of a round to set sail and escape the island!
|
||||
|
||||
### End Discussion Questions:
|
||||
- How did scarcity come into play during this simulation?
|
||||
- How did you determine if and under what terms to trade?
|
||||
- How did your starting production levels determine your success in the game?
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 212 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 11 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB |
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"lockfileVersion": 2,
|
||||
"configVersion": 1,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "escape",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^7",
|
||||
},
|
||||
},
|
||||
},
|
||||
"packages": {
|
||||
"@types/bun": ["@types/bun@1.4.0", "", { "dependencies": { "bun-types": "1.4.0" } }, "sha512-K+lZULY23vRgK/CfTjFIV+tyifaNdSMlPh9j+6mQ/cLfpOznLyAuzgV/JQysyECpkBQLVMSyvjlr2fBUSA9wFQ=="],
|
||||
|
||||
"@types/node": ["@types/node@26.4.1", "", { "dependencies": { "undici-types": "~8.3.0" } }, "sha512-k97ENvZWtvA6yqz5/FS6a7duDgOPEeOQOc2iKS/nY6mX6qJUKtLnWzQS+Xj6tXweyj6ZcTAK2Qecetnvi9nCLA=="],
|
||||
|
||||
"@typescript/typescript-aix-ppc64": ["@typescript/typescript-aix-ppc64@7.0.2", "", { "os": "aix", "cpu": "ppc64" }, "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ=="],
|
||||
|
||||
"@typescript/typescript-darwin-arm64": ["@typescript/typescript-darwin-arm64@7.0.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA=="],
|
||||
|
||||
"@typescript/typescript-darwin-x64": ["@typescript/typescript-darwin-x64@7.0.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA=="],
|
||||
|
||||
"@typescript/typescript-freebsd-arm64": ["@typescript/typescript-freebsd-arm64@7.0.2", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ=="],
|
||||
|
||||
"@typescript/typescript-freebsd-x64": ["@typescript/typescript-freebsd-x64@7.0.2", "", { "os": "freebsd", "cpu": "x64" }, "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw=="],
|
||||
|
||||
"@typescript/typescript-linux-arm": ["@typescript/typescript-linux-arm@7.0.2", "", { "os": "linux", "cpu": "arm" }, "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ=="],
|
||||
|
||||
"@typescript/typescript-linux-arm64": ["@typescript/typescript-linux-arm64@7.0.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ=="],
|
||||
|
||||
"@typescript/typescript-linux-loong64": ["@typescript/typescript-linux-loong64@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ=="],
|
||||
|
||||
"@typescript/typescript-linux-mips64el": ["@typescript/typescript-linux-mips64el@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA=="],
|
||||
|
||||
"@typescript/typescript-linux-ppc64": ["@typescript/typescript-linux-ppc64@7.0.2", "", { "os": "linux", "cpu": "ppc64" }, "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA=="],
|
||||
|
||||
"@typescript/typescript-linux-riscv64": ["@typescript/typescript-linux-riscv64@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ=="],
|
||||
|
||||
"@typescript/typescript-linux-s390x": ["@typescript/typescript-linux-s390x@7.0.2", "", { "os": "linux", "cpu": "s390x" }, "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw=="],
|
||||
|
||||
"@typescript/typescript-linux-x64": ["@typescript/typescript-linux-x64@7.0.2", "", { "os": "linux", "cpu": "x64" }, "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A=="],
|
||||
|
||||
"@typescript/typescript-netbsd-arm64": ["@typescript/typescript-netbsd-arm64@7.0.2", "", { "os": "none", "cpu": "arm64" }, "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA=="],
|
||||
|
||||
"@typescript/typescript-netbsd-x64": ["@typescript/typescript-netbsd-x64@7.0.2", "", { "os": "none", "cpu": "x64" }, "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA=="],
|
||||
|
||||
"@typescript/typescript-openbsd-arm64": ["@typescript/typescript-openbsd-arm64@7.0.2", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ=="],
|
||||
|
||||
"@typescript/typescript-openbsd-x64": ["@typescript/typescript-openbsd-x64@7.0.2", "", { "os": "openbsd", "cpu": "x64" }, "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg=="],
|
||||
|
||||
"@typescript/typescript-sunos-x64": ["@typescript/typescript-sunos-x64@7.0.2", "", { "os": "sunos", "cpu": "x64" }, "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g=="],
|
||||
|
||||
"@typescript/typescript-win32-arm64": ["@typescript/typescript-win32-arm64@7.0.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ=="],
|
||||
|
||||
"@typescript/typescript-win32-x64": ["@typescript/typescript-win32-x64@7.0.2", "", { "os": "win32", "cpu": "x64" }, "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g=="],
|
||||
|
||||
"bun-types": ["bun-types@1.4.0", "", { "dependencies": { "@types/node": "*" } }, "sha512-iIKw23BspnQQYd3prITOBxeUsxBHnwzX6YJfGMuNOZzeNcMmVqzIIVGRm1l69ogaPQmb4wB6BN8mA5bE9YuC5Q=="],
|
||||
|
||||
"typescript": ["typescript@7.0.2", "", { "optionalDependencies": { "@typescript/typescript-aix-ppc64": "7.0.2", "@typescript/typescript-darwin-arm64": "7.0.2", "@typescript/typescript-darwin-x64": "7.0.2", "@typescript/typescript-freebsd-arm64": "7.0.2", "@typescript/typescript-freebsd-x64": "7.0.2", "@typescript/typescript-linux-arm": "7.0.2", "@typescript/typescript-linux-arm64": "7.0.2", "@typescript/typescript-linux-loong64": "7.0.2", "@typescript/typescript-linux-mips64el": "7.0.2", "@typescript/typescript-linux-ppc64": "7.0.2", "@typescript/typescript-linux-riscv64": "7.0.2", "@typescript/typescript-linux-s390x": "7.0.2", "@typescript/typescript-linux-x64": "7.0.2", "@typescript/typescript-netbsd-arm64": "7.0.2", "@typescript/typescript-netbsd-x64": "7.0.2", "@typescript/typescript-openbsd-arm64": "7.0.2", "@typescript/typescript-openbsd-x64": "7.0.2", "@typescript/typescript-sunos-x64": "7.0.2", "@typescript/typescript-win32-arm64": "7.0.2", "@typescript/typescript-win32-x64": "7.0.2" }, "bin": { "tsc": "bin/tsc" } }, "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA=="],
|
||||
|
||||
"undici-types": ["undici-types@8.3.0", "", {}, "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ=="],
|
||||
}
|
||||
}
|
||||
-271
@@ -1,271 +0,0 @@
|
||||
import { createConnection, joinStudentRoom, student } from "./net.js";
|
||||
|
||||
const statusText = document.getElementById("game-status");
|
||||
|
||||
const fishPerHour = document.getElementById("fish_p_hour");
|
||||
const woodPerHour = document.getElementById("wood_p_hour");
|
||||
const fishStored = document.getElementById("fish_stored");
|
||||
const woodStored = document.getElementById("wood_stored");
|
||||
const preserverText = document.getElementById("preserver");
|
||||
const boatText = document.getElementById("boat");
|
||||
const hoursText = document.getElementById("hours");
|
||||
const daysText = document.getElementById("days");
|
||||
const foundText = document.getElementById("found");
|
||||
|
||||
const fishButton = document.getElementById("go-fishing");
|
||||
const forageButton = document.getElementById("go-foraging");
|
||||
const discoverButton = document.getElementById("discover");
|
||||
const foundList = document.getElementById("found-list");
|
||||
const improveFishingButton = document.getElementById("improve-fishing");
|
||||
const improveForagingButton = document.getElementById("improve-foraging");
|
||||
const buildPreserverButton = document.getElementById("build-preserver");
|
||||
const buildBoatButton = document.getElementById("build-boat");
|
||||
|
||||
const identity = student.get();
|
||||
let state = null;
|
||||
let connected = false;
|
||||
let connection = null;
|
||||
|
||||
function setText(element, value) {
|
||||
if (element) element.textContent = String(value);
|
||||
}
|
||||
|
||||
function setStatus(text, tone = "") {
|
||||
if (!statusText) return;
|
||||
statusText.textContent = text;
|
||||
statusText.dataset.tone = tone;
|
||||
}
|
||||
|
||||
function roomProblem(message) {
|
||||
student.clear();
|
||||
window.alert(message || "You are no longer in that room.");
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
function render(nextState) {
|
||||
state = nextState;
|
||||
|
||||
const you = nextState.you;
|
||||
setText(daysText, nextState.day);
|
||||
|
||||
if (you) {
|
||||
setText(foundText, you.found.length);
|
||||
setText(fishPerHour, you.fishingPerHour);
|
||||
setText(woodPerHour, you.foragingPerHour);
|
||||
setText(fishStored, you.fish);
|
||||
setText(woodStored, you.wood);
|
||||
setText(preserverText, you.preserver ? "Yes" : "No");
|
||||
setText(boatText, you.boat ? "Yes" : "No");
|
||||
setText(hoursText, you.hours);
|
||||
|
||||
if (foundList) {
|
||||
foundList.textContent =
|
||||
you.found.length === 0
|
||||
? "No castaways found yet. Use Discover a Castaway."
|
||||
: `Castaways you know: ${you.found.join(", ")}.`;
|
||||
}
|
||||
}
|
||||
|
||||
const active = nextState.phase === "day";
|
||||
const hours = you?.hours ?? 0;
|
||||
|
||||
if (fishButton) fishButton.disabled = !active || hours <= 0;
|
||||
if (forageButton) forageButton.disabled = !active || hours <= 0;
|
||||
|
||||
if (discoverButton) {
|
||||
const usedToday = you?.discoveryDay === nextState.day;
|
||||
const known = you?.found ?? [];
|
||||
const undiscovered = nextState.players.filter(
|
||||
(player) =>
|
||||
player.name !== you?.name && player.connected && !known.includes(player.name),
|
||||
);
|
||||
|
||||
discoverButton.disabled = !active || usedToday || undiscovered.length === 0;
|
||||
discoverButton.textContent = usedToday
|
||||
? "Found Someone Today"
|
||||
: undiscovered.length === 0
|
||||
? "No New Castaways"
|
||||
: "Discover a Castaway";
|
||||
}
|
||||
|
||||
if (improveFishingButton) improveFishingButton.disabled = !active || hours < 8;
|
||||
if (improveForagingButton)
|
||||
improveForagingButton.disabled = !active || hours < 8;
|
||||
if (buildPreserverButton) {
|
||||
buildPreserverButton.disabled =
|
||||
!active || !!you?.preserver || hours < 8 || (you?.wood ?? 0) < 25;
|
||||
}
|
||||
if (buildBoatButton) {
|
||||
buildBoatButton.disabled =
|
||||
!active || !!you?.boat || hours < 16 || (you?.wood ?? 0) < 100;
|
||||
}
|
||||
|
||||
if (!active) return;
|
||||
|
||||
if (hours <= 0) {
|
||||
setStatus(
|
||||
"You are out of hours. Waiting for the rest of the crew to finish.",
|
||||
);
|
||||
} else {
|
||||
setStatus(`Day ${nextState.day}: ${hours} hours left.`, "good");
|
||||
}
|
||||
}
|
||||
|
||||
function askHours(verb) {
|
||||
if (!state?.you) return null;
|
||||
|
||||
const hours = state.you.hours;
|
||||
|
||||
if (hours <= 0) {
|
||||
setStatus("You have no hours left today.");
|
||||
return null;
|
||||
}
|
||||
|
||||
const answer = window.prompt(
|
||||
`How many hours do you want to ${verb}? (1-${hours})`,
|
||||
);
|
||||
if (answer === null) return null;
|
||||
|
||||
const value = Number(answer);
|
||||
|
||||
if (!Number.isInteger(value) || value < 1 || value > hours) {
|
||||
setStatus(`Enter a whole number of hours between 1 and ${hours}.`, "bad");
|
||||
return null;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function sendAction(message) {
|
||||
if (!connected) {
|
||||
setStatus("Not connected yet. Please try again.", "bad");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!connection.send(message)) {
|
||||
setStatus("Not connected yet. Please try again.", "bad");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function goFishing() {
|
||||
const hours = askHours("fish");
|
||||
if (hours === null) return;
|
||||
|
||||
if (sendAction({ type: "FISH", hours })) {
|
||||
setStatus(`Spending ${hours} hours fishing...`);
|
||||
}
|
||||
}
|
||||
|
||||
function goForaging() {
|
||||
const hours = askHours("forage");
|
||||
if (hours === null) return;
|
||||
|
||||
if (sendAction({ type: "FORAGE", hours })) {
|
||||
setStatus(`Spending ${hours} hours foraging...`);
|
||||
}
|
||||
}
|
||||
|
||||
fishButton?.addEventListener("click", goFishing);
|
||||
forageButton?.addEventListener("click", goForaging);
|
||||
|
||||
discoverButton?.addEventListener("click", () => {
|
||||
if (sendAction({ type: "DISCOVER" })) {
|
||||
discoverButton.disabled = true;
|
||||
setStatus("Searching the island for another castaway...");
|
||||
}
|
||||
});
|
||||
|
||||
improveFishingButton?.addEventListener("click", () => {
|
||||
if (sendAction({ type: "IMPROVE_FISHING" })) {
|
||||
setStatus("Spending 8 hours improving fishing...");
|
||||
}
|
||||
});
|
||||
|
||||
improveForagingButton?.addEventListener("click", () => {
|
||||
if (sendAction({ type: "IMPROVE_FORAGING" })) {
|
||||
setStatus("Spending 8 hours improving foraging...");
|
||||
}
|
||||
});
|
||||
|
||||
buildPreserverButton?.addEventListener("click", () => {
|
||||
if (sendAction({ type: "BUILD_PRESERVER" })) {
|
||||
setStatus("Spending 8 hours and 25 wood on a preserver...");
|
||||
}
|
||||
});
|
||||
|
||||
buildBoatButton?.addEventListener("click", () => {
|
||||
if (sendAction({ type: "BUILD_BOAT" })) {
|
||||
setStatus("Spending 16 hours and 100 wood on a boat...");
|
||||
}
|
||||
});
|
||||
|
||||
if (!identity.name || !identity.code) {
|
||||
window.location.href = "/";
|
||||
} else {
|
||||
setStatus("Connecting...");
|
||||
|
||||
const created = createConnection({
|
||||
onOpen(send) {
|
||||
joinStudentRoom(send);
|
||||
},
|
||||
|
||||
onStatus(status) {
|
||||
connected = status === "connected";
|
||||
|
||||
if (status === "connecting") {
|
||||
setStatus("Connecting...");
|
||||
} else if (status === "connected") {
|
||||
if (!state) setStatus("Connected. Loading the day...");
|
||||
} else if (status === "replaced") {
|
||||
student.clear();
|
||||
window.alert(
|
||||
"This game was opened in another tab. This tab has been disconnected.",
|
||||
);
|
||||
window.location.href = "/";
|
||||
} else if (status === "error") {
|
||||
setStatus("Connection error. Retrying...", "bad");
|
||||
} else {
|
||||
setStatus("Connection lost. Reconnecting...", "bad");
|
||||
}
|
||||
},
|
||||
|
||||
onMessage(data) {
|
||||
if (data.type === "SYNC") {
|
||||
if (data.phase === "lobby") {
|
||||
window.location.href = "/waiting";
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.phase === "trading") {
|
||||
window.location.href = "/trading";
|
||||
return;
|
||||
}
|
||||
|
||||
render(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "NOTICE") {
|
||||
setStatus(data.message || "", data.tone || "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type !== "ERROR") return;
|
||||
|
||||
if (
|
||||
data.code === "ROOM_NOT_FOUND" ||
|
||||
/already in use/i.test(data.message ?? "")
|
||||
) {
|
||||
roomProblem(data.message);
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus(data.message || "Something went wrong.", "bad");
|
||||
},
|
||||
});
|
||||
|
||||
connection = created;
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
import { createConnection, getClientId, student } from "./net.js";
|
||||
|
||||
const nameInput = document.getElementById("name");
|
||||
const codeInput = document.getElementById("join-code");
|
||||
const joinForm = document.getElementById("join-form");
|
||||
const joinButton = document.getElementById("join-button");
|
||||
const statusText = document.getElementById("join-status");
|
||||
|
||||
let connected = false;
|
||||
let pendingJoin = null;
|
||||
|
||||
function setStatus(text) {
|
||||
if (statusText) statusText.textContent = text;
|
||||
}
|
||||
|
||||
function updateButton() {
|
||||
joinButton.disabled = !connected || pendingJoin !== null;
|
||||
joinButton.textContent = pendingJoin
|
||||
? "Joining..."
|
||||
: connected
|
||||
? "Join as Student"
|
||||
: "Connecting...";
|
||||
}
|
||||
|
||||
function sendJoin(send) {
|
||||
if (!pendingJoin) return;
|
||||
|
||||
const sent = send({
|
||||
type: "JOIN_ROOM",
|
||||
name: pendingJoin.name,
|
||||
code: pendingJoin.code,
|
||||
clientId: getClientId(),
|
||||
});
|
||||
|
||||
if (!sent) {
|
||||
pendingJoin = null;
|
||||
updateButton();
|
||||
setStatus("Not connected yet. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
const connection = createConnection({
|
||||
onOpen(send) {
|
||||
// If the connection dropped while joining, try again automatically.
|
||||
sendJoin(send);
|
||||
},
|
||||
|
||||
onStatus(status) {
|
||||
connected = status === "connected";
|
||||
|
||||
if (status === "connected") {
|
||||
setStatus("Connected. Enter your name and room code.");
|
||||
} else if (status === "connecting") {
|
||||
setStatus("Connecting to the game server...");
|
||||
} else if (status === "replaced") {
|
||||
setStatus("This page was replaced by another tab. Close this tab.");
|
||||
joinButton.disabled = true;
|
||||
return;
|
||||
} else if (status === "error") {
|
||||
setStatus("Connection error. Retrying...");
|
||||
} else {
|
||||
setStatus("Connection lost. Reconnecting...");
|
||||
}
|
||||
|
||||
updateButton();
|
||||
},
|
||||
|
||||
onMessage(data) {
|
||||
if (data.type === "JOIN_SUCCESS") {
|
||||
if (!pendingJoin) return;
|
||||
|
||||
student.save(pendingJoin.name, pendingJoin.code);
|
||||
window.location.href = "/waiting";
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "ERROR") {
|
||||
const message =
|
||||
data.code === "ROOM_NOT_FOUND"
|
||||
? "No room has that code. Check the code with your teacher."
|
||||
: data.message || "Could not join the room.";
|
||||
|
||||
pendingJoin = null;
|
||||
setStatus(message);
|
||||
updateButton();
|
||||
window.alert(message);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
joinForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
if (!connected || pendingJoin) return;
|
||||
|
||||
const name = nameInput.value.trim();
|
||||
const code = codeInput.value.trim();
|
||||
|
||||
if (!name || !code) {
|
||||
window.alert("Please enter both your name and a room code!");
|
||||
return;
|
||||
}
|
||||
|
||||
pendingJoin = { name, code };
|
||||
updateButton();
|
||||
setStatus("Joining room " + code + "...");
|
||||
|
||||
sendJoin(connection.send);
|
||||
});
|
||||
|
||||
updateButton();
|
||||
-272
@@ -1,272 +0,0 @@
|
||||
import { createConnection, resumeTeacherRoom, teacher } from "./net.js";
|
||||
|
||||
const hostButton = document.getElementById("host-btn");
|
||||
const roomCodeText = document.getElementById("room-code");
|
||||
const statusText = document.getElementById("lobby-status");
|
||||
const rosterPanel = document.getElementById("roster-panel");
|
||||
const rosterBody = document.getElementById("roster-body");
|
||||
const playerCount = document.getElementById("player-count");
|
||||
|
||||
const phasePanel = document.getElementById("phase-panel");
|
||||
const phaseText = document.getElementById("phase-text");
|
||||
const dayText = document.getElementById("day-text");
|
||||
const phaseStatus = document.getElementById("phase-status");
|
||||
const startGameButton = document.getElementById("start-game-btn");
|
||||
const endDayButton = document.getElementById("end-day-btn");
|
||||
const nextDayButton = document.getElementById("next-day-btn");
|
||||
|
||||
let connected = false;
|
||||
let roomOpen = false;
|
||||
let creating = false;
|
||||
let resuming = false;
|
||||
let room = null;
|
||||
|
||||
const PHASE_LABELS = {
|
||||
lobby: "Lobby",
|
||||
day: "Day",
|
||||
trading: "Trading",
|
||||
};
|
||||
|
||||
function setStatus(text, tone = "") {
|
||||
statusText.textContent = text;
|
||||
statusText.dataset.tone = tone;
|
||||
}
|
||||
|
||||
function setPhaseStatus(text, tone = "") {
|
||||
phaseStatus.textContent = text;
|
||||
phaseStatus.dataset.tone = tone;
|
||||
}
|
||||
|
||||
function updateControls() {
|
||||
if (roomOpen) {
|
||||
hostButton.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
hostButton.hidden = false;
|
||||
hostButton.disabled = !connected || creating || resuming;
|
||||
|
||||
if (resuming) {
|
||||
hostButton.textContent = "Reconnecting...";
|
||||
} else if (creating) {
|
||||
hostButton.textContent = "Creating room...";
|
||||
} else if (connected) {
|
||||
hostButton.textContent = "Create Room";
|
||||
} else {
|
||||
hostButton.textContent = "Connecting...";
|
||||
}
|
||||
}
|
||||
|
||||
function updatePhaseControls() {
|
||||
if (!room) {
|
||||
phasePanel.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
phasePanel.hidden = false;
|
||||
phaseText.textContent = PHASE_LABELS[room.phase] ?? room.phase;
|
||||
dayText.textContent = String(room.day);
|
||||
|
||||
const hasPlayers = room.players.length > 0;
|
||||
|
||||
startGameButton.hidden = room.phase !== "lobby";
|
||||
startGameButton.disabled = !connected || !hasPlayers;
|
||||
|
||||
endDayButton.hidden = room.phase !== "day";
|
||||
endDayButton.disabled = !connected;
|
||||
|
||||
nextDayButton.hidden = room.phase !== "trading";
|
||||
nextDayButton.disabled = !connected;
|
||||
|
||||
if (!hasPlayers && room.phase === "lobby") {
|
||||
setPhaseStatus("Waiting for at least one student before you can start.");
|
||||
} else if (room.phase === "lobby") {
|
||||
setPhaseStatus("The crew is ready when you are.");
|
||||
} else if (room.phase === "day") {
|
||||
setPhaseStatus("Students are spending their hours.");
|
||||
} else if (room.phase === "trading") {
|
||||
setPhaseStatus("Trading is open. Start the next day when ready.");
|
||||
} else {
|
||||
setPhaseStatus("");
|
||||
}
|
||||
}
|
||||
|
||||
function showRoom(code) {
|
||||
roomOpen = true;
|
||||
roomCodeText.textContent = code;
|
||||
rosterPanel.hidden = false;
|
||||
updateControls();
|
||||
}
|
||||
|
||||
function makeCell(text, className) {
|
||||
const cell = document.createElement("td");
|
||||
cell.textContent = text;
|
||||
if (className) cell.className = className;
|
||||
return cell;
|
||||
}
|
||||
|
||||
function makePlayerRow(player) {
|
||||
const row = document.createElement("tr");
|
||||
row.append(
|
||||
makeCell(player.name),
|
||||
makeCell(String(player.fish)),
|
||||
makeCell(String(player.wood)),
|
||||
makeCell(String(player.hours)),
|
||||
makeCell(
|
||||
player.connected ? "Connected" : "Offline",
|
||||
player.connected ? "online" : "offline",
|
||||
),
|
||||
);
|
||||
return row;
|
||||
}
|
||||
|
||||
function renderRoster(players) {
|
||||
playerCount.textContent = String(players.length);
|
||||
|
||||
if (players.length === 0) {
|
||||
const row = document.createElement("tr");
|
||||
const cell = makeCell("No students have joined yet.", "empty");
|
||||
cell.colSpan = 5;
|
||||
row.append(cell);
|
||||
rosterBody.replaceChildren(row);
|
||||
return;
|
||||
}
|
||||
|
||||
rosterBody.replaceChildren(...players.map(makePlayerRow));
|
||||
}
|
||||
|
||||
function handleSync(data) {
|
||||
room = {
|
||||
phase: data.phase,
|
||||
day: data.day,
|
||||
players: Array.isArray(data.players) ? data.players : [],
|
||||
};
|
||||
|
||||
showRoom(data.code);
|
||||
renderRoster(room.players);
|
||||
updatePhaseControls();
|
||||
}
|
||||
|
||||
const connection = createConnection({
|
||||
onOpen(send) {
|
||||
const saved = teacher.get();
|
||||
|
||||
if (saved.code && saved.token) {
|
||||
resuming = true;
|
||||
updateControls();
|
||||
setStatus("Restoring your room...");
|
||||
resumeTeacherRoom(send);
|
||||
}
|
||||
},
|
||||
|
||||
onStatus(status) {
|
||||
connected = status === "connected";
|
||||
|
||||
if (status === "connected") {
|
||||
if (!roomOpen) {
|
||||
setStatus(
|
||||
resuming
|
||||
? "Restoring your room..."
|
||||
: "Connected. Create a room to begin.",
|
||||
);
|
||||
}
|
||||
} else if (status === "connecting") {
|
||||
setStatus("Connecting to the game server...");
|
||||
} else if (status === "replaced") {
|
||||
setStatus("This lobby was opened in another tab. Close this tab.");
|
||||
hostButton.disabled = true;
|
||||
return;
|
||||
} else if (status === "error") {
|
||||
setStatus("Connection error. Retrying...");
|
||||
} else {
|
||||
setStatus("Connection lost. Reconnecting...");
|
||||
}
|
||||
|
||||
updateControls();
|
||||
updatePhaseControls();
|
||||
},
|
||||
|
||||
onMessage(data) {
|
||||
if (data.type === "ROOM_CREATED") {
|
||||
teacher.save(data.code, data.token);
|
||||
creating = false;
|
||||
resuming = false;
|
||||
showRoom(data.code);
|
||||
setStatus("Room open. Share the code with your students.", "good");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "ROOM_RESUMED") {
|
||||
creating = false;
|
||||
resuming = false;
|
||||
showRoom(data.code);
|
||||
setStatus("Room restored. Students can keep joining.", "good");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "SYNC") {
|
||||
handleSync(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "ERROR") {
|
||||
creating = false;
|
||||
resuming = false;
|
||||
|
||||
if (data.code === "ROOM_NOT_FOUND") {
|
||||
teacher.clear();
|
||||
roomOpen = false;
|
||||
room = null;
|
||||
roomCodeText.textContent = "----";
|
||||
rosterPanel.hidden = true;
|
||||
phasePanel.hidden = true;
|
||||
setStatus("That room no longer exists. Create a new one.", "bad");
|
||||
} else if (roomOpen) {
|
||||
setPhaseStatus(data.message || "Something went wrong.", "bad");
|
||||
} else {
|
||||
setStatus(data.message || "Something went wrong.", "bad");
|
||||
}
|
||||
|
||||
updateControls();
|
||||
updatePhaseControls();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function sendAction(type) {
|
||||
if (!connected) return;
|
||||
|
||||
setPhaseStatus(
|
||||
type === "START_GAME"
|
||||
? "Starting the game..."
|
||||
: type === "END_DAY"
|
||||
? "Ending the day..."
|
||||
: "Starting the next day...",
|
||||
);
|
||||
|
||||
if (!connection.send({ type })) {
|
||||
setPhaseStatus("Not connected yet. Please try again.", "bad");
|
||||
}
|
||||
}
|
||||
|
||||
hostButton.addEventListener("click", () => {
|
||||
if (!connected || creating || resuming) return;
|
||||
|
||||
creating = true;
|
||||
updateControls();
|
||||
setStatus("Creating room...");
|
||||
|
||||
if (!connection.send({ type: "CREATE_ROOM" })) {
|
||||
creating = false;
|
||||
updateControls();
|
||||
setStatus("Not connected yet. Please try again.", "bad");
|
||||
}
|
||||
});
|
||||
|
||||
startGameButton.addEventListener("click", () => sendAction("START_GAME"));
|
||||
endDayButton.addEventListener("click", () => sendAction("END_DAY"));
|
||||
nextDayButton.addEventListener("click", () => sendAction("NEXT_DAY"));
|
||||
|
||||
roomCodeText.textContent = teacher.get().code || "----";
|
||||
updateControls();
|
||||
updatePhaseControls();
|
||||
-182
@@ -1,182 +0,0 @@
|
||||
// Shared browser networking for every page.
|
||||
//
|
||||
// The server is authoritative. Pages send intents (JOIN_ROOM, CREATE_ROOM,
|
||||
// PING, ...) and render what the server sends back. This file only knows about
|
||||
// transport: connection, reconnection, heartbeat, and per-tab identity.
|
||||
|
||||
const wsProtocol = location.protocol === "https:" ? "wss:" : "ws:";
|
||||
export const WS_URL = `${wsProtocol}//${location.host}/ws`;
|
||||
|
||||
export function getClientId() {
|
||||
let clientId = sessionStorage.getItem("clientId");
|
||||
|
||||
if (!clientId) {
|
||||
clientId =
|
||||
crypto.randomUUID?.() ??
|
||||
Math.random().toString(36).slice(2) + Date.now().toString(36);
|
||||
sessionStorage.setItem("clientId", clientId);
|
||||
}
|
||||
|
||||
return clientId;
|
||||
}
|
||||
|
||||
export const student = {
|
||||
get() {
|
||||
return {
|
||||
name: sessionStorage.getItem("playerName") ?? "",
|
||||
code: sessionStorage.getItem("roomCode") ?? "",
|
||||
clientId: getClientId(),
|
||||
};
|
||||
},
|
||||
|
||||
save(name, code) {
|
||||
sessionStorage.setItem("playerName", name);
|
||||
sessionStorage.setItem("roomCode", code);
|
||||
},
|
||||
|
||||
clear() {
|
||||
sessionStorage.removeItem("playerName");
|
||||
sessionStorage.removeItem("roomCode");
|
||||
},
|
||||
};
|
||||
|
||||
export const teacher = {
|
||||
get() {
|
||||
return {
|
||||
code: sessionStorage.getItem("teacherCode") ?? "",
|
||||
token: sessionStorage.getItem("teacherToken") ?? "",
|
||||
};
|
||||
},
|
||||
|
||||
save(code, token) {
|
||||
sessionStorage.setItem("teacherCode", code);
|
||||
sessionStorage.setItem("teacherToken", token);
|
||||
},
|
||||
|
||||
clear() {
|
||||
sessionStorage.removeItem("teacherCode");
|
||||
sessionStorage.removeItem("teacherToken");
|
||||
},
|
||||
};
|
||||
|
||||
// Tell the server which student this tab belongs to.
|
||||
export function joinStudentRoom(send) {
|
||||
const { name, code, clientId } = student.get();
|
||||
|
||||
if (!name || !code) {
|
||||
location.href = "/";
|
||||
return false;
|
||||
}
|
||||
|
||||
return send({ type: "JOIN_ROOM", name, code, clientId });
|
||||
}
|
||||
|
||||
// Reclaim a room the teacher already created in this tab.
|
||||
export function resumeTeacherRoom(send) {
|
||||
const { code, token } = teacher.get();
|
||||
|
||||
if (!code || !token) return false;
|
||||
|
||||
return send({ type: "RESUME_TEACHER", code, token });
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a WebSocket and keep it open.
|
||||
*
|
||||
* Options:
|
||||
* onMessage(data) called for every non-PONG server message
|
||||
* onStatus(status) "connecting" | "connected" | "disconnected" |
|
||||
* "error" | "replaced"
|
||||
* onOpen(send) called after each successful (re)connection, so the page
|
||||
* can re-announce who it is
|
||||
*
|
||||
* Returns { send, close } where send() returns false when the socket is not
|
||||
* ready instead of throwing.
|
||||
*/
|
||||
export function createConnection({ onMessage, onStatus = () => {}, onOpen } = {}) {
|
||||
let socket = null;
|
||||
let heartbeat = null;
|
||||
let reconnectTimer = null;
|
||||
let reconnectDelay = 1000;
|
||||
let unloading = false;
|
||||
|
||||
window.addEventListener("beforeunload", () => {
|
||||
unloading = true;
|
||||
});
|
||||
|
||||
function send(message) {
|
||||
if (!socket || socket.readyState !== WebSocket.OPEN) return false;
|
||||
socket.send(JSON.stringify(message));
|
||||
return true;
|
||||
}
|
||||
|
||||
function connect() {
|
||||
onStatus("connecting");
|
||||
|
||||
const ws = new WebSocket(WS_URL);
|
||||
socket = ws;
|
||||
|
||||
ws.onopen = () => {
|
||||
if (socket !== ws) return;
|
||||
|
||||
clearTimeout(reconnectTimer);
|
||||
reconnectTimer = null;
|
||||
reconnectDelay = 1000;
|
||||
|
||||
clearInterval(heartbeat);
|
||||
heartbeat = setInterval(() => {
|
||||
if (socket?.readyState === WebSocket.OPEN) {
|
||||
socket.send(JSON.stringify({ type: "PING" }));
|
||||
}
|
||||
}, 25000);
|
||||
|
||||
onStatus("connected");
|
||||
onOpen?.(send);
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
if (socket !== ws) return;
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(event.data);
|
||||
} catch {
|
||||
console.warn("Ignored a non-JSON server message");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "PONG") return;
|
||||
onMessage?.(data);
|
||||
};
|
||||
|
||||
ws.onclose = (event) => {
|
||||
if (socket !== ws) return;
|
||||
|
||||
socket = null;
|
||||
clearInterval(heartbeat);
|
||||
heartbeat = null;
|
||||
|
||||
// 4000 = the server found a newer connection for this identity. Do not
|
||||
// reconnect, or two tabs will keep taking the room from each other.
|
||||
if (event.code === 4000) {
|
||||
onStatus("replaced");
|
||||
return;
|
||||
}
|
||||
|
||||
onStatus("disconnected");
|
||||
|
||||
if (unloading) return;
|
||||
|
||||
reconnectTimer = setTimeout(connect, reconnectDelay);
|
||||
reconnectDelay = Math.min(reconnectDelay * 2, 10000);
|
||||
};
|
||||
|
||||
ws.onerror = () => {
|
||||
if (socket === ws) onStatus("error");
|
||||
};
|
||||
}
|
||||
|
||||
connect();
|
||||
|
||||
return { send };
|
||||
}
|
||||
@@ -1,438 +0,0 @@
|
||||
import { createConnection, joinStudentRoom, student } from "./net.js";
|
||||
|
||||
const dayText = document.getElementById("trade-day");
|
||||
const fishText = document.getElementById("trade-fish");
|
||||
const woodText = document.getElementById("trade-wood");
|
||||
const statusText = document.getElementById("trade-status");
|
||||
const foundList = document.getElementById("trade-found-list");
|
||||
|
||||
const offerPanel = document.getElementById("trade-offer-panel");
|
||||
const offerForm = document.getElementById("trade-offer-form");
|
||||
const targetSelect = document.getElementById("trade-target");
|
||||
const giveFishInput = document.getElementById("trade-give-fish");
|
||||
const giveWoodInput = document.getElementById("trade-give-wood");
|
||||
const wantFishInput = document.getElementById("trade-want-fish");
|
||||
const wantWoodInput = document.getElementById("trade-want-wood");
|
||||
const offerStatus = document.getElementById("trade-offer-status");
|
||||
|
||||
const incomingPanel = document.getElementById("trade-incoming-panel");
|
||||
const incomingList = document.getElementById("trade-incoming-list");
|
||||
const outgoingPanel = document.getElementById("trade-outgoing-panel");
|
||||
const outgoingList = document.getElementById("trade-outgoing-list");
|
||||
|
||||
const rosterPanel = document.getElementById("trade-roster-panel");
|
||||
const rosterBody = document.getElementById("trade-roster-body");
|
||||
|
||||
const identity = student.get();
|
||||
let state = null;
|
||||
let connected = false;
|
||||
let connection = null;
|
||||
let hasRendered = false;
|
||||
|
||||
function setStatus(text, tone = "") {
|
||||
statusText.textContent = text;
|
||||
statusText.dataset.tone = tone;
|
||||
}
|
||||
|
||||
function setOfferStatus(text, tone = "") {
|
||||
offerStatus.textContent = text;
|
||||
offerStatus.dataset.tone = tone;
|
||||
}
|
||||
|
||||
function makeCell(text, className) {
|
||||
const cell = document.createElement("td");
|
||||
cell.textContent = text;
|
||||
if (className) cell.className = className;
|
||||
return cell;
|
||||
}
|
||||
|
||||
function makePlayerRow(player) {
|
||||
const row = document.createElement("tr");
|
||||
row.append(
|
||||
makeCell(player.name),
|
||||
makeCell(String(player.fish)),
|
||||
makeCell(String(player.wood)),
|
||||
makeCell(player.preserver ? "Yes" : "No"),
|
||||
makeCell(player.boat ? "Yes" : "No"),
|
||||
);
|
||||
|
||||
if (!player.connected) row.classList.add("offline-player");
|
||||
return row;
|
||||
}
|
||||
|
||||
function renderRoster(players) {
|
||||
rosterPanel.hidden = false;
|
||||
|
||||
const known = new Set(state?.you?.found ?? []);
|
||||
const visible = players.filter((player) => known.has(player.name));
|
||||
|
||||
if (visible.length === 0) {
|
||||
const row = document.createElement("tr");
|
||||
const cell = makeCell(
|
||||
"You have not found any castaways to trade with yet.",
|
||||
"empty",
|
||||
);
|
||||
cell.colSpan = 5;
|
||||
row.append(cell);
|
||||
rosterBody.replaceChildren(row);
|
||||
return;
|
||||
}
|
||||
|
||||
rosterBody.replaceChildren(...visible.map(makePlayerRow));
|
||||
}
|
||||
|
||||
function renderFound(found) {
|
||||
if (found.length === 0) {
|
||||
foundList.textContent =
|
||||
"No one yet. You can only trade with castaways you found during the day.";
|
||||
offerPanel.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
foundList.textContent = `You know: ${found.join(", ")}.`;
|
||||
offerPanel.hidden = false;
|
||||
|
||||
const names = [...found].sort((a, b) => a.localeCompare(b));
|
||||
const signature = names.join("\u0000");
|
||||
|
||||
if (targetSelect.dataset.signature !== signature) {
|
||||
const current = targetSelect.value;
|
||||
targetSelect.replaceChildren(
|
||||
...names.map((name) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = name;
|
||||
option.textContent = name;
|
||||
return option;
|
||||
}),
|
||||
);
|
||||
targetSelect.dataset.signature = signature;
|
||||
|
||||
if (names.includes(current)) targetSelect.value = current;
|
||||
}
|
||||
|
||||
updateTradeLimits();
|
||||
}
|
||||
|
||||
function selectedTarget() {
|
||||
if (!state?.players) return null;
|
||||
|
||||
return (
|
||||
state.players.find((player) => player.name === targetSelect.value) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
function clampAmount(input, max) {
|
||||
const limit = Math.max(0, max);
|
||||
input.max = String(limit);
|
||||
|
||||
const value = Number(input.value);
|
||||
if (input.value.trim() === "" || !Number.isFinite(value)) return;
|
||||
|
||||
if (value > limit) input.value = String(limit);
|
||||
else if (value < 0) input.value = "0";
|
||||
}
|
||||
|
||||
function updateTradeLimits() {
|
||||
const you = state?.you;
|
||||
const target = selectedTarget();
|
||||
|
||||
clampAmount(giveFishInput, you?.fish ?? 0);
|
||||
clampAmount(giveWoodInput, you?.wood ?? 0);
|
||||
clampAmount(wantFishInput, target?.fish ?? 0);
|
||||
clampAmount(wantWoodInput, target?.wood ?? 0);
|
||||
}
|
||||
|
||||
targetSelect.addEventListener("change", updateTradeLimits);
|
||||
|
||||
for (const input of [giveFishInput, giveWoodInput, wantFishInput, wantWoodInput]) {
|
||||
input.addEventListener("input", updateTradeLimits);
|
||||
}
|
||||
|
||||
function describeItems(fish, wood) {
|
||||
const parts = [];
|
||||
|
||||
if (fish > 0) parts.push(`${fish} fish`);
|
||||
if (wood > 0) parts.push(`${wood} wood`);
|
||||
|
||||
return parts.length > 0 ? parts.join(" and ") : "nothing";
|
||||
}
|
||||
|
||||
function makeOfferCard(offer) {
|
||||
const card = document.createElement("article");
|
||||
card.className = "offer-card";
|
||||
|
||||
const summary = document.createElement("p");
|
||||
summary.className = "offer-summary";
|
||||
|
||||
if (offer.incoming) {
|
||||
const who = document.createElement("strong");
|
||||
who.textContent = offer.from;
|
||||
summary.append(
|
||||
who,
|
||||
document.createTextNode(
|
||||
` gives ${describeItems(offer.giveFish, offer.giveWood)} and wants ` +
|
||||
`${describeItems(offer.wantFish, offer.wantWood)} from you.`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
summary.append(
|
||||
document.createTextNode(
|
||||
`You give ${describeItems(offer.giveFish, offer.giveWood)} to ` +
|
||||
`${offer.to} and want ` +
|
||||
`${describeItems(offer.wantFish, offer.wantWood)} in return.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const actions = document.createElement("div");
|
||||
actions.className = "offer-actions";
|
||||
|
||||
if (offer.incoming) {
|
||||
const accept = document.createElement("button");
|
||||
accept.type = "button";
|
||||
accept.className = "btn-primary btn-small";
|
||||
accept.dataset.action = "accept";
|
||||
accept.dataset.id = offer.id;
|
||||
accept.textContent = "Accept";
|
||||
|
||||
const decline = document.createElement("button");
|
||||
decline.type = "button";
|
||||
decline.className = "btn-quiet btn-small";
|
||||
decline.dataset.action = "decline";
|
||||
decline.dataset.id = offer.id;
|
||||
decline.textContent = "Decline";
|
||||
|
||||
actions.append(accept, decline);
|
||||
} else {
|
||||
const cancel = document.createElement("button");
|
||||
cancel.type = "button";
|
||||
cancel.className = "btn-quiet btn-small";
|
||||
cancel.dataset.action = "cancel";
|
||||
cancel.dataset.id = offer.id;
|
||||
cancel.textContent = "Cancel Offer";
|
||||
|
||||
actions.append(cancel);
|
||||
}
|
||||
|
||||
card.append(summary, actions);
|
||||
return card;
|
||||
}
|
||||
|
||||
function renderOffers(offers) {
|
||||
const incoming = offers.filter((offer) => offer.incoming);
|
||||
const outgoing = offers.filter((offer) => !offer.incoming);
|
||||
|
||||
incomingPanel.hidden = incoming.length === 0;
|
||||
outgoingPanel.hidden = outgoing.length === 0;
|
||||
|
||||
incomingList.replaceChildren(...incoming.map(makeOfferCard));
|
||||
outgoingList.replaceChildren(...outgoing.map(makeOfferCard));
|
||||
}
|
||||
|
||||
function render(nextState) {
|
||||
state = nextState;
|
||||
|
||||
dayText.textContent = String(nextState.day);
|
||||
|
||||
if (nextState.you) {
|
||||
fishText.textContent = String(nextState.you.fish);
|
||||
woodText.textContent = String(nextState.you.wood);
|
||||
renderFound(nextState.you.found ?? []);
|
||||
}
|
||||
|
||||
renderRoster(nextState.players);
|
||||
renderOffers(Array.isArray(nextState.offers) ? nextState.offers : []);
|
||||
|
||||
if (!hasRendered) {
|
||||
setStatus(
|
||||
"Trading is open. Make an offer to a castaway you found during the day.",
|
||||
"good",
|
||||
);
|
||||
hasRendered = true;
|
||||
}
|
||||
}
|
||||
|
||||
function roomProblem(message) {
|
||||
student.clear();
|
||||
window.alert(message || "You are no longer in that room.");
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
function sendAction(message) {
|
||||
if (!connected) {
|
||||
setStatus("Not connected yet. Please try again.", "bad");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!connection.send(message)) {
|
||||
setStatus("Not connected yet. Please try again.", "bad");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function amountFrom(input) {
|
||||
if (input.value.trim() === "") return 0;
|
||||
|
||||
const amount = Number(input.value);
|
||||
return Number.isInteger(amount) && amount >= 0 ? amount : null;
|
||||
}
|
||||
|
||||
offerForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (!state?.you) return;
|
||||
|
||||
const target = targetSelect.value;
|
||||
if (!target) {
|
||||
setOfferStatus("Find a castaway to trade with first.", "bad");
|
||||
return;
|
||||
}
|
||||
|
||||
const giveFish = amountFrom(giveFishInput);
|
||||
const giveWood = amountFrom(giveWoodInput);
|
||||
const wantFish = amountFrom(wantFishInput);
|
||||
const wantWood = amountFrom(wantWoodInput);
|
||||
|
||||
if (
|
||||
giveFish === null ||
|
||||
giveWood === null ||
|
||||
wantFish === null ||
|
||||
wantWood === null
|
||||
) {
|
||||
setOfferStatus("Use whole numbers of 0 or more.", "bad");
|
||||
return;
|
||||
}
|
||||
|
||||
if (giveFish + giveWood + wantFish + wantWood === 0) {
|
||||
setOfferStatus("Offer at least one fish or piece of wood.", "bad");
|
||||
return;
|
||||
}
|
||||
|
||||
const targetPlayer = selectedTarget();
|
||||
|
||||
if (giveFish > state.you.fish || giveWood > state.you.wood) {
|
||||
setOfferStatus("You do not have enough supplies for that offer.", "bad");
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
targetPlayer &&
|
||||
(wantFish > targetPlayer.fish || wantWood > targetPlayer.wood)
|
||||
) {
|
||||
setOfferStatus(
|
||||
`${target} does not have enough supplies for that offer.`,
|
||||
"bad",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
sendAction({
|
||||
type: "TRADE_OFFER",
|
||||
to: target,
|
||||
giveFish,
|
||||
giveWood,
|
||||
wantFish,
|
||||
wantWood,
|
||||
})
|
||||
) {
|
||||
setOfferStatus(`Offer sent to ${target}.`);
|
||||
giveFishInput.value = "0";
|
||||
giveWoodInput.value = "0";
|
||||
wantFishInput.value = "0";
|
||||
wantWoodInput.value = "0";
|
||||
}
|
||||
});
|
||||
|
||||
function handleOfferAction(event) {
|
||||
const button = event.target.closest("button[data-action]");
|
||||
if (!button) return;
|
||||
|
||||
const action = button.dataset.action;
|
||||
const id = button.dataset.id;
|
||||
|
||||
const messages = {
|
||||
accept: { type: "TRADE_ACCEPT", id, label: "Accepting the offer..." },
|
||||
decline: { type: "TRADE_DECLINE", id, label: "Declining the offer..." },
|
||||
cancel: { type: "TRADE_CANCEL", id, label: "Cancelling the offer..." },
|
||||
};
|
||||
|
||||
const pending = messages[action];
|
||||
if (!pending) return;
|
||||
|
||||
if (sendAction({ type: pending.type, id: pending.id })) {
|
||||
button.disabled = true;
|
||||
setOfferStatus(pending.label);
|
||||
}
|
||||
}
|
||||
|
||||
incomingList.addEventListener("click", handleOfferAction);
|
||||
outgoingList.addEventListener("click", handleOfferAction);
|
||||
|
||||
if (!identity.name || !identity.code) {
|
||||
window.location.href = "/";
|
||||
} else {
|
||||
connection = createConnection({
|
||||
onOpen(send) {
|
||||
joinStudentRoom(send);
|
||||
},
|
||||
|
||||
onStatus(status) {
|
||||
connected = status === "connected";
|
||||
|
||||
if (status === "connecting") {
|
||||
if (!state) setStatus("Connecting...");
|
||||
} else if (status === "connected") {
|
||||
if (!state) setStatus("Connected. Loading the trading post...");
|
||||
} else if (status === "replaced") {
|
||||
student.clear();
|
||||
window.alert(
|
||||
"This game was opened in another tab. This tab has been disconnected.",
|
||||
);
|
||||
window.location.href = "/";
|
||||
} else if (status === "error") {
|
||||
setStatus("Connection error. Retrying...", "bad");
|
||||
} else {
|
||||
setStatus("Connection lost. Reconnecting...", "bad");
|
||||
}
|
||||
},
|
||||
|
||||
onMessage(data) {
|
||||
if (data.type === "SYNC") {
|
||||
if (data.phase === "day") {
|
||||
window.location.href = "/game";
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.phase === "lobby") {
|
||||
window.location.href = "/waiting";
|
||||
return;
|
||||
}
|
||||
|
||||
render(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "NOTICE") {
|
||||
setStatus(data.message || "", data.tone || "");
|
||||
setOfferStatus(data.message || "", data.tone || "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type !== "ERROR") return;
|
||||
|
||||
if (
|
||||
data.code === "ROOM_NOT_FOUND" ||
|
||||
/already in use/i.test(data.message ?? "")
|
||||
) {
|
||||
roomProblem(data.message);
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus(data.message || "Something went wrong.", "bad");
|
||||
setOfferStatus(data.message || "Something went wrong.", "bad");
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
import { createConnection, joinStudentRoom, student } from "./net.js";
|
||||
|
||||
const nameText = document.getElementById("waiting-name");
|
||||
const codeText = document.getElementById("waiting-code");
|
||||
const statusText = document.getElementById("waiting-status");
|
||||
|
||||
const identity = student.get();
|
||||
|
||||
if (!identity.name || !identity.code) {
|
||||
window.location.href = "/";
|
||||
} else {
|
||||
nameText.textContent = identity.name;
|
||||
codeText.textContent = identity.code;
|
||||
|
||||
createConnection({
|
||||
onOpen(send) {
|
||||
joinStudentRoom(send);
|
||||
},
|
||||
|
||||
onStatus(status) {
|
||||
if (status === "connected") {
|
||||
setStatus("Connected. Waiting for the teacher to start...");
|
||||
} else if (status === "connecting") {
|
||||
setStatus("Connecting...");
|
||||
} else if (status === "replaced") {
|
||||
setStatus("This room was opened in another tab. You can close this tab.");
|
||||
} else if (status === "error") {
|
||||
setStatus("Connection error. Retrying...");
|
||||
} else {
|
||||
setStatus("Connection lost. Reconnecting...");
|
||||
}
|
||||
},
|
||||
|
||||
onMessage(data) {
|
||||
if (data.type === "JOIN_SUCCESS") {
|
||||
setStatus("You're in! Waiting for the teacher to start the game...");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "SYNC") {
|
||||
if (data.phase === "day") {
|
||||
window.location.href = "/game";
|
||||
} else if (data.phase === "trading") {
|
||||
window.location.href = "/trading";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type !== "ERROR") return;
|
||||
|
||||
if (
|
||||
data.code === "ROOM_NOT_FOUND" ||
|
||||
/already in use/i.test(data.message ?? "")
|
||||
) {
|
||||
student.clear();
|
||||
window.alert(data.message || "You could not rejoin that room.");
|
||||
window.location.href = "/";
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus(data.message || "Something went wrong.");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function setStatus(text) {
|
||||
statusText.textContent = text;
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Escape the Island</title>
|
||||
<link rel="icon" type="image/x-icon" href="assets/shipwreck.png" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style></style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="header-container">
|
||||
<h1>Escape the Island</h1>
|
||||
<div class="boat-container">
|
||||
<img src="assets/boat-small.png" alt="" class="boat" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="Content">
|
||||
<div class="Instruction">
|
||||
<p>Backstory</p>
|
||||
<details>
|
||||
<summary>Click to expand</summary>
|
||||
<p>
|
||||
You and your class planned to go on a one week cruise trip over
|
||||
spring break to learn about how inflation affects nautical
|
||||
exploration and catching some sun. The cruise ship is built a pirate
|
||||
ship which you all find amusing at first. However, issues arise from
|
||||
an underlying problem. They didn't have the money to get schedule a
|
||||
final inspection before departing, but they still let you go anyways
|
||||
(because they are broke). As the boat leaves and cruises away from
|
||||
land, you see rocky terrain that has formed in the middle of the
|
||||
ocean (shocking). Your boat hits it and as people don't learn from
|
||||
the titanic, you don't have enough life boats to fit everyone and
|
||||
make it home safely. Everybody else gets on boats while you and your
|
||||
classmates are still on the boat (coincidentally). One of your
|
||||
friends believes he has a boat license (he doesn't) and tries to
|
||||
steer the boat before you sink. Magically you find an island. You
|
||||
all get onto the island safely but with no way home, scattered and
|
||||
disoriented.
|
||||
</p>
|
||||
</details>
|
||||
</div>
|
||||
<div class="Instruction">
|
||||
<p>Objective</p>
|
||||
<details>
|
||||
<summary>Click to expand</summary>
|
||||
<p>
|
||||
You will have 16 hours each day to gain as many resources as
|
||||
possible to survive. You must choose what to spend your hours doing
|
||||
each day carefully. The survival requirement for the end of each day
|
||||
is to have 8 fish and 4 pieces of lumber. Otherwise, you die (lose).
|
||||
You will be able to trade with other classmates you have found
|
||||
stranded at no expense of your daily hours.
|
||||
</p>
|
||||
</details>
|
||||
</div>
|
||||
<div class="Instruction">
|
||||
<p>Requirements</p>
|
||||
<details>
|
||||
<summary>Click to expand</summary>
|
||||
<ol>
|
||||
<li>
|
||||
In order to escape, you must have 24 stockpiled fish and a boat at
|
||||
the START of a new day.
|
||||
</li>
|
||||
<li>Fish will go bad without a preserver.</li>
|
||||
<li>
|
||||
Improving skills requires 8 hours and adds 1 per hour the next
|
||||
day.
|
||||
</li>
|
||||
<li>Building a preserver requires 8 hours and 25 wood</li>
|
||||
<li>Building a boat requires 16 hours and 100 wood</li>
|
||||
<li>You can only trade with "found" players</li>
|
||||
<li>
|
||||
It is recommended to donate resources to other players at end of
|
||||
day if you have a boat (Need to have 24 fish to leave)
|
||||
</li>
|
||||
</ol>
|
||||
</details>
|
||||
</div>
|
||||
<p id="game-status" class="game-status" role="status" aria-live="polite">
|
||||
Connecting...
|
||||
</p>
|
||||
<div class="game">
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fishing Stats</th>
|
||||
<th>Foraging Stats</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="width: 25%">Days: <span id="days">0</span></th>
|
||||
<td id="fish_p_hour">0</td>
|
||||
<td id="wood_p_hour">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="width: 25%">
|
||||
Players Found: <span id="found">0</span>
|
||||
</th>
|
||||
<td>Preserver: <span id="preserver">No</span></td>
|
||||
<td>Boat: <span id="boat">No</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="width: 25%">Hours Left: <span id="hours">16</span></th>
|
||||
<td>Stored Fish: <span id="fish_stored"></span></td>
|
||||
<td>Stored Wood: <span id="wood_stored"></span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="button-container">
|
||||
<div class="button-container-part">
|
||||
<button type="button" id="go-fishing">Go Fishing</button>
|
||||
<button type="button" id="go-foraging">Go Foraging</button>
|
||||
<button type="button" id="discover">Discover a Castaway</button>
|
||||
<!-- <button type="button" id="trading">Trade</button> -->
|
||||
</div>
|
||||
<div class="button-container-part">
|
||||
<button type="button" id="improve-fishing">
|
||||
Improve Fish Per Hour
|
||||
</button>
|
||||
<button type="button" id="build-preserver">Build Preserver</button>
|
||||
|
||||
<button type="button" id="improve-foraging">
|
||||
Improve Wood Per Hour
|
||||
</button>
|
||||
<button type="button" id="build-boat">Build Boat</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p id="found-list" class="found-list">No castaways found yet.</p>
|
||||
</div>
|
||||
<footer>
|
||||
<h3 style="padding: 10px 0px 0px 10px">
|
||||
Gamemaker: Mr. J. Walla ~=~ Developer: Andrew H. ~=~ Designer: Logan C.
|
||||
</h3>
|
||||
</footer>
|
||||
<script type="module" src="client/game.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Escape the Island</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="assets/shipwreck.png" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
</head>
|
||||
<body class="page page-join">
|
||||
<header>
|
||||
<div class="header-container">
|
||||
<h1>Escape the Island</h1>
|
||||
<div class="boat-container">
|
||||
<img src="assets/boat-small.png" alt="" class="boat" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="Content">
|
||||
<section class="panel">
|
||||
<p class="eyebrow">Join The Expedition</p>
|
||||
<h2>Join the crew</h2>
|
||||
<p class="panel-subtitle">
|
||||
Enter your name and the room code from your teacher. You will wait on
|
||||
the shore until the game begins.
|
||||
</p>
|
||||
|
||||
<form class="join-form" id="join-form" autocomplete="off" novalidate>
|
||||
<div class="form-grid">
|
||||
<label class="field">
|
||||
<span class="field-label">Player Name</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. Captain Milo"
|
||||
id="name"
|
||||
maxlength="24"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">Room Code</span>
|
||||
<input
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
placeholder="0000"
|
||||
id="join-code"
|
||||
maxlength="4"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<p id="join-status" class="lobby-status" role="status" aria-live="polite">
|
||||
Connecting...
|
||||
</p>
|
||||
<button type="submit" id="join-button" class="btn-primary" disabled>
|
||||
Connecting...
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="panel-footnote">
|
||||
No downloads needed. Just join from your browser and wait for your
|
||||
teacher to start the day.
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
<footer>
|
||||
<h3 style="padding: 0px 0px 0px 10px">
|
||||
Gamemaker: Mr. J. Walla ~=~ Developer: Andrew H. ~=~ Designer: Logan C.
|
||||
</h3>
|
||||
</footer>
|
||||
<script type="module" src="client/join.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,941 +0,0 @@
|
||||
interface WebSocketData {
|
||||
role: "teacher" | "student" | "unknown";
|
||||
roomCode: string | null;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
type Phase = "lobby" | "day" | "trading";
|
||||
|
||||
interface Player {
|
||||
name: string;
|
||||
clientId: string;
|
||||
ws: any | null;
|
||||
fish: number;
|
||||
wood: number;
|
||||
fishingPerHour: number;
|
||||
foragingPerHour: number;
|
||||
hours: number;
|
||||
preserver: boolean;
|
||||
boat: boolean;
|
||||
pendingFishing: number;
|
||||
pendingForaging: number;
|
||||
found: Set<string>;
|
||||
discoveryDay: number;
|
||||
}
|
||||
|
||||
interface TradeOffer {
|
||||
id: string;
|
||||
from: string;
|
||||
to: string;
|
||||
giveFish: number;
|
||||
giveWood: number;
|
||||
wantFish: number;
|
||||
wantWood: number;
|
||||
}
|
||||
|
||||
type Room = {
|
||||
code: string;
|
||||
teacherWs: any | null;
|
||||
teacherToken: string;
|
||||
players: Map<string, Player>;
|
||||
phase: Phase;
|
||||
day: number;
|
||||
offers: Map<string, TradeOffer>;
|
||||
};
|
||||
|
||||
const IMPROVE_HOURS = 8;
|
||||
const PRESERVER_HOURS = 8;
|
||||
const PRESERVER_WOOD = 25;
|
||||
const BOAT_HOURS = 16;
|
||||
const BOAT_WOOD = 100;
|
||||
|
||||
const rooms = new Map<string, Room>();
|
||||
|
||||
const pages: Record<string, string> = {
|
||||
"/": "index.html",
|
||||
"/host": "lobby.html",
|
||||
"/lobby": "lobby.html",
|
||||
"/waiting": "waiting.html",
|
||||
"/game": "game.html",
|
||||
"/trading": "trading.html",
|
||||
"/ws-test": "ws-test.html",
|
||||
};
|
||||
|
||||
async function serveFile(path: string): Promise<Response> {
|
||||
const file = Bun.file(path);
|
||||
if (!(await file.exists())) return new Response("Not Found", { status: 404 });
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": file.type || "application/octet-stream",
|
||||
};
|
||||
|
||||
// Pages and scripts change while developing, so don't let the browser serve
|
||||
// a stale copy. Images can still be cached normally.
|
||||
if (/\.(html|css|js)$/.test(path)) {
|
||||
headers["Cache-Control"] = "no-store";
|
||||
}
|
||||
|
||||
return new Response(file, { headers });
|
||||
}
|
||||
|
||||
function safeSend(ws: any | null, message: unknown): boolean {
|
||||
if (!ws) return false;
|
||||
|
||||
try {
|
||||
ws.send(JSON.stringify(message));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function sendError(ws: any, message: string, code?: string) {
|
||||
const payload: Record<string, unknown> = { type: "ERROR", message };
|
||||
if (code) payload.code = code;
|
||||
safeSend(ws, payload);
|
||||
}
|
||||
|
||||
function playerView(player: Player, room: Room) {
|
||||
return {
|
||||
name: player.name,
|
||||
fish: player.fish,
|
||||
wood: player.wood,
|
||||
hours: player.hours,
|
||||
fishingPerHour: player.fishingPerHour,
|
||||
foragingPerHour: player.foragingPerHour,
|
||||
preserver: player.preserver,
|
||||
boat: player.boat,
|
||||
pendingFishing: player.pendingFishing,
|
||||
pendingForaging: player.pendingForaging,
|
||||
found: Array.from(player.found, (key) => room.players.get(key)?.name ?? key),
|
||||
discoveryDay: player.discoveryDay,
|
||||
connected: player.ws !== null,
|
||||
};
|
||||
}
|
||||
|
||||
// Trade offers are only sent to the two students involved. The teacher still
|
||||
// sees the roster but not the private offers.
|
||||
function offersFor(room: Room, playerKey: string) {
|
||||
const nameOf = (key: string) => room.players.get(key)?.name ?? key;
|
||||
|
||||
return Array.from(room.offers.values())
|
||||
.filter((offer) => offer.from === playerKey || offer.to === playerKey)
|
||||
.map((offer) => ({
|
||||
id: offer.id,
|
||||
from: nameOf(offer.from),
|
||||
to: nameOf(offer.to),
|
||||
giveFish: offer.giveFish,
|
||||
giveWood: offer.giveWood,
|
||||
wantFish: offer.wantFish,
|
||||
wantWood: offer.wantWood,
|
||||
incoming: offer.to === playerKey,
|
||||
}));
|
||||
}
|
||||
|
||||
function notify(ws: any | null, message: string, tone = "") {
|
||||
safeSend(ws, { type: "NOTICE", message, tone });
|
||||
}
|
||||
|
||||
// Send the authoritative room state to the teacher and every student.
|
||||
// Each student gets the same roster plus their own `you` object and any trade
|
||||
// offers they are involved in.
|
||||
function broadcastSync(room: Room) {
|
||||
const players = Array.from(room.players.values()).map((player) =>
|
||||
playerView(player, room),
|
||||
);
|
||||
const base = {
|
||||
type: "SYNC",
|
||||
code: room.code,
|
||||
phase: room.phase,
|
||||
day: room.day,
|
||||
players,
|
||||
};
|
||||
|
||||
if (
|
||||
room.teacherWs &&
|
||||
!safeSend(room.teacherWs, { ...base, you: null, offers: [] })
|
||||
) {
|
||||
room.teacherWs = null;
|
||||
}
|
||||
|
||||
for (const [key, player] of room.players) {
|
||||
if (!player.ws) continue;
|
||||
|
||||
const payload = {
|
||||
...base,
|
||||
you: playerView(player, room),
|
||||
offers: offersFor(room, key),
|
||||
};
|
||||
|
||||
if (!safeSend(player.ws, payload)) {
|
||||
player.ws = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createPlayer(
|
||||
name: string,
|
||||
clientId: string,
|
||||
ws: any,
|
||||
room: Room,
|
||||
): Player {
|
||||
const first = Math.floor(Math.random() * 2) + 1;
|
||||
|
||||
return {
|
||||
name,
|
||||
clientId,
|
||||
ws,
|
||||
fish: 0,
|
||||
wood: 0,
|
||||
fishingPerHour: first,
|
||||
foragingPerHour: first === 1 ? 2 : 1,
|
||||
hours: room.phase === "trading" ? 0 : 16,
|
||||
preserver: false,
|
||||
boat: false,
|
||||
pendingFishing: 0,
|
||||
pendingForaging: 0,
|
||||
found: new Set(),
|
||||
discoveryDay: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function teacherRoom(ws: any): Room | null {
|
||||
if (ws.data.role !== "teacher" || !ws.data.roomCode) return null;
|
||||
|
||||
const room = rooms.get(ws.data.roomCode);
|
||||
if (!room || room.teacherWs !== ws) return null;
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
function studentInRoom(
|
||||
ws: any,
|
||||
): { room: Room; player: Player; key: string } | null {
|
||||
if (ws.data.role !== "student" || !ws.data.roomCode || !ws.data.name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const room = rooms.get(ws.data.roomCode);
|
||||
if (!room) return null;
|
||||
|
||||
const key = ws.data.name.toLowerCase();
|
||||
const player = room.players.get(key);
|
||||
if (!player || player.ws !== ws) return null;
|
||||
|
||||
return { room, player, key };
|
||||
}
|
||||
|
||||
function startGame(room: Room) {
|
||||
room.phase = "day";
|
||||
room.day = 1;
|
||||
|
||||
for (const player of room.players.values()) {
|
||||
player.hours = 16;
|
||||
}
|
||||
|
||||
console.log(`Room ${room.code}: day 1 started`);
|
||||
broadcastSync(room);
|
||||
}
|
||||
|
||||
function endDay(room: Room) {
|
||||
room.phase = "trading";
|
||||
console.log(`Room ${room.code}: day ${room.day} ended, trading open`);
|
||||
broadcastSync(room);
|
||||
}
|
||||
|
||||
function startNextDay(room: Room) {
|
||||
room.day += 1;
|
||||
room.phase = "day";
|
||||
room.offers.clear();
|
||||
|
||||
for (const player of room.players.values()) {
|
||||
player.hours = 16;
|
||||
player.fishingPerHour += player.pendingFishing;
|
||||
player.foragingPerHour += player.pendingForaging;
|
||||
player.pendingFishing = 0;
|
||||
player.pendingForaging = 0;
|
||||
}
|
||||
|
||||
console.log(`Room ${room.code}: day ${room.day} started`);
|
||||
broadcastSync(room);
|
||||
}
|
||||
|
||||
// If every connected student has spent all their hours, open trading
|
||||
// automatically. Returns true when it changed the phase.
|
||||
function checkAutoEndDay(room: Room): boolean {
|
||||
if (room.phase !== "day") return false;
|
||||
|
||||
const active = Array.from(room.players.values()).filter(
|
||||
(player) => player.ws !== null,
|
||||
);
|
||||
|
||||
if (active.length === 0) return false;
|
||||
if (!active.every((player) => player.hours <= 0)) return false;
|
||||
|
||||
room.phase = "trading";
|
||||
console.log(
|
||||
`Room ${room.code}: every connected player is out of hours; trading open`,
|
||||
);
|
||||
broadcastSync(room);
|
||||
return true;
|
||||
}
|
||||
|
||||
function finishAction(room: Room) {
|
||||
if (!checkAutoEndDay(room)) broadcastSync(room);
|
||||
}
|
||||
|
||||
function parseAmount(value: unknown): number | null {
|
||||
const amount = Number(value ?? 0);
|
||||
return Number.isInteger(amount) && amount >= 0 ? amount : null;
|
||||
}
|
||||
|
||||
function findOfferBetween(
|
||||
room: Room,
|
||||
a: string,
|
||||
b: string,
|
||||
): TradeOffer | undefined {
|
||||
for (const offer of room.offers.values()) {
|
||||
if (
|
||||
(offer.from === a && offer.to === b) ||
|
||||
(offer.from === b && offer.to === a)
|
||||
) {
|
||||
return offer;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function handleDiscover(
|
||||
ws: any,
|
||||
room: Room,
|
||||
player: Player,
|
||||
key: string,
|
||||
) {
|
||||
if (room.phase !== "day") {
|
||||
sendError(ws, "You can only explore during the day.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.discoveryDay === room.day) {
|
||||
sendError(ws, "You already found someone today.");
|
||||
return;
|
||||
}
|
||||
|
||||
const candidates = Array.from(room.players.entries()).filter(
|
||||
([otherKey, other]) =>
|
||||
otherKey !== key && other.ws !== null && !player.found.has(otherKey),
|
||||
);
|
||||
|
||||
if (candidates.length === 0) {
|
||||
const connectedOthers = Array.from(room.players.entries()).filter(
|
||||
([otherKey, other]) => otherKey !== key && other.ws !== null,
|
||||
);
|
||||
|
||||
sendError(
|
||||
ws,
|
||||
connectedOthers.length === 0
|
||||
? "No other castaways are online right now."
|
||||
: "You have already found every online castaway.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const picked = candidates[Math.floor(Math.random() * candidates.length)];
|
||||
if (!picked) return;
|
||||
|
||||
const [otherKey, other] = picked;
|
||||
|
||||
player.found.add(otherKey);
|
||||
other.found.add(key);
|
||||
player.discoveryDay = room.day;
|
||||
|
||||
broadcastSync(room);
|
||||
notify(ws, `You found ${other.name}!`, "good");
|
||||
notify(
|
||||
other.ws,
|
||||
`${player.name} found you. You can now trade with each other.`,
|
||||
"good",
|
||||
);
|
||||
}
|
||||
|
||||
function handleTradeOffer(
|
||||
ws: any,
|
||||
room: Room,
|
||||
player: Player,
|
||||
key: string,
|
||||
data: any,
|
||||
) {
|
||||
if (room.phase !== "trading") {
|
||||
sendError(ws, "Trading is only open after the day ends.");
|
||||
return;
|
||||
}
|
||||
|
||||
const targetName = String(data.to || "").trim();
|
||||
const targetKey = targetName.toLowerCase();
|
||||
const target = room.players.get(targetKey);
|
||||
|
||||
if (!target || targetKey === key) {
|
||||
sendError(ws, "That castaway is not in this room.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.found.has(targetKey)) {
|
||||
sendError(ws, "You can only trade with a castaway you have found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.ws) {
|
||||
sendError(ws, `${target.name} is offline right now.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const giveFish = parseAmount(data.giveFish);
|
||||
const giveWood = parseAmount(data.giveWood);
|
||||
const wantFish = parseAmount(data.wantFish);
|
||||
const wantWood = parseAmount(data.wantWood);
|
||||
|
||||
if (
|
||||
giveFish === null ||
|
||||
giveWood === null ||
|
||||
wantFish === null ||
|
||||
wantWood === null
|
||||
) {
|
||||
sendError(ws, "Trade amounts must be whole numbers of 0 or more.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (giveFish + giveWood + wantFish + wantWood === 0) {
|
||||
sendError(ws, "Offer at least one fish or piece of wood.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.fish < giveFish || player.wood < giveWood) {
|
||||
sendError(ws, "You do not have enough supplies for that offer.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.fish < wantFish || target.wood < wantWood) {
|
||||
sendError(ws, `${target.name} does not have enough supplies for that offer.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (findOfferBetween(room, key, targetKey)) {
|
||||
sendError(ws, "There is already a pending offer between you two.");
|
||||
return;
|
||||
}
|
||||
|
||||
const offer: TradeOffer = {
|
||||
id: crypto.randomUUID(),
|
||||
from: key,
|
||||
to: targetKey,
|
||||
giveFish,
|
||||
giveWood,
|
||||
wantFish,
|
||||
wantWood,
|
||||
};
|
||||
|
||||
room.offers.set(offer.id, offer);
|
||||
broadcastSync(room);
|
||||
notify(ws, `Offer sent to ${target.name}.`);
|
||||
notify(target.ws, `Offer from ${player.name}. Check the trading post.`);
|
||||
}
|
||||
|
||||
function handleTradeAccept(
|
||||
ws: any,
|
||||
room: Room,
|
||||
player: Player,
|
||||
key: string,
|
||||
data: any,
|
||||
) {
|
||||
if (room.phase !== "trading") {
|
||||
sendError(ws, "Trading is only open after the day ends.");
|
||||
return;
|
||||
}
|
||||
|
||||
const offer = room.offers.get(String(data.id || ""));
|
||||
if (!offer || offer.to !== key) {
|
||||
sendError(ws, "That offer is no longer available.");
|
||||
return;
|
||||
}
|
||||
|
||||
const fromPlayer = room.players.get(offer.from);
|
||||
if (!fromPlayer) {
|
||||
room.offers.delete(offer.id);
|
||||
broadcastSync(room);
|
||||
sendError(ws, "That castaway is no longer in the room.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
fromPlayer.fish < offer.giveFish ||
|
||||
fromPlayer.wood < offer.giveWood ||
|
||||
player.fish < offer.wantFish ||
|
||||
player.wood < offer.wantWood
|
||||
) {
|
||||
sendError(ws, "That offer can no longer be completed. Ask for a new one.");
|
||||
return;
|
||||
}
|
||||
|
||||
fromPlayer.fish -= offer.giveFish;
|
||||
fromPlayer.wood -= offer.giveWood;
|
||||
player.fish += offer.giveFish;
|
||||
player.wood += offer.giveWood;
|
||||
player.fish -= offer.wantFish;
|
||||
player.wood -= offer.wantWood;
|
||||
fromPlayer.fish += offer.wantFish;
|
||||
fromPlayer.wood += offer.wantWood;
|
||||
|
||||
room.offers.delete(offer.id);
|
||||
broadcastSync(room);
|
||||
notify(ws, `Trade complete with ${fromPlayer.name}.`, "good");
|
||||
notify(fromPlayer.ws, `Trade complete with ${player.name}.`, "good");
|
||||
}
|
||||
|
||||
function handleTradeDecline(
|
||||
ws: any,
|
||||
room: Room,
|
||||
player: Player,
|
||||
key: string,
|
||||
data: any,
|
||||
) {
|
||||
const offer = room.offers.get(String(data.id || ""));
|
||||
if (!offer || offer.to !== key) {
|
||||
sendError(ws, "That offer is no longer available.");
|
||||
return;
|
||||
}
|
||||
|
||||
const fromPlayer = room.players.get(offer.from);
|
||||
room.offers.delete(offer.id);
|
||||
broadcastSync(room);
|
||||
notify(ws, "Offer declined.");
|
||||
notify(fromPlayer?.ws ?? null, `${player.name} declined your offer.`);
|
||||
}
|
||||
|
||||
function handleTradeCancel(
|
||||
ws: any,
|
||||
room: Room,
|
||||
player: Player,
|
||||
key: string,
|
||||
data: any,
|
||||
) {
|
||||
const offer = room.offers.get(String(data.id || ""));
|
||||
if (!offer || offer.from !== key) {
|
||||
sendError(ws, "That offer is no longer available.");
|
||||
return;
|
||||
}
|
||||
|
||||
const target = room.players.get(offer.to);
|
||||
room.offers.delete(offer.id);
|
||||
broadcastSync(room);
|
||||
notify(ws, "Offer cancelled.");
|
||||
notify(target?.ws ?? null, `${player.name} cancelled their offer.`);
|
||||
}
|
||||
|
||||
const server = Bun.serve<WebSocketData>({
|
||||
port: Number(process.env.PORT ?? 3000),
|
||||
async fetch(req, server) {
|
||||
const url = new URL(req.url);
|
||||
|
||||
console.log(req.method, url.pathname);
|
||||
|
||||
if (url.pathname === "/ws") {
|
||||
if (server.upgrade(req, { data: { role: "unknown", roomCode: null } }))
|
||||
return;
|
||||
return new Response("WebSocket upgrade failed", { status: 400 });
|
||||
}
|
||||
|
||||
const page = pages[url.pathname];
|
||||
if (page) return serveFile(page);
|
||||
|
||||
if (
|
||||
url.pathname.startsWith("/client/") ||
|
||||
url.pathname.startsWith("/assets/")
|
||||
) {
|
||||
if (url.pathname.includes("..")) {
|
||||
return new Response("Bad path", { status: 400 });
|
||||
}
|
||||
return serveFile("." + url.pathname);
|
||||
}
|
||||
|
||||
if (url.pathname === "/styles.css") return serveFile("styles.css");
|
||||
if (url.pathname == "/api/health") {
|
||||
return Response.json({ ok: true, time: Date.now() });
|
||||
}
|
||||
if (url.pathname == "/hello") {
|
||||
return new Response("Hello from bun");
|
||||
}
|
||||
return new Response("Not Found", { status: 404 });
|
||||
},
|
||||
websocket: {
|
||||
open() {
|
||||
console.log("A client connect via websocket!");
|
||||
},
|
||||
message(ws, message) {
|
||||
const text = typeof message === "string" ? message : message.toString();
|
||||
|
||||
let data: any;
|
||||
try {
|
||||
data = JSON.parse(text);
|
||||
} catch {
|
||||
sendError(ws, "Invalid JSON");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "PING") {
|
||||
safeSend(ws, { type: "PONG" });
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("recv:", text);
|
||||
|
||||
if (data.type === "ECHO") {
|
||||
safeSend(ws, { type: "ECHO", text: data.text });
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "CREATE_ROOM") {
|
||||
if (ws.data.roomCode) {
|
||||
sendError(ws, "Already in a room");
|
||||
return;
|
||||
}
|
||||
|
||||
let roomCode = "";
|
||||
|
||||
do {
|
||||
roomCode = Math.floor(1000 + Math.random() * 9000).toString();
|
||||
} while (rooms.has(roomCode));
|
||||
|
||||
const teacherToken = crypto.randomUUID();
|
||||
const room: Room = {
|
||||
code: roomCode,
|
||||
teacherWs: ws,
|
||||
teacherToken,
|
||||
players: new Map(),
|
||||
phase: "lobby",
|
||||
day: 0,
|
||||
offers: new Map(),
|
||||
};
|
||||
|
||||
rooms.set(roomCode, room);
|
||||
ws.data = { role: "teacher", roomCode };
|
||||
|
||||
safeSend(ws, {
|
||||
type: "ROOM_CREATED",
|
||||
code: roomCode,
|
||||
token: teacherToken,
|
||||
});
|
||||
broadcastSync(room);
|
||||
console.log(`Teacher created room: ${roomCode}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "RESUME_TEACHER") {
|
||||
const code = String(data.code || "").trim();
|
||||
const token = String(data.token || "").trim();
|
||||
|
||||
if (!code || !token) {
|
||||
sendError(ws, "Code and token required");
|
||||
return;
|
||||
}
|
||||
|
||||
const room = rooms.get(code);
|
||||
if (!room) {
|
||||
sendError(ws, "Room not found", "ROOM_NOT_FOUND");
|
||||
return;
|
||||
}
|
||||
|
||||
if (room.teacherToken !== token) {
|
||||
sendError(ws, "Not allowed to resume that room");
|
||||
return;
|
||||
}
|
||||
|
||||
if (room.teacherWs && room.teacherWs !== ws) {
|
||||
try {
|
||||
room.teacherWs.close(4000, "Replaced by newer connection");
|
||||
} catch {}
|
||||
}
|
||||
|
||||
room.teacherWs = ws;
|
||||
ws.data = { role: "teacher", roomCode: code };
|
||||
safeSend(ws, { type: "ROOM_RESUMED", code });
|
||||
broadcastSync(room);
|
||||
console.log(`Teacher resumed room: ${code}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "JOIN_ROOM") {
|
||||
const code = String(data.code || "").trim();
|
||||
const name = String(data.name || "").trim();
|
||||
const clientId = String(data.clientId || "").trim();
|
||||
|
||||
if (!code || !name || !clientId) {
|
||||
sendError(ws, "Name, code and clientId required");
|
||||
return;
|
||||
}
|
||||
|
||||
const room = rooms.get(code);
|
||||
if (!room) {
|
||||
sendError(ws, "Room not found!", "ROOM_NOT_FOUND");
|
||||
return;
|
||||
}
|
||||
|
||||
const key = name.toLowerCase();
|
||||
const existing = room.players.get(key);
|
||||
|
||||
if (existing) {
|
||||
if (existing.clientId === clientId) {
|
||||
if (existing.ws && existing.ws !== ws) {
|
||||
try {
|
||||
existing.ws.close(4000, "Replaced by newer connection");
|
||||
} catch {}
|
||||
}
|
||||
|
||||
existing.ws = ws;
|
||||
ws.data = { role: "student", roomCode: code, name: existing.name };
|
||||
safeSend(ws, { type: "JOIN_SUCCESS", rejoined: true });
|
||||
console.log(`Student ${existing.name} rejoined room ${code}`);
|
||||
broadcastSync(room);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!existing.ws) {
|
||||
existing.ws = ws;
|
||||
existing.clientId = clientId;
|
||||
ws.data = { role: "student", roomCode: code, name: existing.name };
|
||||
safeSend(ws, { type: "JOIN_SUCCESS", rejoined: true });
|
||||
console.log(`Student ${existing.name} took over room ${code}`);
|
||||
broadcastSync(room);
|
||||
return;
|
||||
}
|
||||
|
||||
sendError(ws, "That name is already in use in another tab");
|
||||
return;
|
||||
}
|
||||
|
||||
const player = createPlayer(name, clientId, ws, room);
|
||||
room.players.set(key, player);
|
||||
ws.data = { role: "student", roomCode: code, name };
|
||||
safeSend(ws, { type: "JOIN_SUCCESS" });
|
||||
console.log(`Student ${name} joined room ${code}`);
|
||||
broadcastSync(room);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
data.type === "START_GAME" ||
|
||||
data.type === "END_DAY" ||
|
||||
data.type === "NEXT_DAY"
|
||||
) {
|
||||
const room = teacherRoom(ws);
|
||||
|
||||
if (!room) {
|
||||
sendError(ws, "Only the teacher can control the game.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "START_GAME") {
|
||||
if (room.phase !== "lobby") {
|
||||
sendError(ws, "The game has already started.");
|
||||
} else if (room.players.size === 0) {
|
||||
sendError(ws, "Wait for at least one student to join.");
|
||||
} else {
|
||||
startGame(room);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "END_DAY") {
|
||||
if (room.phase !== "day") {
|
||||
sendError(ws, "The game is not in a day phase.");
|
||||
} else {
|
||||
endDay(room);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (room.phase !== "trading") {
|
||||
sendError(ws, "The game is not in the trading phase.");
|
||||
} else {
|
||||
startNextDay(room);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
data.type === "FISH" ||
|
||||
data.type === "FORAGE" ||
|
||||
data.type === "IMPROVE_FISHING" ||
|
||||
data.type === "IMPROVE_FORAGING" ||
|
||||
data.type === "BUILD_PRESERVER" ||
|
||||
data.type === "BUILD_BOAT"
|
||||
) {
|
||||
const student = studentInRoom(ws);
|
||||
|
||||
if (!student) {
|
||||
sendError(ws, "You are not in a room.");
|
||||
return;
|
||||
}
|
||||
|
||||
const { room, player } = student;
|
||||
|
||||
if (room.phase !== "day") {
|
||||
sendError(ws, "The day is not active.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "FISH" || data.type === "FORAGE") {
|
||||
if (player.hours <= 0) {
|
||||
sendError(ws, "You have no hours left today.");
|
||||
return;
|
||||
}
|
||||
|
||||
const hours = Number(data.hours);
|
||||
|
||||
if (
|
||||
!Number.isInteger(hours) ||
|
||||
hours < 1 ||
|
||||
hours > player.hours
|
||||
) {
|
||||
sendError(ws, `Choose between 1 and ${player.hours} hours.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "FISH") {
|
||||
player.fish += hours * player.fishingPerHour;
|
||||
} else {
|
||||
player.wood += hours * player.foragingPerHour;
|
||||
}
|
||||
|
||||
player.hours -= hours;
|
||||
finishAction(room);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
data.type === "IMPROVE_FISHING" ||
|
||||
data.type === "IMPROVE_FORAGING"
|
||||
) {
|
||||
if (player.hours < IMPROVE_HOURS) {
|
||||
sendError(
|
||||
ws,
|
||||
`Improving a skill costs ${IMPROVE_HOURS} hours.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
player.hours -= IMPROVE_HOURS;
|
||||
|
||||
if (data.type === "IMPROVE_FISHING") {
|
||||
player.pendingFishing += 1;
|
||||
} else {
|
||||
player.pendingForaging += 1;
|
||||
}
|
||||
|
||||
finishAction(room);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "BUILD_PRESERVER") {
|
||||
if (player.preserver) {
|
||||
sendError(ws, "You already have a preserver.");
|
||||
} else if (player.hours < PRESERVER_HOURS) {
|
||||
sendError(
|
||||
ws,
|
||||
`Building a preserver costs ${PRESERVER_HOURS} hours.`,
|
||||
);
|
||||
} else if (player.wood < PRESERVER_WOOD) {
|
||||
sendError(
|
||||
ws,
|
||||
`Building a preserver costs ${PRESERVER_WOOD} wood.`,
|
||||
);
|
||||
} else {
|
||||
player.hours -= PRESERVER_HOURS;
|
||||
player.wood -= PRESERVER_WOOD;
|
||||
player.preserver = true;
|
||||
finishAction(room);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "BUILD_BOAT") {
|
||||
if (player.boat) {
|
||||
sendError(ws, "You already have a boat.");
|
||||
} else if (player.hours < BOAT_HOURS) {
|
||||
sendError(ws, `Building a boat costs ${BOAT_HOURS} hours.`);
|
||||
} else if (player.wood < BOAT_WOOD) {
|
||||
sendError(ws, `Building a boat costs ${BOAT_WOOD} wood.`);
|
||||
} else {
|
||||
player.hours -= BOAT_HOURS;
|
||||
player.wood -= BOAT_WOOD;
|
||||
player.boat = true;
|
||||
finishAction(room);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
data.type === "DISCOVER" ||
|
||||
data.type === "TRADE_OFFER" ||
|
||||
data.type === "TRADE_ACCEPT" ||
|
||||
data.type === "TRADE_DECLINE" ||
|
||||
data.type === "TRADE_CANCEL"
|
||||
) {
|
||||
const student = studentInRoom(ws);
|
||||
|
||||
if (!student) {
|
||||
sendError(ws, "You are not in a room.");
|
||||
return;
|
||||
}
|
||||
|
||||
const { room, player, key } = student;
|
||||
|
||||
if (data.type === "DISCOVER") {
|
||||
handleDiscover(ws, room, player, key);
|
||||
} else if (data.type === "TRADE_OFFER") {
|
||||
handleTradeOffer(ws, room, player, key, data);
|
||||
} else if (data.type === "TRADE_ACCEPT") {
|
||||
handleTradeAccept(ws, room, player, key, data);
|
||||
} else if (data.type === "TRADE_DECLINE") {
|
||||
handleTradeDecline(ws, room, player, key, data);
|
||||
} else {
|
||||
handleTradeCancel(ws, room, player, key, data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
},
|
||||
close(ws) {
|
||||
if (!ws.data || !ws.data.roomCode) return;
|
||||
|
||||
const room = rooms.get(ws.data.roomCode);
|
||||
if (!room) return;
|
||||
|
||||
if (ws.data.role === "teacher") {
|
||||
if (room.teacherWs === ws) {
|
||||
room.teacherWs = null;
|
||||
console.log(`Teacher disconnected from room ${ws.data.roomCode}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (ws.data.role === "student" && ws.data.name) {
|
||||
const key = ws.data.name.toLowerCase();
|
||||
const player = room.players.get(key);
|
||||
|
||||
if (player && player.ws === ws) {
|
||||
player.ws = null;
|
||||
console.log(
|
||||
`Student ${player.name} disconnected from room ${ws.data.roomCode}`,
|
||||
);
|
||||
|
||||
if (!checkAutoEndDay(room)) broadcastSync(room);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("A client disconnected");
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Listening on ${server.url}`);
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Escape the Island</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="assets/shipwreck.png" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
</head>
|
||||
<body class="page page-lobby">
|
||||
<header>
|
||||
<div class="header-container">
|
||||
<h1>Escape the Island</h1>
|
||||
<div class="boat-container">
|
||||
<img src="assets/boat-small.png" alt="" class="boat" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="Content">
|
||||
<div class="card-grid">
|
||||
<section class="panel room-panel">
|
||||
<p class="eyebrow">Teacher Console</p>
|
||||
<h2>Room Code</h2>
|
||||
<p id="room-code" class="room-code">----</p>
|
||||
<p id="lobby-status" class="lobby-status" aria-live="polite">
|
||||
Connecting...
|
||||
</p>
|
||||
<button type="button" id="host-btn" class="btn-primary" disabled>
|
||||
Connecting...
|
||||
</button>
|
||||
<p class="panel-footnote">
|
||||
Students open this same address, enter a name, and use the code
|
||||
above.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="panel" id="phase-panel" hidden>
|
||||
<p class="eyebrow">Game Control</p>
|
||||
<h2>Phase: <span id="phase-text">-</span></h2>
|
||||
<p class="panel-subtitle">Day <span id="day-text">0</span></p>
|
||||
<div class="phase-controls">
|
||||
<button type="button" id="start-game-btn" class="btn-primary">
|
||||
Start Game
|
||||
</button>
|
||||
<button type="button" id="end-day-btn" class="btn-primary">
|
||||
End Day Early
|
||||
</button>
|
||||
<button type="button" id="next-day-btn" class="btn-primary">
|
||||
Start Day N+1
|
||||
</button>
|
||||
</div>
|
||||
<p id="phase-status" class="lobby-status" aria-live="polite"></p>
|
||||
</section>
|
||||
|
||||
<section class="panel" id="roster-panel" hidden>
|
||||
<div class="roster-heading">
|
||||
<div>
|
||||
<p class="eyebrow">Crew Manifest</p>
|
||||
<h2>
|
||||
Players <span id="player-count" class="count-badge">0</span>
|
||||
</h2>
|
||||
</div>
|
||||
<p class="panel-subtitle">
|
||||
This list updates live as students join and connect.
|
||||
</p>
|
||||
</div>
|
||||
<div class="table-container">
|
||||
<table class="roster-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Fish</th>
|
||||
<th>Wood</th>
|
||||
<th>Hours</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="roster-body">
|
||||
<tr>
|
||||
<td colspan="5" class="empty">
|
||||
No students have joined yet.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<h3 style="padding: 0px 0px 0px 10px">
|
||||
Gamemaker: Mr. J. Walla ~=~ Developer: Andrew H. ~=~ Designer: Logan C.
|
||||
</h3>
|
||||
</footer>
|
||||
<script type="module" src="client/lobby.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,171 @@
|
||||
import random
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self, fish_per_hour, wood_per_hour):
|
||||
self.fish = 0
|
||||
self.wood = 0
|
||||
self.hours = 16
|
||||
self.obtained_boat = 0 # when they got boat
|
||||
|
||||
self.fish_per_hour = fish_per_hour
|
||||
self.wood_per_hour = wood_per_hour
|
||||
|
||||
# If player does not have it, all fish expires at end of day.
|
||||
self.fish_preserver = False
|
||||
self.boat = False
|
||||
|
||||
def strip_hours(self, hours):
|
||||
self.hours -= hours
|
||||
|
||||
|
||||
class Game:
|
||||
def __init__(self):
|
||||
self.players_found = 0
|
||||
self.days = 0
|
||||
|
||||
def fishing(self, player: Player, hours):
|
||||
player.fish += player.fish_per_hour * hours
|
||||
|
||||
def collect_wood(self, player: Player, hours):
|
||||
player.wood += player.wood_per_hour * hours
|
||||
|
||||
def improve_fishing(self, player: Player):
|
||||
player.fish_per_hour += 1
|
||||
|
||||
def improve_foraging(self, player: Player):
|
||||
player.wood_per_hour += 1
|
||||
|
||||
def create_fish_preserver(self, player: Player):
|
||||
player.wood -= 25
|
||||
player.fish_preserver = True
|
||||
|
||||
def create_boat(self, player: Player):
|
||||
player.wood -= 100
|
||||
player.boat = True
|
||||
|
||||
def create_player_values(self, player: Player):
|
||||
fish = random.randint(1, 2)
|
||||
wood = 0
|
||||
if (fish == 1):
|
||||
wood = 2
|
||||
if (fish == 2):
|
||||
wood = 1
|
||||
|
||||
player.fish_per_hour = fish
|
||||
player.wood_per_hour = wood
|
||||
|
||||
def state(self, player: Player):
|
||||
running = True
|
||||
invalid = False
|
||||
while (running):
|
||||
if (player.boat and player.obtained_boat < self.days and player.fish >= 24):
|
||||
print("Good fucking job lad. You win!")
|
||||
break
|
||||
if (player.hours <= 0):
|
||||
if (player.fish >= 8 and player.wood >= 4):
|
||||
self.days += 1
|
||||
player.hours += 16
|
||||
player.wood -= 4
|
||||
if (not player.fish_preserver):
|
||||
player.fish = 0
|
||||
else:
|
||||
player.fish -= 8
|
||||
else:
|
||||
print("You fucking died!")
|
||||
break
|
||||
print("\033[H\033[J", end="")
|
||||
if (invalid):
|
||||
print("LAST RESPONSE WAS INVALID!\n")
|
||||
invalid = False
|
||||
print(f"Game Days: {self.days}\n")
|
||||
print(f"Player Production: {player.hours} hours left")
|
||||
|
||||
print("╭───────────────┬───────────────╮\n"
|
||||
"│ Fish Per Hour │ Wood Per Hour │\n"
|
||||
f"│ {player.fish_per_hour} │ {player.wood_per_hour} │\n"
|
||||
"╰───────────────┴───────────────╯")
|
||||
print("╭────────────────┬─────────────────╮\n"
|
||||
"│ Owns Preserver │ Owns Boat │\n"
|
||||
f"│ {player.fish_preserver} │ {player.boat} │\n"
|
||||
"╰────────────────┴─────────────────╯")
|
||||
print("╭─────────────┬─────────────╮\n"
|
||||
"│ Stored Fish │ Stored Wood │\n"
|
||||
f"│ {player.fish} │ {player.wood} │\n"
|
||||
"╰─────────────┴─────────────╯")
|
||||
print("What do you want to spend your hours on?\n1. Fishing.\n2. Foraging.\n3. Improve Fishing.\n4. Improve Foraging.\n5. Build a preserver.\n6. Build a boat.\nQ to quit")
|
||||
user_input = input()
|
||||
if (user_input == "q"):
|
||||
print("Leaving self. Does not save. Tough shit.")
|
||||
break
|
||||
elif (user_input == "1"):
|
||||
print("How many hours do you want to fish?")
|
||||
user_input = input()
|
||||
if (player.hours >= int(user_input)):
|
||||
self.fishing(player, int(user_input))
|
||||
player.strip_hours(int(user_input))
|
||||
else:
|
||||
print(
|
||||
f"You dont have the hours to do that much work. Hours left: {int(user_input)}")
|
||||
elif (user_input == "2"):
|
||||
print("How many hours do you want to forage?")
|
||||
user_input = input()
|
||||
if (player.hours >= int(user_input)):
|
||||
self.collect_wood(player, int(user_input))
|
||||
player.strip_hours(int(user_input))
|
||||
else:
|
||||
print(
|
||||
f"You dont have the hours to do that much work. Hours left: {player.hours}")
|
||||
elif (user_input == "3"):
|
||||
print("Do you want to improve your fishing efficiency?")
|
||||
user_input = input()
|
||||
if (user_input == "Y" and player.hours >= 8):
|
||||
self.improve_fishing(player)
|
||||
player.strip_hours(8)
|
||||
else:
|
||||
print(
|
||||
f"You dont have the hours to do that much work. Hours left: {player.hours}")
|
||||
elif (user_input == "4"):
|
||||
print("Do you want to improve your foraging efficiency?")
|
||||
user_input = input()
|
||||
if (user_input == "Y" and player.hours >= 8):
|
||||
self.improve_foraging(player)
|
||||
player.strip_hours(8)
|
||||
else:
|
||||
print(
|
||||
f"You dont have the hours to do that much work. Hours left: {player.hours}")
|
||||
elif (user_input == "5"):
|
||||
print("Do you want to build a fish preserver?")
|
||||
user_input = input()
|
||||
if (user_input == "Y" and player.hours >= 8 and player.wood >= 25):
|
||||
self.create_fish_preserver(player)
|
||||
player.strip_hours(8)
|
||||
else:
|
||||
print(
|
||||
f"You dont have the hours to do that much work. Hours left: {player.hours}")
|
||||
elif (user_input == "6"):
|
||||
print("Do you want to build a boat?")
|
||||
user_input = input()
|
||||
if (user_input == "Y" and player.hours >= 16 and player.wood >= 100):
|
||||
self.create_boat(player)
|
||||
player.strip_hours(16)
|
||||
player.obtained_boat = self.days
|
||||
else:
|
||||
print(
|
||||
f"You dont have the hours to do that much work. Hours left: {player.hours}")
|
||||
else:
|
||||
invalid = True
|
||||
|
||||
|
||||
def main():
|
||||
game = Game()
|
||||
player = Player(0, 0)
|
||||
game.create_player_values(player)
|
||||
game.state(player)
|
||||
print("1. How did scarcity come into play durig this simulation?\n")
|
||||
print("2. How did you determine if and under what terms to trade?\n")
|
||||
print("3. How did your starting production levels determine your success in the game?\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "escape",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^7"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
[tool.autopep8]
|
||||
max-line-length = 120
|
||||
ignore = "E501,W6"
|
||||
aggressive = 2
|
||||
-896
@@ -1,896 +0,0 @@
|
||||
html {
|
||||
background-color: moccasin;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: cadetblue;
|
||||
transition: background-color 0.1s ease-out;
|
||||
margin: 20px;
|
||||
padding: 0;
|
||||
font-family: "Almendra";
|
||||
}
|
||||
|
||||
header {
|
||||
background-color: moccasin;
|
||||
padding: 10px;
|
||||
border-bottom: 2px dashed gray;
|
||||
|
||||
.header-container {
|
||||
display: flex;
|
||||
flex-direction: row-reverse;
|
||||
align-items: center;
|
||||
|
||||
h1 {
|
||||
color: cornflowerblue;
|
||||
font-family: "Almendra";
|
||||
text-align: left;
|
||||
font-size: clamp(20px, 10vh, 55px);
|
||||
height: auto;
|
||||
max-height: 100px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.boat {
|
||||
height: auto;
|
||||
max-width: 150px;
|
||||
width: 100%;
|
||||
pointer-events: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.boat-container {
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: left;
|
||||
width: 100%;
|
||||
flex: 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.Content {
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
|
||||
|
||||
.Instruction {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
|
||||
details {
|
||||
p {
|
||||
line-height: 1.4;
|
||||
font-size: 20px;
|
||||
color: black;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 40px;
|
||||
text-align: left;
|
||||
line-height: 1;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
li {
|
||||
line-height: 1.4;
|
||||
font-size: 20px;
|
||||
color: black;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.game {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
padding: 10px;
|
||||
flex: 1;
|
||||
background-color: cadetblue;
|
||||
|
||||
table,
|
||||
th,
|
||||
td,
|
||||
tr {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
tr:nth-child(odd) {
|
||||
background-color: rgba(0, 0, 0, 0.125);
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: darkseagreen;
|
||||
}
|
||||
}
|
||||
|
||||
.button-container {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
|
||||
}
|
||||
|
||||
.button-container-part {
|
||||
display: flex;
|
||||
|
||||
}
|
||||
|
||||
button {
|
||||
font-family: "Almendra";
|
||||
font-size: 18px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
transition-duration: 0.2s;
|
||||
padding: 7px;
|
||||
height: clamp(30px, 15vh, 85px);
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: darkseagreen;
|
||||
color: black;
|
||||
cursor: grab;
|
||||
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.6);
|
||||
border: 2px solid black;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
background-color: moccasin;
|
||||
width: 100%;
|
||||
margin-top: 25px;
|
||||
text-align: center;
|
||||
border-top: 2px dashed gray;
|
||||
}
|
||||
|
||||
/* ---- Page shell: join, waiting, lobby, trading ---- */
|
||||
|
||||
body.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: calc(100vh - 40px);
|
||||
background:
|
||||
radial-gradient(
|
||||
circle at 15% 0%,
|
||||
rgba(255, 228, 181, 0.22),
|
||||
transparent 38%
|
||||
),
|
||||
cadetblue;
|
||||
}
|
||||
|
||||
body.page .Content {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
max-width: 1024px;
|
||||
margin: 0 auto;
|
||||
padding: clamp(12px, 2vw, 20px) 10px 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body.page-join .Content,
|
||||
body.page-waiting .Content {
|
||||
max-width: 760px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
position: relative;
|
||||
margin: 0 0 16px;
|
||||
padding: clamp(16px, 2.6vw, 24px);
|
||||
background-color: moccasin;
|
||||
background-image: radial-gradient(
|
||||
circle at top left,
|
||||
rgba(255, 255, 255, 0.35),
|
||||
transparent 55%
|
||||
);
|
||||
border: 2px dashed gray;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
|
||||
color: #2b2b2b;
|
||||
}
|
||||
|
||||
.panel::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 8px;
|
||||
border: 1px solid rgba(105, 105, 105, 0.22);
|
||||
border-radius: 9px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0 0 6px;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
color: #7a6242;
|
||||
}
|
||||
|
||||
.panel h2 {
|
||||
margin: 0 0 8px;
|
||||
font-size: clamp(26px, 3.4vw, 34px);
|
||||
line-height: 1.05;
|
||||
color: #2f4f4f;
|
||||
}
|
||||
|
||||
.panel-subtitle {
|
||||
margin: 0 0 16px;
|
||||
font-size: clamp(16px, 1.9vw, 18px);
|
||||
line-height: 1.45;
|
||||
color: #4d4d4d;
|
||||
}
|
||||
|
||||
.panel-footnote {
|
||||
margin: 14px 0 0;
|
||||
padding-top: 10px;
|
||||
border-top: 1px dashed rgba(105, 105, 105, 0.45);
|
||||
font-size: 15px;
|
||||
line-height: 1.4;
|
||||
color: #6b5a3e;
|
||||
}
|
||||
|
||||
.room-code {
|
||||
margin: 4px 0 14px;
|
||||
padding: 6px 0;
|
||||
font-size: clamp(42px, 9vw, 64px);
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
letter-spacing: 0.16em;
|
||||
text-align: center;
|
||||
color: cornflowerblue;
|
||||
text-shadow: 2px 2px 0 rgba(47, 79, 79, 0.18);
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.lobby-status {
|
||||
margin: 0 0 12px;
|
||||
font-size: 18px;
|
||||
min-height: 1.5em;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.lobby-status[data-tone="good"] {
|
||||
color: darkgreen;
|
||||
}
|
||||
|
||||
.lobby-status[data-tone="bad"] {
|
||||
color: darkred;
|
||||
}
|
||||
|
||||
/* ---- Join page ---- */
|
||||
|
||||
.join-form {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
color: #6b5a3e;
|
||||
}
|
||||
|
||||
.field input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 13px 14px;
|
||||
border: 2px solid #b9a887;
|
||||
border-radius: 9px;
|
||||
background-color: #fff8e7;
|
||||
color: #2b2b2b;
|
||||
font-family: "Almendra", serif;
|
||||
font-size: 22px;
|
||||
transition:
|
||||
border-color 0.15s ease,
|
||||
box-shadow 0.15s ease;
|
||||
}
|
||||
|
||||
.field input:focus {
|
||||
outline: none;
|
||||
border-color: cornflowerblue;
|
||||
box-shadow: 0 0 0 3px rgba(100, 149, 237, 0.25);
|
||||
}
|
||||
|
||||
#join-code {
|
||||
letter-spacing: 0.22em;
|
||||
text-align: center;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* ---- Buttons and links ---- */
|
||||
|
||||
.Content .btn-primary,
|
||||
.Content .btn-link {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 56px;
|
||||
height: auto;
|
||||
box-sizing: border-box;
|
||||
padding: 12px 20px;
|
||||
border: 2px solid #2f4f4f;
|
||||
border-radius: 10px;
|
||||
background-color: cornflowerblue;
|
||||
color: white;
|
||||
font-family: "Almendra", serif;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 5px 0 #2f4f4f;
|
||||
transition:
|
||||
transform 0.12s ease,
|
||||
background-color 0.15s ease,
|
||||
box-shadow 0.12s ease;
|
||||
}
|
||||
|
||||
.Content .btn-primary:hover:not(:disabled),
|
||||
.Content .btn-link:hover {
|
||||
background-color: darkseagreen;
|
||||
color: black;
|
||||
border-color: #2f4f4f;
|
||||
box-shadow: 0 5px 0 #2f4f4f;
|
||||
}
|
||||
|
||||
.Content .btn-primary:active:not(:disabled),
|
||||
.Content .btn-link:active {
|
||||
transform: translateY(3px);
|
||||
box-shadow: 0 2px 0 #2f4f4f;
|
||||
}
|
||||
|
||||
.Content .btn-primary:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* ---- Waiting page ---- */
|
||||
|
||||
.waiting-panel {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.waiting-panel .panel-subtitle {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.waiting-details {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 14px;
|
||||
margin: 22px 0;
|
||||
padding: 16px 0;
|
||||
border-top: 1px dashed rgba(105, 105, 105, 0.45);
|
||||
border-bottom: 1px dashed rgba(105, 105, 105, 0.45);
|
||||
}
|
||||
|
||||
.waiting-details .detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 12px 14px;
|
||||
border: 2px dashed #b9a887;
|
||||
border-radius: 12px;
|
||||
background-color: rgba(255, 248, 231, 0.75);
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-size: clamp(24px, 4vw, 32px);
|
||||
line-height: 1.1;
|
||||
color: #2f4f4f;
|
||||
}
|
||||
|
||||
.room-code-inline {
|
||||
color: cornflowerblue;
|
||||
letter-spacing: 0.14em;
|
||||
}
|
||||
|
||||
.waiting-indicator {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin: 8px 0 14px;
|
||||
}
|
||||
|
||||
.waiting-indicator span {
|
||||
width: 11px;
|
||||
height: 11px;
|
||||
border-radius: 50%;
|
||||
background-color: cornflowerblue;
|
||||
animation: waiting-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.waiting-indicator span:nth-child(2) {
|
||||
animation-delay: 0.18s;
|
||||
}
|
||||
|
||||
.waiting-indicator span:nth-child(3) {
|
||||
animation-delay: 0.36s;
|
||||
}
|
||||
|
||||
@keyframes waiting-pulse {
|
||||
0%,
|
||||
80%,
|
||||
100% {
|
||||
transform: scale(0.7);
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
40% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Teacher lobby ---- */
|
||||
|
||||
.room-panel {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.roster-heading {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 16px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.roster-heading h2 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.roster-heading .panel-subtitle {
|
||||
max-width: 280px;
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.count-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 34px;
|
||||
height: 34px;
|
||||
padding: 0 10px;
|
||||
border-radius: 999px;
|
||||
background-color: cornflowerblue;
|
||||
color: white;
|
||||
font-size: 19px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.page-lobby .table-container {
|
||||
overflow-x: auto;
|
||||
background-color: rgba(95, 158, 160, 0.18);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.roster-table {
|
||||
min-width: 480px;
|
||||
}
|
||||
|
||||
.roster-table th {
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
|
||||
.roster-table td.online {
|
||||
color: darkgreen;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.roster-table td.offline {
|
||||
color: #5a5a5a;
|
||||
}
|
||||
|
||||
.roster-table td.empty {
|
||||
padding: 22px 10px;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ---- Card grid: trading and teacher lobby ---- */
|
||||
|
||||
.card-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 14px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.card-grid > .panel {
|
||||
flex: 1 1 380px;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.trading-panel {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.trade-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.trade-chip {
|
||||
flex: 0 1 140px;
|
||||
padding: 14px 10px;
|
||||
border: 2px dashed #b9a887;
|
||||
border-radius: 12px;
|
||||
background-color: rgba(255, 248, 231, 0.75);
|
||||
}
|
||||
|
||||
.trade-chip span {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
color: #6b5a3e;
|
||||
}
|
||||
|
||||
.trade-chip strong {
|
||||
display: block;
|
||||
font-size: 30px;
|
||||
line-height: 1.1;
|
||||
color: #2f4f4f;
|
||||
}
|
||||
|
||||
.trade-arrow {
|
||||
font-size: 34px;
|
||||
line-height: 1;
|
||||
color: cornflowerblue;
|
||||
}
|
||||
|
||||
/* ---- Game status banner ---- */
|
||||
|
||||
.game-status {
|
||||
margin: 0 0 12px;
|
||||
padding: 10px 14px;
|
||||
border: 2px dashed gray;
|
||||
border-radius: 10px;
|
||||
background-color: moccasin;
|
||||
color: #2f4f4f;
|
||||
font-size: 20px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.game-status[data-tone="good"] {
|
||||
color: darkgreen;
|
||||
}
|
||||
|
||||
.game-status[data-tone="bad"] {
|
||||
color: darkred;
|
||||
}
|
||||
|
||||
/* ---- Teacher phase controls ---- */
|
||||
|
||||
.phase-controls {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
#phase-status {
|
||||
margin: 16px 0 0;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
/* ---- Trading roster ---- */
|
||||
|
||||
#trade-roster-panel .table-container {
|
||||
overflow-x: auto;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
#trade-roster-panel .roster-table {
|
||||
min-width: 100%;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#trade-roster-panel .roster-table th,
|
||||
#trade-roster-panel .roster-table td {
|
||||
padding: 10px;
|
||||
border: 1px solid black;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#trade-roster-panel .roster-table th {
|
||||
background-color: darkseagreen;
|
||||
}
|
||||
|
||||
.roster-table tr.offline-player td {
|
||||
color: #5a5a5a;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* ---- Discovery and trading ---- */
|
||||
|
||||
.found-list {
|
||||
margin: 12px 0 0;
|
||||
padding: 10px 14px;
|
||||
border: 2px dashed gray;
|
||||
border-radius: 10px;
|
||||
background-color: moccasin;
|
||||
color: #2f4f4f;
|
||||
font-size: 18px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.found-block {
|
||||
margin-top: 14px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px dashed rgba(105, 105, 105, 0.45);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.trade-found-list {
|
||||
margin: 4px 0 0;
|
||||
font-size: 19px;
|
||||
line-height: 1.4;
|
||||
color: #2f4f4f;
|
||||
}
|
||||
|
||||
.trade-offer-form {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.trade-offer-form .field {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.trade-offer-form select,
|
||||
.trade-amount input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 11px 12px;
|
||||
border: 2px solid #b9a887;
|
||||
border-radius: 9px;
|
||||
background-color: #fff8e7;
|
||||
color: #2b2b2b;
|
||||
font-family: "Almendra", serif;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.trade-offer-form select:focus,
|
||||
.trade-amount input:focus {
|
||||
outline: none;
|
||||
border-color: cornflowerblue;
|
||||
box-shadow: 0 0 0 3px rgba(100, 149, 237, 0.25);
|
||||
}
|
||||
|
||||
.trade-columns {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 14px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.trade-side {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 12px 14px 14px;
|
||||
border: 2px dashed #b9a887;
|
||||
border-radius: 12px;
|
||||
background-color: rgba(255, 248, 231, 0.75);
|
||||
}
|
||||
|
||||
.trade-side legend {
|
||||
padding: 0 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
color: #6b5a3e;
|
||||
}
|
||||
|
||||
.trade-amount {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.trade-amount span {
|
||||
font-size: 18px;
|
||||
color: #2f4f4f;
|
||||
}
|
||||
|
||||
.trade-amount input {
|
||||
width: 92px;
|
||||
flex: 0 0 auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.offer-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.offer-card {
|
||||
padding: 16px;
|
||||
border: 2px dashed #b9a887;
|
||||
border-radius: 12px;
|
||||
background-color: rgba(255, 248, 231, 0.75);
|
||||
}
|
||||
|
||||
.offer-summary {
|
||||
margin: 0 0 12px;
|
||||
font-size: 19px;
|
||||
line-height: 1.45;
|
||||
color: #2f4f4f;
|
||||
}
|
||||
|
||||
.offer-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.Content .offer-actions .btn-small {
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
min-height: 44px;
|
||||
height: auto;
|
||||
padding: 8px 18px;
|
||||
font-size: 18px;
|
||||
box-shadow: 0 4px 0 #2f4f4f;
|
||||
}
|
||||
|
||||
.Content .offer-actions .btn-small:active {
|
||||
transform: translateY(2px);
|
||||
box-shadow: 0 2px 0 #2f4f4f;
|
||||
}
|
||||
|
||||
.Content .btn-quiet {
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
min-height: 44px;
|
||||
height: auto;
|
||||
padding: 8px 18px;
|
||||
border: 2px solid #8b7a5c;
|
||||
border-radius: 10px;
|
||||
background-color: transparent;
|
||||
color: #5a4a30;
|
||||
font-family: "Almendra", serif;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 0 rgba(90, 74, 48, 0.35);
|
||||
}
|
||||
|
||||
.Content .btn-quiet:hover {
|
||||
background-color: rgba(255, 248, 231, 0.9);
|
||||
color: #2b2b2b;
|
||||
}
|
||||
|
||||
/* ---- Small screens ---- */
|
||||
|
||||
@media (min-width: 1440px) {
|
||||
body.page-lobby .Content,
|
||||
body.page-trading .Content {
|
||||
max-width: 1120px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
body.page {
|
||||
margin: 10px;
|
||||
min-height: calc(100vh - 20px);
|
||||
}
|
||||
|
||||
body.page .Content {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.form-grid,
|
||||
.waiting-details {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.roster-heading {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.roster-heading .panel-subtitle {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.trade-preview {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.trade-chip {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.trade-columns {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.trade-columns > .trade-arrow {
|
||||
align-self: center;
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.trade-amount input {
|
||||
width: 110px;
|
||||
}
|
||||
|
||||
.panel::before {
|
||||
inset: 6px;
|
||||
}
|
||||
|
||||
.room-code {
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.waiting-indicator span {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
-179
@@ -1,179 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Escape the Island</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="assets/shipwreck.png" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
</head>
|
||||
<body class="page page-trading">
|
||||
<header>
|
||||
<div class="header-container">
|
||||
<h1>Escape the Island</h1>
|
||||
<div class="boat-container">
|
||||
<img src="assets/boat-small.png" alt="" class="boat" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="Content">
|
||||
<section class="panel trading-panel">
|
||||
<p class="eyebrow">The Trading Post</p>
|
||||
<h2>Day <span id="trade-day">-</span> trading</h2>
|
||||
<p class="panel-subtitle">
|
||||
The day has ended. Compare supplies with the castaways you found
|
||||
during the day and make an offer. Trading does not cost any daily
|
||||
hours.
|
||||
</p>
|
||||
|
||||
<div class="trade-preview">
|
||||
<div class="trade-chip">
|
||||
<span>Your Fish</span>
|
||||
<strong id="trade-fish">-</strong>
|
||||
</div>
|
||||
<div class="trade-arrow">⇄</div>
|
||||
<div class="trade-chip">
|
||||
<span>Your Wood</span>
|
||||
<strong id="trade-wood">-</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="trade-status" class="lobby-status" aria-live="polite">
|
||||
Connecting...
|
||||
</p>
|
||||
|
||||
<div class="found-block">
|
||||
<p class="field-label">Castaways You Know</p>
|
||||
<p id="trade-found-list" class="trade-found-list">
|
||||
No one yet. You can only trade with castaways you found during the
|
||||
day.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="card-grid">
|
||||
<section class="panel" id="trade-offer-panel" hidden>
|
||||
<p class="eyebrow">Make an Offer</p>
|
||||
<h2>Trade supplies</h2>
|
||||
<p class="panel-subtitle">
|
||||
Choose what you give and what you want back. The other castaway must
|
||||
accept before anything changes hands.
|
||||
</p>
|
||||
|
||||
<form
|
||||
id="trade-offer-form"
|
||||
class="trade-offer-form"
|
||||
autocomplete="off"
|
||||
>
|
||||
<label class="field">
|
||||
<span class="field-label">Trade With</span>
|
||||
<select id="trade-target"></select>
|
||||
</label>
|
||||
|
||||
<div class="trade-columns">
|
||||
<fieldset class="trade-side">
|
||||
<legend>You Give</legend>
|
||||
<label class="trade-amount">
|
||||
<span>Fish</span>
|
||||
<input
|
||||
type="number"
|
||||
id="trade-give-fish"
|
||||
min="0"
|
||||
step="1"
|
||||
value="0"
|
||||
/>
|
||||
</label>
|
||||
<label class="trade-amount">
|
||||
<span>Wood</span>
|
||||
<input
|
||||
type="number"
|
||||
id="trade-give-wood"
|
||||
min="0"
|
||||
step="1"
|
||||
value="0"
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
<div class="trade-arrow" aria-hidden="true">⇄</div>
|
||||
|
||||
<fieldset class="trade-side">
|
||||
<legend>You Want</legend>
|
||||
<label class="trade-amount">
|
||||
<span>Fish</span>
|
||||
<input
|
||||
type="number"
|
||||
id="trade-want-fish"
|
||||
min="0"
|
||||
step="1"
|
||||
value="0"
|
||||
/>
|
||||
</label>
|
||||
<label class="trade-amount">
|
||||
<span>Wood</span>
|
||||
<input
|
||||
type="number"
|
||||
id="trade-want-wood"
|
||||
min="0"
|
||||
step="1"
|
||||
value="0"
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-primary">Send Offer</button>
|
||||
</form>
|
||||
|
||||
<p id="trade-offer-status" class="lobby-status" aria-live="polite"></p>
|
||||
</section>
|
||||
|
||||
<section class="panel" id="trade-incoming-panel" hidden>
|
||||
<p class="eyebrow">Incoming</p>
|
||||
<h2>Offers for you</h2>
|
||||
<div id="trade-incoming-list" class="offer-list"></div>
|
||||
</section>
|
||||
|
||||
<section class="panel" id="trade-outgoing-panel" hidden>
|
||||
<p class="eyebrow">Waiting</p>
|
||||
<h2>Your offers</h2>
|
||||
<div id="trade-outgoing-list" class="offer-list"></div>
|
||||
</section>
|
||||
|
||||
<section class="panel" id="trade-roster-panel" hidden>
|
||||
<p class="eyebrow">Supplies Afloat</p>
|
||||
<h2>Castaways You Know</h2>
|
||||
<div class="table-container">
|
||||
<table class="roster-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Fish</th>
|
||||
<th>Wood</th>
|
||||
<th>Preserver</th>
|
||||
<th>Boat</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="trade-roster-body">
|
||||
<tr>
|
||||
<td colspan="5" class="empty">Waiting for the crew...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<h3 style="padding: 0px 0px 0px 10px">
|
||||
Gamemaker: Mr. J. Walla ~=~ Developer: Andrew H. ~=~ Designer: Logan C.
|
||||
</h3>
|
||||
</footer>
|
||||
<script type="module" src="client/trading.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Environment setup & latest features
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"module": "Preserve",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
"types": ["bun"],
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Escape the Island</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="assets/shipwreck.png" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
</head>
|
||||
<body class="page page-waiting">
|
||||
<header>
|
||||
<div class="header-container">
|
||||
<h1>Escape the Island</h1>
|
||||
<div class="boat-container">
|
||||
<img src="assets/boat-small.png" alt="" class="boat" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="Content">
|
||||
<section class="panel waiting-panel">
|
||||
<p class="eyebrow">Waiting On The Shore</p>
|
||||
<h2>You made it to the island</h2>
|
||||
<p class="panel-subtitle">
|
||||
Your teacher will start the first day once the whole class has
|
||||
joined. Keep this tab open.
|
||||
</p>
|
||||
|
||||
<div class="waiting-details">
|
||||
<div class="detail">
|
||||
<span class="field-label">Castaway</span>
|
||||
<strong id="waiting-name" class="detail-value">----</strong>
|
||||
</div>
|
||||
<div class="detail">
|
||||
<span class="field-label">Room Code</span>
|
||||
<strong id="waiting-code" class="detail-value room-code-inline">
|
||||
----
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="waiting-indicator" aria-hidden="true">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</div>
|
||||
<p id="waiting-status" class="lobby-status" role="status" aria-live="polite">
|
||||
Connecting...
|
||||
</p>
|
||||
<p class="panel-footnote">
|
||||
If your connection drops, this page will reconnect automatically.
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
<footer>
|
||||
<h3 style="padding: 0px 0px 0px 10px">
|
||||
Gamemaker: Mr. J. Walla ~=~ Developer: Andrew H. ~=~ Designer: Logan C.
|
||||
</h3>
|
||||
</footer>
|
||||
<script type="module" src="client/waiting.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,25 +0,0 @@
|
||||
<!doctype html>
|
||||
<meta charset="utf-8" />
|
||||
<title>WebSocket test</title>
|
||||
<button id="send">Send</button>
|
||||
<pre id="log"></pre>
|
||||
|
||||
<script>
|
||||
const logEl = document.getElementById("log");
|
||||
const log = (msg) => (logEl.textContent += msg + "\n");
|
||||
const wsProto = location.protocol === "https:" ? "wss:" : "ws:";
|
||||
const ws = new WebSocket(`${wsProto}//${location.host}/ws`);
|
||||
|
||||
ws.onopen = () => {
|
||||
log("open");
|
||||
ws.send(JSON.stringify({ type: "ECHO", text: "hello" }));
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => log("recv: " + event.data);
|
||||
ws.onclose = (event) => log(`close ${event.code}`);
|
||||
ws.onerror = () => log("error");
|
||||
|
||||
document.getElementById("send").onclick = () => {
|
||||
ws.send(JSON.stringify({ type: "ECHO", text: "button " }));
|
||||
};
|
||||
</script>
|
||||
Reference in new issue
Block a user