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
*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