Starting to program a simple game
In the last exercise, you wrote some text. In this exercise, we'll be transforming that text into code.
SpecRunner.html
in your browserplayer
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
GameSpec.js
, write tests that equate to the descriptions you wrote for the moveRight
function.Game.js
, write code for the functions that you are testing. All functions should go in the global scope.moveLeft
, moveDown
, and moveUp
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.
For your visual reference, here is an image of how position will be applied in the game:
Examples of passing and failing tests, respectively: