Checking who won
In the last exercise, you wrote some functions to control a player. If you weren't able to complete it, don't worry. You can download and unzip the solution.
In this exercise, we'll be adding more complex test cases.
goal
that contains the current position of the goal as x and y properties:
console.log(goal.x); // logs 0
console.log(goal.y); // logs 0
checkWin
that checks whether the player has won. A player has won when the player's x
and y
coordinates match those of the goal.checkWin
should be called whenever moveRight
, moveLeft
, moveDown
, or moveUp
are called.renderWin
. renderWin
should be called if checkWin
finds that the player has won.GameSpec.js
, write tests for the checkWin
function. Remember that you sometimes have to "set the stage" before running the test. You should also be sure to use at least 1 spy.Game.js
, write code for checkWin
.What can you do to improve the game play? Would you randomly set the goal? Would you add an enemy character? How would you test the code? Give it a try!
For your reference, we have provided a basic solution: solution.zip