Kyrel is a simple browser-based game for learning about control flow and loops in javascript.
This codebase contains the following methods for traversing / transforming the row:
moveRight();
moveLeft();
useGreen();
useBlue();
draw();
erase();
onGreen();
onBlue();
Write a program which draws a green circle at the end of the row.
function main() {
moveRight();
moveRight();
moveRight();
moveRight();
useGreen();
draw();
}
Fork and git clone
this repo (you now know how to do this!).
There are 3 problem sets:
You will write your code in play.js
:
var initial_state = [ '.', '.', '.', '.', '.' ];
function main(n) {
//////////////////////////////////
//// ////
//// v YOUR CODE BELOW HERE v ////
//// ////
//////////////////////////////////
//////////////////////////////////
//// ////
//// ^ YOUR CODE ABOVE HERE ^ ////
//// ////
//////////////////////////////////
}
-
First, manually configure your
initial_state
to match the start state of the problem you're solvingvar initial_state = ['.', 'b', '.', 'g', '.']
- 'b' means blue
- 'g' mean green
- '.' (dot) means empty
-
Next, use the methods available to you (e.g.
moveRight()
,moveLeft()
, etc.) inside themain
function to get the problem's finish state -
To execute your code in the
main
function, openindex.html
in your browser and press "Play"- Refresh the page whenever you make changes to your JavaScript
- Always have your Chrome Developer Console open (
Cmd
+Opt
+i
) to check for error messages
-
When you've completed a problem, save your work! Create a file that matches your problem name, e.g.
all-blue.js
, and copy-paste yourplay.js
into that new file. Then, go back toplay.js
and clear out yourmain
function, so you can start fresh again.
Adapted from Kyrel.