├── .gitignore ├── env.ts ├── old-code └── src │ ├── deps.ts │ ├── server-ssr.jsx │ └── index.jsx ├── import_map.json ├── jsconfig.json ├── .vscode └── settings.json ├── README.md ├── client └── index.jsx ├── file.ts ├── scripts.json ├── colors.ts ├── pokedle.ts └── dist └── pokedle.js /.gitignore: -------------------------------------------------------------------------------- 1 | solution.txt -------------------------------------------------------------------------------- /env.ts: -------------------------------------------------------------------------------- 1 | export const isArceusMode = Boolean(Deno.env.get('ARCEUS_MODE')) 2 | -------------------------------------------------------------------------------- /old-code/src/deps.ts: -------------------------------------------------------------------------------- 1 | export { serve } from "https://deno.land/std@0.125.0/http/server.ts"; 2 | -------------------------------------------------------------------------------- /import_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "imports": { 3 | "colors": "https://deno.land/std@0.125.0/fmt/colors.ts" 4 | } 5 | } -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "lint": { 3 | "rules": { 4 | "tags": ["recommended"], 5 | "exclude": ["import-prefix-missing"] 6 | } 7 | }, 8 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "deno.enable": true, 3 | "deno.lint": true, 4 | "deno.unstable": false, 5 | "deno.importMap": "./import_map.json" 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deno-wordle 2 | 3 | ![FKyK56NXMAUU5Dd](https://user-images.githubusercontent.com/1561955/152847579-3ef0d0f9-738e-47ba-8261-fccc6ea8684c.jpeg) 4 | 5 | -------------------------------------------------------------------------------- /client/index.jsx: -------------------------------------------------------------------------------- 1 | import { App } from "../src/index.jsx"; 2 | 3 | ReactDOM.hydrate( 4 | , 5 | document.getElementById("root"), 6 | ); 7 | -------------------------------------------------------------------------------- /file.ts: -------------------------------------------------------------------------------- 1 | export const writePokemonFile = (pokemon: string) => { 2 | // return Deno.writeTextFile('./solution.txt', pokemon) 3 | 4 | const encoder = new TextEncoder() 5 | const bytes = encoder.encode(pokemon) 6 | return Deno.writeFile('./solution.txt', bytes) 7 | } 8 | -------------------------------------------------------------------------------- /scripts.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "deno bundle pokedle.ts > ./dist/pokedle.js", 4 | "run": "deno run --allow-net=pokeapi.co --allow-env=ARCEUS_MODE pokedle.ts", 5 | "lint": "deno lint", 6 | "fmt": "deno fmt", 7 | "dev": "deno run --watch --allow-write --allow-env=ARCEUS_MODE --allow-net=pokeapi.co pokedle.ts" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /colors.ts: -------------------------------------------------------------------------------- 1 | import { 2 | bgBrightBlack, 3 | bgGreen, 4 | bgYellow, 5 | bold, 6 | white, 7 | //} from "colors"; 8 | } from "https://deno.land/std@0.125.0/fmt/colors.ts"; 9 | 10 | const colorMethods = { 11 | green: bgGreen, 12 | yellow: bgYellow, 13 | gray: bgBrightBlack, 14 | }; 15 | 16 | export function colorLetter(color: "green" | "yellow" | "gray", letter: string) { 17 | const bg = colorMethods[color]; 18 | const colorizedLetter = bg(bold(` ${white(letter)} `)); 19 | return ` ${colorizedLetter} `; 20 | } -------------------------------------------------------------------------------- /old-code/src/server-ssr.jsx: -------------------------------------------------------------------------------- 1 | import React from "https://esm.sh/react"; 2 | import { renderToString } from "https://esm.sh/react-dom/server"; 3 | import { serve } from "https://deno.land/std@0.125.0/http/server.ts"; 4 | import { App } from "./src/index.jsx"; 5 | 6 | serve((req) => { 7 | const { url } = req; 8 | 9 | const { pathname } = new URL(url); 10 | 11 | const app = renderToString(); 12 | 13 | return new Response(`
${app}
`, { 14 | headers: { 15 | "content-type": "text/html; charset=utf-8", 16 | }, 17 | }); 18 | }, { port: 8000 }); 19 | -------------------------------------------------------------------------------- /old-code/src/index.jsx: -------------------------------------------------------------------------------- 1 | import React from "https://esm.sh/react"; 2 | 3 | export function App({ pathname }) { 4 | return ( 5 | <> 6 | 20 | {pathname === "/login" && ( 21 |
22 | 23 |
24 | )} 25 | {pathname === "/" && ( 26 | <> 27 |

Hola mundo!

28 | 29 | 30 | )} 31 | 32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /pokedle.ts: -------------------------------------------------------------------------------- 1 | import { colorLetter } from "./colors.ts"; 2 | import { writePokemonFile } from './file.ts' 3 | import { isArceusMode } from './env.ts' 4 | 5 | const MAX_TRIES = 6; 6 | const POKEMONS_AVAILABLE = 850; 7 | 8 | const previousGuesses: Array = []; 9 | const randomId = Math.ceil(Math.random() * (POKEMONS_AVAILABLE - 1)); 10 | 11 | const pokemon = await fetch(`https://pokeapi.co/api/v2/pokemon/${randomId}/`) 12 | .then((res) => res.json()) 13 | .then((response) => response.name.toUpperCase()); 14 | 15 | if (isArceusMode) { 16 | await writePokemonFile(pokemon) 17 | } 18 | 19 | let globalResults = ""; 20 | // this pokemon should be fetched randomly from the API 21 | 22 | function askWord() { 23 | const response = prompt("The Pokemon is..."); 24 | if (response == null) { 25 | return { error: "💬 You must provide a possible pokemon name" }; 26 | } else if (response.length !== pokemon.length) { 27 | return { 28 | error: "📏 The pokemon name must be " + pokemon.length + 29 | " characters long", 30 | }; 31 | } else if (previousGuesses.includes(response.toUpperCase())) { 32 | return { error: "📋 You already tried this pokemon name!" }; 33 | } else if (!/^[a-zA-Z]+$/.test(response)) { 34 | return { error: "📋 The pokemon name must contain only letters" }; 35 | } 36 | 37 | return { response: response.toUpperCase() }; 38 | } 39 | 40 | function print(guess: string) { 41 | console.clear(); 42 | 43 | let results = ""; 44 | 45 | const letters: Array = [...guess]; 46 | 47 | letters.forEach((letter, index) => { 48 | if (letter === pokemon[index]) { 49 | results += colorLetter("green", letter); 50 | } else if (pokemon.includes(letter)) { 51 | results += colorLetter("yellow", letter); 52 | } else { 53 | results += colorLetter("gray", letter); 54 | } 55 | }); 56 | 57 | globalResults += `${results} \n\n`; 58 | console.log(globalResults); 59 | } 60 | 61 | function start(tries: number) { 62 | if (tries >= MAX_TRIES) { 63 | console.log("💥 You lost!"); 64 | console.log("💥 The pokemon was " + pokemon); 65 | return; 66 | } 67 | 68 | let guess = ""; 69 | while (guess === "") { 70 | const { error, response } = askWord(); 71 | if (error) { 72 | console.error(error); 73 | continue; 74 | } 75 | 76 | if (response) guess = response; 77 | } 78 | 79 | if (guess === pokemon) { 80 | print(guess); 81 | console.log("🎉 You won!"); 82 | return; 83 | } else { 84 | print(guess); 85 | console.log(""); 86 | tries++; 87 | start(tries); 88 | } 89 | } 90 | 91 | let timesPlayed = +(localStorage.getItem('times_played') || 0) 92 | timesPlayed++ 93 | localStorage.setItem('times_played', timesPlayed.toString()) 94 | 95 | console.log("🎮 Let's play a game! Guess the Pokemon Name"); 96 | console.log(`💡 Hint: It has ${pokemon.length} characters... Good luck!`); 97 | console.log(`🔥 You have played ${timesPlayed} times`); 98 | start(0); 99 | -------------------------------------------------------------------------------- /dist/pokedle.js: -------------------------------------------------------------------------------- 1 | // deno-fmt-ignore-file 2 | // deno-lint-ignore-file 3 | // This code was bundled using `deno bundle` and it's not recommended to edit it manually 4 | 5 | const { Deno } = globalThis; 6 | const noColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : true; 7 | let enabled = !noColor; 8 | function code(open, close) { 9 | return { 10 | open: `\x1b[${open.join(";")}m`, 11 | close: `\x1b[${close}m`, 12 | regexp: new RegExp(`\\x1b\\[${close}m`, "g") 13 | }; 14 | } 15 | function run(str, code1) { 16 | return enabled ? `${code1.open}${str.replace(code1.regexp, code1.open)}${code1.close}` : str; 17 | } 18 | function bold(str) { 19 | return run(str, code([ 20 | 1 21 | ], 22)); 22 | } 23 | function white(str) { 24 | return run(str, code([ 25 | 37 26 | ], 39)); 27 | } 28 | function bgGreen(str) { 29 | return run(str, code([ 30 | 42 31 | ], 49)); 32 | } 33 | function bgYellow(str) { 34 | return run(str, code([ 35 | 43 36 | ], 49)); 37 | } 38 | function bgBrightBlack(str) { 39 | return run(str, code([ 40 | 100 41 | ], 49)); 42 | } 43 | new RegExp([ 44 | "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", 45 | "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", 46 | ].join("|"), "g"); 47 | const previousGuesses = []; 48 | const randomId = Math.ceil(Math.random() * (850 - 1)); 49 | const pokemon = await fetch(`https://pokeapi.co/api/v2/pokemon/${randomId}/`).then((res)=>res.json() 50 | ).then((response)=>response.name.toUpperCase() 51 | ); 52 | let globalResults = ""; 53 | function askWord() { 54 | const response = prompt("The Pokemon is..."); 55 | if (response == null) { 56 | return { 57 | error: "💬 You must provide a possible pokemon name" 58 | }; 59 | } else if (response.length !== pokemon.length) { 60 | return { 61 | error: "📏 The pokemon name must be " + pokemon.length + " characters long" 62 | }; 63 | } else if (previousGuesses.includes(response.toUpperCase())) { 64 | return { 65 | error: "📋 You already tried this pokemon name!" 66 | }; 67 | } else if (!/^[a-zA-Z]+$/.test(response)) { 68 | return { 69 | error: "📋 The pokemon name must contain only letters" 70 | }; 71 | } 72 | return { 73 | response: response.toUpperCase() 74 | }; 75 | } 76 | const colorMethods = { 77 | green: bgGreen, 78 | yellow: bgYellow, 79 | gray: bgBrightBlack 80 | }; 81 | function colorLetter(color, letter) { 82 | const bg = colorMethods[color]; 83 | const colorizedLetter = bg(bold(` ${white(letter)} `)); 84 | return ` ${colorizedLetter} `; 85 | } 86 | function print(guess) { 87 | console.clear(); 88 | let results = ""; 89 | const letters = [ 90 | ...guess 91 | ]; 92 | letters.forEach((letter, index)=>{ 93 | if (letter === pokemon[index]) { 94 | results += colorLetter("green", letter); 95 | } else if (pokemon.includes(letter)) { 96 | results += colorLetter("yellow", letter); 97 | } else { 98 | results += colorLetter("gray", letter); 99 | } 100 | }); 101 | globalResults += `${results} \n\n`; 102 | console.log(globalResults); 103 | } 104 | function start(tries) { 105 | if (tries >= 6) { 106 | console.log("💥 You lost!"); 107 | console.log("💥 The pokemon was " + pokemon); 108 | return; 109 | } 110 | let guess = ""; 111 | while(guess === ""){ 112 | const { error , response } = askWord(); 113 | if (error) { 114 | console.error(error); 115 | continue; 116 | } 117 | if (response) guess = response; 118 | } 119 | if (guess === pokemon) { 120 | print(guess); 121 | console.log("🎉 You won!"); 122 | return; 123 | } else { 124 | print(guess); 125 | console.log(""); 126 | tries++; 127 | start(tries); 128 | } 129 | } 130 | console.log("🎮 Let's play a game! Guess the Pokemon Name"); 131 | console.log(`💡 Hint: It has ${pokemon.length} characters... Good luck!`); 132 | start(0); 133 | 134 | --------------------------------------------------------------------------------