parent
							
								
									d038132055
								
							
						
					
					
						commit
						8581b7ee64
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
					@ -271,7 +271,6 @@ public class Game implements GameSpecification {
 | 
				
			||||||
                currentCarIndex++;
 | 
					                currentCarIndex++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } while (track.getCar(currentCarIndex).isCrashed());
 | 
					        } while (track.getCar(currentCarIndex).isCrashed());
 | 
				
			||||||
        // TODO: evtl andere Kapselung
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -123,7 +123,6 @@ public class Track implements TrackSpecification {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //TODO: THIS
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     *  Determines the finish line and saves it in a list, throws an Exception if none is found.
 | 
					     *  Determines the finish line and saves it in a list, throws an Exception if none is found.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,10 +5,14 @@ import ch.zhaw.pm2.racetrack.PositionVector;
 | 
				
			||||||
import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
 | 
					import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Do not accelerate in any direction.
 | 
					 * This Class represents the DoNotMoveStrategy.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class DoNotMoveStrategy implements MoveStrategy {
 | 
					public class DoNotMoveStrategy implements MoveStrategy {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * This method will be used to return the next Direction for the car.
 | 
				
			||||||
 | 
					     * @return a NONE Direction
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Direction nextMove() {
 | 
					    public Direction nextMove() {
 | 
				
			||||||
        return PositionVector.Direction.NONE;
 | 
					        return PositionVector.Direction.NONE;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,11 @@ import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Scanner;
 | 
					import java.util.Scanner;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This Class represent the MoveListStrategy. The Directions returned by the
 | 
				
			||||||
 | 
					 * nextMove() are written down in a List.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
public class MoveListStrategy implements MoveStrategy {
 | 
					public class MoveListStrategy implements MoveStrategy {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final List<Direction> moveList;
 | 
					    private final List<Direction> moveList;
 | 
				
			||||||
| 
						 | 
					@ -21,6 +26,12 @@ public class MoveListStrategy implements MoveStrategy {
 | 
				
			||||||
        readFile(new File(path));
 | 
					        readFile(new File(path));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * This Method will read in a File and checks line by line if the file contains a valid direction.
 | 
				
			||||||
 | 
					     * If so the direction will be added to the moveList.
 | 
				
			||||||
 | 
					     * @param trackFile the file to read in the directions
 | 
				
			||||||
 | 
					     * @throws FileNotFoundException if the file does not exist.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private void readFile(File trackFile) throws FileNotFoundException {
 | 
					    private void readFile(File trackFile) throws FileNotFoundException {
 | 
				
			||||||
        Scanner scanner = new Scanner(new FileInputStream(trackFile), StandardCharsets.UTF_8);
 | 
					        Scanner scanner = new Scanner(new FileInputStream(trackFile), StandardCharsets.UTF_8);
 | 
				
			||||||
        Direction[] directions = Direction.values();
 | 
					        Direction[] directions = Direction.values();
 | 
				
			||||||
| 
						 | 
					@ -35,6 +46,10 @@ public class MoveListStrategy implements MoveStrategy {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * This method will be used to return the next Direction for the car.
 | 
				
			||||||
 | 
					     * @return the next direction from the list. Returns null if the list is empty.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Direction nextMove() {
 | 
					    public Direction nextMove() {
 | 
				
			||||||
        pointer += 1;
 | 
					        pointer += 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,7 +141,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public PositionVector.Direction nextMove() { //TODO check for crash and recreate movelist if crash
 | 
					    public PositionVector.Direction nextMove() {
 | 
				
			||||||
        pointer += 1;
 | 
					        pointer += 1;
 | 
				
			||||||
        if (pointer < moveList.size()) {
 | 
					        if (pointer < moveList.size()) {
 | 
				
			||||||
            PositionVector.Direction direction = moveList.get(pointer);
 | 
					            PositionVector.Direction direction = moveList.get(pointer);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ import ch.zhaw.pm2.racetrack.UserInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Let the user decide the next move.
 | 
					 * Let the user decide the next move.
 | 
				
			||||||
 | 
					 * Therefore it uses the UserInterface class to ask for a direction.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class UserMoveStrategy implements MoveStrategy {
 | 
					public class UserMoveStrategy implements MoveStrategy {
 | 
				
			||||||
    private final UserInterface userInterface;
 | 
					    private final UserInterface userInterface;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,8 @@
 | 
				
			||||||
package ch.zhaw.pm2.racetrack;
 | 
					package ch.zhaw.pm2.racetrack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ch.zhaw.pm2.racetrack.strategy.UserMoveStrategy;
 | 
					import ch.zhaw.pm2.racetrack.strategy.UserMoveStrategy;
 | 
				
			||||||
import org.junit.jupiter.api.Nested;
 | 
					import org.junit.jupiter.api.*;
 | 
				
			||||||
import org.junit.jupiter.api.DisplayName;
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.BeforeEach;
 | 
					 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					 | 
				
			||||||
import org.junit.jupiter.api.Assertions;
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.FileNotFoundException;
 | 
					import java.io.FileNotFoundException;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
| 
						 | 
					@ -14,7 +11,7 @@ import static ch.zhaw.pm2.racetrack.PositionVector.Direction.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Test for Class Game
 | 
					 * Test for Class Game. The Class is split up in nested classes.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class GameTest {
 | 
					class GameTest {
 | 
				
			||||||
    private UserInterface userInterface;
 | 
					    private UserInterface userInterface;
 | 
				
			||||||
| 
						 | 
					@ -26,7 +23,7 @@ class GameTest {
 | 
				
			||||||
    private final int CAR_INDEX_TWO = 1;
 | 
					    private final int CAR_INDEX_TWO = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This nested Class tests if the game gets initiatet correctly
 | 
					     * This nested Class tests if the game gets initiatet correctly.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nested
 | 
					    @Nested
 | 
				
			||||||
    @DisplayName("Test correct Setup")
 | 
					    @DisplayName("Test correct Setup")
 | 
				
			||||||
| 
						 | 
					@ -124,7 +121,8 @@ class GameTest {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This nested Class tests a Playtrough. And implements a UserInterface interagtion to pretend a real player
 | 
					     * This nested Class tests a playtrough and implements a userInterface which pretends to be a real player.
 | 
				
			||||||
 | 
					     * At the end of every Test the Userinterface stays open for 10 more sec to visualize the game.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nested
 | 
					    @Nested
 | 
				
			||||||
    @DisplayName("Playtrough")
 | 
					    @DisplayName("Playtrough")
 | 
				
			||||||
| 
						 | 
					@ -183,8 +181,28 @@ class GameTest {
 | 
				
			||||||
            Assertions.assertEquals("b",game.gamePhase());
 | 
					            Assertions.assertEquals("b",game.gamePhase());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Test
 | 
				
			||||||
 | 
					        void passFinishLineInWrongDirection() {
 | 
				
			||||||
 | 
					            game = new Game(new interFace("Test",new Integer[]{1,0,1},new PositionVector.Direction[]{LEFT,NONE,NONE,RIGHT,RIGHT}));
 | 
				
			||||||
 | 
					            game.initPhase();
 | 
				
			||||||
 | 
					            Assertions.assertEquals("a",game.gamePhase());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @AfterEach
 | 
				
			||||||
 | 
					        void cleanUp() {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                Thread.sleep(10000);
 | 
				
			||||||
 | 
					            } catch (InterruptedException e) {
 | 
				
			||||||
 | 
					                e.printStackTrace();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * This Class is used to communicate with the UserInterface. It overrides crucial methods and returns an instruction based on the instructions data field.
 | 
				
			||||||
 | 
					     * To implement the right instructions the user has to be aware of the game sequence.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private class interFace extends UserInterface {
 | 
					    private class interFace extends UserInterface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private PositionVector.Direction[] directions;
 | 
					        private PositionVector.Direction[] directions;
 | 
				
			||||||
| 
						 | 
					@ -210,9 +228,6 @@ class GameTest {
 | 
				
			||||||
        public void printInformation(String text) {
 | 
					        public void printInformation(String text) {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void printTrack(Track track) {
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public void quit(String text) {
 | 
					        public void quit(String text) {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue