an implementation of the Mastermind game in SvelteKit (on Node), aiming for good UX.
This is my first project in svelte.
key | action |
---|---|
A..H on QWERTY | guess a color (corrseponding to order in UI selection row) |
Backspace | reset a dot under the cursor; move the cursor backwards |
Enter | submit the sequence/guess if possible |
Esc | reset the current field |
P | reset the game state completely |
red dot means a guessed color exists in the sequence.
white dot means a guessed color exists in the sequence and is on the same position as a guessed value.
you win if the guess matches the original sequence, so, if all the dots in the rating are white.
you lose after 15 consecutive non-winning attempts.
the sequences and guesses can contain duplicates. empty fields are not allowed, though.
when rating, a dot is given only if a corresponding duplicate exists in the original sequence.
sequence contains two yellows, guess contains three --> two dots are given in the rating for guessed yellows.
the rating is done left-to-right.
some behavior is described in the comment here: lib/logik.ts:52.
the game greets you with the initial sequence input screenn.
here you can input the sequence the player will try to guess using buttons on the bottom row or keys. submit it with the Enter key or the appearing button.
after that, the guessing screen opens.
you can input the guess the same way as the sequence and submit it.
on submission, your guess will be rated according to the rules mentioned above.
rating results in colored dots appearing left to the guess row, representing fulfilled rating conditions stated above.
old guesses remain available for reference.
if you neither win nor lose, another row appends to the end and you can guess again.
at a win/lose you're given the choice to reset the game and play again.
fetch dependencies with npm:
$ npm install
and then
$ npm run build
$ npm run preview
or for development:
$ npm run dev
logik.svelte
likely isn't an independed component yet