Checking who won
In the last exercise, you wrote some functions to move 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.
goalthat contains the current position of the goal as x and y properties:
console.log(goal.x); // logs 0 console.log(goal.y); // logs 0
checkWinthat checks whether the player has won. A player has won when the player's
ycoordinates match those of the goal.
renderWinshould be called whenever
GameSpec.js, write tests for the
checkWinfunction. 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
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