In this project, you will create a command-line Bejeweled game. Unlike
previous projects, you will be start by implementing test specs in
bejeweled-spec.js
for the game logic. Once these specs are in place, you can
implement the game logic in bejeweled.js
.
To render the game, you have been given a Screen
API that handles
command-line rendering. You do not need to understand how the code in Screen
works but you will need to make use of the commands provided. The API is
documented below. Try out the commands to see how they work.
To process keypresses, you will need to load Command
objects into the Screen
API using Screen.addCommand
. This function takes a key
which triggers the
command, a string description
, and an action
callback which is executed
when key
is pressed.
In order to swap items, you will need to add extra cursor controls: one to select an item and one to execute the swap. You can only swap adjacent items.
Bejeweled is a game that requires you to match three of the same item in a row either horizontally or vertically by swapping items. When you do this, the matched items disappear and new items above it fall to fill the gaps.
Example:
๐ฅ ๐ ๐ฅฅ
๐ ๐ ๐
๐ฅ ๐ ๐
Swapping the middle ๐
with the ๐
below it will match three ๐
in a row.
๐ฅ ๐ ๐ฅฅ
๐ฅ ๐ ๐
The ๐
s disappear new items fall in from the top to fill in the blank spots.
๐ฅ ๐ ๐
๐ฅ ๐ ๐ฅฅ
๐ฅ ๐ ๐
In this case, a new ๐ฅ
fell down, triggering a combo.
๐ ๐ ๐
๐ฅฅ ๐ ๐
Again, new items fall in to replace the completed ๐ฅ
s.
๐ ๐ ๐
๐ ๐ ๐ฅฅ
๐ ๐ ๐
There are no more matches, so the player can take their next turn.
- Type
npm install
to install all packages - Run
npm run build
to compile the typescript (ornpm run build:watch
to also watch for changes) - Run
npm start
to run the game - Run
mocha
to run tests
- Implement tests in
test/bejeweled-spec.js
matching the bejeweled game logic - Update tests in
test/cursor-spec.js
to handle selecting and swapping gems - Fill out game logic in
class/bejeweled.js
untilmocha test/bejeweled-spec.js
passes all tests - Update cursor logic in
class/cursor.js
untilmocha test/cursor-spec.js
passes all tests - Use
setBackgroundColor
andresetBackgroundColor
incursor.js
to highlight the cursor's current position on the grid, with a visual signifier when the cursor is in a "swap" state - Create commands in
bejeweled.js
to select gems and execute swaps - Fill out the game state in
bejeweled.js
that checks for match-3s. - Chain the game state to check and alert the player for match combos.
- Implement a score for the player based on matches and combos.
๐ ๐ ๐ ๐ ๐ ๐ ๐
๐ ๐ ๐ฅฅ ๐ ๐ ๐ฅฅ ๐
๐ ๐ ๐ฅ ๐ ๐ฅฅ ๐ ๐ฅฅ
๐ ๐ ๐ ๐ฅ ๐ ๐ ๐
๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐
๐ ๐ ๐ ๐ฅฅ ๐ ๐ฅ ๐ ๐
๐ ๐ ๐ ๐ฅ ๐ ๐ฅฅ ๐ ๐ฅฅ
Run with console debugger and sample data: CONSOLE_VERBOSITY=debug SAMPLE_DATA=true npm start