package ch.zhaw.pm2.racetrack; import ch.zhaw.pm2.racetrack.given.GameSpecification; import java.util.List; import static ch.zhaw.pm2.racetrack.PositionVector.Direction; /** * Game controller class, performing all actions to modify the game state. * It contains the logic to move the cars, detect if they are crashed * and if we have a winner. */ public class Game implements GameSpecification { public static final int NO_WINNER = -1; /** * Return the index of the current active car. * Car indexes are zero-based, so the first car is 0, and the last car is getCarCount() - 1. * @return The zero-based number of the current car */ @Override public int getCurrentCarIndex() { // TODO: implementation throw new UnsupportedOperationException(); } /** * Get the id of the specified car. * @param carIndex The zero-based carIndex number * @return A char containing the id of the car */ @Override public char getCarId(int carIndex) { // TODO: implementation throw new UnsupportedOperationException(); } /** * Get the position of the specified car. * @param carIndex The zero-based carIndex number * @return A PositionVector containing the car's current position */ @Override public PositionVector getCarPosition(int carIndex) { // TODO: implementation throw new UnsupportedOperationException(); } /** * Get the velocity of the specified car. * @param carIndex The zero-based carIndex number * @return A PositionVector containing the car's current velocity */ @Override public PositionVector getCarVelocity(int carIndex) { // TODO: implementation throw new UnsupportedOperationException(); } /** * Return the winner of the game. If the game is still in progress, returns NO_WINNER. * @return The winning car's index (zero-based, see getCurrentCar()), or NO_WINNER if the game is still in progress */ @Override public int getWinner() { // TODO: implementation throw new UnsupportedOperationException(); } /** * Execute the next turn for the current active car. *

This method changes the current car's velocity and checks on the path to the next position, * if it crashes (car state to crashed) or passes the finish line in the right direction (set winner state).

*

The steps are as follows

*
    *
  1. Accelerate the current car
  2. *
  3. Calculate the path from current (start) to next (end) position * (see {@link Game#calculatePath(PositionVector, PositionVector)})
  4. *
  5. Verify for each step what space type it hits: * *
  6. *
  7. If the car crashed or wins, set its position to the crash/win coordinates
  8. *
  9. If the car crashed, also detect if there is only one car remaining, remaining car is the winner
  10. *
  11. Otherwise move the car to the end position
  12. *
*

The calling method must check the winner state and decide how to go on. If the winner is different * than {@link Game#NO_WINNER}, or the current car is already marked as crashed the method returns immediately.

* * @param acceleration A Direction containing the current cars acceleration vector (-1,0,1) in x and y direction * for this turn */ @Override public void doCarTurn(Direction acceleration) { // TODO: implementation throw new UnsupportedOperationException(); } /** * Switches to the next car who is still in the game. Skips crashed cars. */ @Override public void switchToNextActiveCar() { // TODO: implementation throw new UnsupportedOperationException(); } /** * Returns all of the grid positions in the path between two positions, for use in determining line of sight. * Determine the 'pixels/positions' on a raster/grid using Bresenham's line algorithm. * (https://de.wikipedia.org/wiki/Bresenham-Algorithmus) * Basic steps are * - Detect which axis of the distance vector is longer (faster movement) * - for each pixel on the 'faster' axis calculate the position on the 'slower' axis. * Direction of the movement has to correctly considered * @param startPosition Starting position as a PositionVector * @param endPosition Ending position as a PositionVector * @return Intervening grid positions as a List of PositionVector's, including the starting and ending positions. */ @Override public List calculatePath(PositionVector startPosition, PositionVector endPosition) { // TODO: implementation throw new UnsupportedOperationException(); } /** * Does indicate if a car would have a crash with a WALL space or another car at the given position. * @param carIndex The zero-based carIndex number * @param position A PositionVector of the possible crash position * @return A boolean indicator if the car would crash with a WALL or another car. */ @Override public boolean willCarCrash(int carIndex, PositionVector position) { // TODO: implementation throw new UnsupportedOperationException(); } }