bitburner-src/src/Infiltration/ui/BackwardGame.tsx

313 lines
5.4 KiB
TypeScript
Raw Normal View History

2021-09-05 01:09:30 +02:00
import React, { useState } from "react";
2021-09-17 01:23:03 +02:00
import Grid from "@mui/material/Grid";
import { IMinigameProps } from "./IMinigameProps";
import { KeyHandler } from "./KeyHandler";
import { GameTimer } from "./GameTimer";
import { random } from "../utils";
import { interpolate } from "./Difficulty";
import { BlinkingCursor } from "./BlinkingCursor";
import { KEY } from "../../utils/helpers/keyCodes";
import { Player } from "../../Player";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
2022-04-24 21:50:55 +02:00
import { Paper, Typography, Box } from "@mui/material";
interface Difficulty {
2021-09-05 01:09:30 +02:00
[key: string]: number;
timer: number;
min: number;
max: number;
}
const difficulties: {
2021-09-05 01:09:30 +02:00
Trivial: Difficulty;
Normal: Difficulty;
Hard: Difficulty;
Impossible: Difficulty;
} = {
2021-09-05 01:09:30 +02:00
Trivial: { timer: 16000, min: 3, max: 4 },
Normal: { timer: 12500, min: 2, max: 3 },
Hard: { timer: 15000, min: 3, max: 4 },
Impossible: { timer: 8000, min: 4, max: 4 },
};
export function BackwardGame(props: IMinigameProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const difficulty: Difficulty = { timer: 0, min: 0, max: 0 };
interpolate(difficulties, props.difficulty, difficulty);
const timer = difficulty.timer;
const [answer] = useState(makeAnswer(difficulty));
const [guess, setGuess] = useState("");
2022-04-22 21:30:49 +02:00
const hasAugment = Player.hasAugmentation(AugmentationNames.ChaosOfDionysus, true);
2021-09-25 04:15:19 +02:00
function press(this: Document, event: KeyboardEvent): void {
2021-09-05 01:09:30 +02:00
event.preventDefault();
if (event.key === KEY.BACKSPACE) return;
2021-09-05 01:09:30 +02:00
const nextGuess = guess + event.key.toUpperCase();
if (!answer.startsWith(nextGuess)) props.onFailure();
else if (answer === nextGuess) props.onSuccess();
else setGuess(nextGuess);
}
2021-09-05 01:09:30 +02:00
return (
2022-04-24 21:50:55 +02:00
<>
2021-09-05 01:09:30 +02:00
<GameTimer millis={timer} onExpire={props.onFailure} />
2022-04-24 21:50:55 +02:00
<Paper sx={{ display: "grid", justifyItems: "center", pb: 1 }}>
2022-03-25 16:39:14 +01:00
<Typography variant="h4">Type it{!hasAugment ? " backward" : ""}</Typography>
2021-09-05 01:09:30 +02:00
<KeyHandler onKeyDown={press} onFailure={props.onFailure} />
2022-04-24 21:50:55 +02:00
<Typography style={{ transform: hasAugment ? "none" : "scaleX(-1)" }}>{answer}</Typography>
2021-10-01 19:08:37 +02:00
<Typography>
2021-09-05 01:09:30 +02:00
{guess}
<BlinkingCursor />
2021-10-01 19:08:37 +02:00
</Typography>
2022-04-24 21:50:55 +02:00
</Paper>
</>
2021-09-05 01:09:30 +02:00
);
}
function makeAnswer(difficulty: Difficulty): string {
2021-09-05 01:09:30 +02:00
const length = random(difficulty.min, difficulty.max);
let answer = "";
for (let i = 0; i < length; i++) {
if (i > 0) answer += " ";
answer += words[Math.floor(Math.random() * words.length)];
}
2021-09-05 01:09:30 +02:00
return answer;
}
2021-09-05 01:09:30 +02:00
const words = [
"ALGORITHM",
"ANALOG",
"APP",
"APPLICATION",
"ARRAY",
"BACKUP",
"BANDWIDTH",
"BINARY",
"BIT",
"BITE",
"BITMAP",
"BLOG",
"BLOGGER",
"BOOKMARK",
"BOOT",
"BROADBAND",
"BROWSER",
"BUFFER",
"BUG",
"BUS",
"BYTE",
"CACHE",
"CAPS LOCK",
"CAPTCHA",
"CD",
"CD-ROM",
"CLIENT",
"CLIPBOARD",
"CLOUD",
"COMPUTING",
"COMMAND",
"COMPILE",
"COMPRESS",
"COMPUTER",
"CONFIGURE",
"COOKIE",
"COPY",
"CPU",
"CYBERCRIME",
"CYBERSPACE",
"DASHBOARD",
"DATA",
"MINING",
"DATABASE",
"DEBUG",
"DECOMPRESS",
"DELETE",
"DESKTOP",
"DEVELOPMENT",
"DIGITAL",
"DISK",
"DNS",
"DOCUMENT",
"DOMAIN",
"DOMAIN NAME",
"DOT",
"DOT MATRIX",
"DOWNLOAD",
"DRAG",
"DVD",
"DYNAMIC",
"EMAIL",
"EMOTICON",
"ENCRYPT",
"ENCRYPTION",
"ENTER",
"EXABYTE",
"FAQ",
"FILE",
"FINDER",
"FIREWALL",
"FIRMWARE",
"FLAMING",
"FLASH",
"FLASH DRIVE",
"FLOPPY DISK",
"FLOWCHART",
"FOLDER",
"FONT",
"FORMAT",
"FRAME",
"FREEWARE",
"GIGABYTE",
"GRAPHICS",
"HACK",
"HACKER",
"HARDWARE",
"HOME PAGE",
"HOST",
"HTML",
"HYPERLINK",
"HYPERTEXT",
"ICON",
"INBOX",
"INTEGER",
"INTERFACE",
"INTERNET",
"IP ADDRESS",
"ITERATION",
"JAVA",
"JOYSTICK",
"JUNKMAIL",
"KERNEL",
"KEY",
"KEYBOARD",
"KEYWORD",
"LAPTOP",
"LASER PRINTER",
"LINK",
"LINUX",
"LOG OUT",
"LOGIC",
"LOGIN",
"LURKING",
"MACINTOSH",
"MACRO",
"MAINFRAME",
"MALWARE",
"MEDIA",
"MEMORY",
"MIRROR",
"MODEM",
"MONITOR",
"MOTHERBOARD",
"MOUSE",
"MULTIMEDIA",
"NET",
"NETWORK",
"NODE",
"NOTEBOOK",
"COMPUTER",
"OFFLINE",
"ONLINE",
"OPENSOURCE",
"OPERATING",
"SYSTEM",
"OPTION",
"OUTPUT",
"PAGE",
"PASSWORD",
"PASTE",
"PATH",
"PHISHING",
"PIRACY",
"PIRATE",
"PLATFORM",
"PLUGIN",
"PODCAST",
"POPUP",
"PORTAL",
"PRINT",
"PRINTER",
"PRIVACY",
"PROCESS",
"PROGRAM",
"PROGRAMMER",
"PROTOCOL",
"QUEUE",
"QWERTY",
"RAM",
"REALTIME",
"REBOOT",
"RESOLUTION",
"RESTORE",
"ROM",
"ROOT",
"ROUTER",
"RUNTIME",
"SAVE",
"SCAN",
"SCANNER",
"SCREEN",
"SCREENSHOT",
"SCRIPT",
"SCROLL",
"SCROLL",
"SEARCH",
"ENGINE",
"SECURITY",
"SERVER",
"SHAREWARE",
"SHELL",
"SHIFT",
"SHIFT KEY",
"SNAPSHOT",
"SOCIAL NETWORKING",
"SOFTWARE",
"SPAM",
"SPAMMER",
"SPREADSHEET",
"SPYWARE",
"STATUS",
"STORAGE",
"SUPERCOMPUTER",
"SURF",
"SYNTAX",
"TABLE",
"TAG",
"TERMINAL",
"TEMPLATE",
"TERABYTE",
"TEXT EDITOR",
"THREAD",
"TOOLBAR",
"TRASH",
"TROJAN HORSE",
"TYPEFACE",
"UNDO",
"UNIX",
"UPLOAD",
"URL",
"USER",
"USER INTERFACE",
"USERNAME",
"UTILITY",
"VERSION",
"VIRTUAL",
"VIRTUAL MEMORY",
"VIRUS",
"WEB",
"WEBMASTER",
"WEBSITE",
"WIDGET",
"WIKI",
"WINDOW",
"WINDOWS",
"WIRELESS",
"PROCESSOR",
"WORKSTATION",
"WEB",
"WORM",
"WWW",
"XML",
"ZIP",
];