Background

In the last exercise, you wrote some text. In this exercise, we'll be transforming that text into code.

Instructions

  1. Download this starter file and unzip it. Take a look around and make sure you understand the file structure. For your reference, here's a diagram of how it's set up:directory structure
  2. To run your tests, open SpecRunner.html in your browser
  3. Note that the teachers have already created a global Object called player that contains the current position as x and y properties. Here's how you'd access them:
    player.x = 0; // sets the player's x posiiton to 0
    player.y = 2; // sets the player's y position to 2
  4. In GameSpec.js, write tests that equate to the descriptions you wrote for the moveRight function.
  5. In Game.js, write code for the functions that you are testing. All functions should go in the global scope.
  6. Repeat the last 2 steps for moveLeft, moveDown, and moveUp

Bonus

What happens when the player goes "out of bounds", or too far forwards/backwards? Add some tests for these cases and write code for the desired behavior.


Diagrams

For your visual reference, here is an image of how position will be applied in the game:coordinate plane

Examples of passing and failing tests, respectively:

passing tests
failing tests