Racetrack

Racetrack is a game based on vector math. I first read about it in a Martin Gardner column in Scientific American magazine a very long time ago. It's simple and easy to play and learn.

This implementation is not very sophisticated, but it was enough to give me several spots I could create themed AngularJS directives for the Packt Publishing course Learning AngularJS Directives.

Links

Credits

Tools Used in the Course

  • Node.js - This is really only used to install and run the next tool. No Node.js code is written or run during the course.
  • Puer - This serves up my HTML/CSS/JavaScript for the demonstration and automatically refreshes the browser each time I save a file.

Exercises

The source code for the course is freely available and after you've gone through the videos you might find yourself wanting to either explore improving the game itself or the directives in some way. In the spirit of that idea, I thought I'd suggest some areas for improvement.

Game Improvements

  • Movement Timer - The game is obviously one which can be planned out many moves in advance if you're willing to make the other player wait for extended periods. In board gaming this is called "analysis paralysis". Put a time limit on how long a user has to pick his or her move and if they fail to do so within the specified period they automatically maintain the same vector for another turn.
  • Take Damage - If a player sends his or her car off the track (inside or outside) or runs into another car, assign damage to the car. If it goes over a set limit that player loses.
  • Purchase Special Moves - Give each player some initial money which can be used to buy damage points and other abilities which can be used during the game (for example, braking, extreme braking, etc.). See below for examples of abilities which could be added and "purchased" for use.
  • Braking - The eight possible next vector choices have the current vector as the top-center choice rather than the center choice. Thus allowing the user to slow down by up to two rather than just one.
  • Extreme Braking - The same as breaking except that the current vector is actually outside of all of the new choices. Thus allowing a user to slow down by three if necessary.
  • Pedal to the Metal - Eight points of movement have the vector point below the bottom center.
  • Accelerate - The same idea as breaking except the current vector is at the bottom center, allowing an acceleration of two instead of just one.
  • Damage Points - Take off points of damage for each car collision with another car or with an out-of-bounds area on the racetrack. Once a user is out of points, they lose the game unless the other player does the same on the same turn.

Program Improvements

  • Reset - Reset the game after a player wins. Note that this implies the game can tell when a player wins, that means you have to track that a player went all the way around a track before crossing the finish line.
  • Internet Games - Utilize a service like Firebase (or another back-end-as-a-service) to store the data for a given game on a remote server and allow players to play over the Internet.
  • Better Movement UI - Instead of clicking buttons to select a new movement vector, Show the available moves on the racetrack and let the user pick a choice there.
  • Track Editing - It would be fun to have different tracks to play on. Provide a simple means (perhaps by clicking dots or drag selecting groups of dots) to mark out a new track. Export the data so it can be embedded into the game or even store designs online.
  • Controls for Special Moves - If you implement any of the new special moves in the game, be sure to implement new directives for each one. It could allow the user to invoke the special move and show how many uses of the special move are left for the current game.