Background

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.

Instructions

  1. There will be a global Object called 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
  2. There should be a function called 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.
  3. The teachers have written a function called renderWin. renderWin should be called whenever checkWinis.
  4. In 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.
  5. In Game.js, write code for checkWin.

Bonus

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!


Solution

For your reference, we have provided a basic solution: solution.zip