Ring minigame !!
This commit is contained in:
@@ -389,3 +389,118 @@ Deno.test("harder valley fish move around more", async () => {
|
||||
assert(hard > easy * 2, `${hard} isn't much more than ${easy}`);
|
||||
}, "valley");
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame lands the fish when clicked with the green ring in the gray one", async () => {
|
||||
const t = await setup();
|
||||
// at difficulty 0 it grows 1 a tick
|
||||
await with_minigames(() =>
|
||||
with_difficulty(0, async () => {
|
||||
const open = () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
return opened_menu(t.take(1));
|
||||
};
|
||||
const closes = () => t.take(1).some((m: Msg) => m.type === "close_menu");
|
||||
|
||||
// too early: the green ring starts at 4, the gray one is from 44 to 52
|
||||
let opened = open();
|
||||
assertEquals(opened.data, {
|
||||
radius: 4,
|
||||
rings: 1,
|
||||
checked: 0,
|
||||
ring_radius: 48,
|
||||
ring_spacing: 16,
|
||||
ring_width: 8,
|
||||
});
|
||||
for (let i = 0; i < 30; i++) t.game.tick();
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
t.game.tick();
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 0);
|
||||
|
||||
// too late: past 52 it's gone
|
||||
opened = open();
|
||||
for (let i = 0; i < 48; i++) t.game.tick();
|
||||
assert(!closes());
|
||||
t.game.tick();
|
||||
t.game.tick();
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 0);
|
||||
|
||||
// in it
|
||||
opened = open();
|
||||
for (let i = 0; i < 44; i++) t.game.tick();
|
||||
assertEquals(menu_data(t.take(1))?.radius, 48);
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
assertEquals(t.fish().map((i: Msg) => i.id), ["bworld:cod"]);
|
||||
}), "ring");
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame's green ring grows faster the harder the fish is", async () => {
|
||||
const t = await setup();
|
||||
let radius = 0;
|
||||
// how big it is after 10 ticks, from 4
|
||||
const after_10_ticks = (difficulty: number | undefined) =>
|
||||
with_difficulty(difficulty, async () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
t.take(1);
|
||||
for (let i = 0; i < 10; i++) t.game.tick();
|
||||
radius = menu_data(t.take(1))?.radius;
|
||||
});
|
||||
await with_minigames(async () => {
|
||||
await after_10_ticks(undefined);
|
||||
assertAlmostEquals(radius, 4 + 11);
|
||||
await after_10_ticks(100);
|
||||
assertEquals(radius, 4 + 20);
|
||||
}, "ring");
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame has a ring for every 30 difficulty", async () => {
|
||||
const t = await setup();
|
||||
const rings: number[] = [];
|
||||
await with_minigames(async () => {
|
||||
for (const difficulty of [0, 30, 31, 60, 61, 90, 91, 120]) {
|
||||
await with_difficulty(difficulty, async () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
rings.push(opened_menu(t.take(1)).data.rings);
|
||||
});
|
||||
}
|
||||
}, "ring");
|
||||
assertEquals(rings, [1, 1, 2, 2, 3, 3, 4, 4]);
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame needs every ring checked, and missing one loses it", async () => {
|
||||
const t = await setup();
|
||||
const closes = () => t.take(1).some((m: Msg) => m.type === "close_menu");
|
||||
// at 60 there are 2 rings, at 48 and 64, and the green ring grows 1.6 a tick from 4
|
||||
await with_minigames(() =>
|
||||
with_difficulty(60, async () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
let opened = opened_menu(t.take(1));
|
||||
for (let i = 0; i < 26; i++) t.game.tick(); // 45.6
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
assertEquals(menu_data(t.take(1))?.checked, 1);
|
||||
assertEquals(t.fish().length, 0);
|
||||
for (let i = 0; i < 11; i++) t.game.tick(); // 63.2
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
assertEquals(t.fish().map((i: Msg) => i.id), ["bworld:cod"]);
|
||||
|
||||
// checking the first and letting the green ring past the second
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
opened = opened_menu(t.take(1));
|
||||
for (let i = 0; i < 26; i++) t.game.tick();
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
for (let i = 0; i < 15; i++) t.game.tick(); // 71.2
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 1);
|
||||
|
||||
// clicking twice in the first: the second click isn't in the second ring
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
opened = opened_menu(t.take(1));
|
||||
for (let i = 0; i < 26; i++) t.game.tick();
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
t.game.tick();
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 1);
|
||||
}), "ring");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user