The same card game โ but every line of it is Python, running in your browser
โ Back to Fun TimeThere is almost no JavaScript on this page. The browser downloaded Pyodide โ a complete Python interpreter compiled to WebAssembly โ and then ran the .py files in funtime/pylib/. Python does the rules, the maths and the drawing.
| File | What it does | Good functions to try re-writing |
|---|---|---|
| pylib/memory_rules.py | The rules: dealing, flipping, matching | card_index, create_deck, is_match, flip_card |
| pylib/memory_draw.py | Painting the cards โ Python calling the canvas | draw_symbol, draw_card, card_at_pixel |
| pylib/memory_web.py | The glue: clicks, keyboard, the loop | do_action, on_board_click, frame |
๐ Compare the two versions. Open lib/memory-rules.js and pylib/memory_rules.py side by side โ same ideas, two languages.
๐ ๏ธ Build it yourself: Build Memory Match in Python walks you through the functions one at a time.
โ ๏ธ If the game never starts: the page has to read its .py files, which a browser will not do for a page opened straight off your disk. Use the live site, or run python3 -m http.server in the project folder.