Game test #29
			
				
			
		
		
		
	| 
						 | 
					@ -1,11 +1,14 @@
 | 
				
			||||||
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.Before;
 | 
				
			||||||
import org.junit.jupiter.api.*;
 | 
					import org.junit.jupiter.api.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static ch.zhaw.pm2.racetrack.Game.NO_WINNER;
 | 
					import static ch.zhaw.pm2.racetrack.Game.NO_WINNER;
 | 
				
			||||||
 | 
					import static ch.zhaw.pm2.racetrack.PositionVector.Direction.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GameTest {
 | 
					class GameTest {
 | 
				
			||||||
    private UserInterface userInterface;
 | 
					    private UserInterface userInterface;
 | 
				
			||||||
| 
						 | 
					@ -83,7 +86,7 @@ class GameTest {
 | 
				
			||||||
        @Test
 | 
					        @Test
 | 
				
			||||||
        void carTurnCorrect() {
 | 
					        void carTurnCorrect() {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                game.doCarTurn(PositionVector.Direction.RIGHT);
 | 
					                game.doCarTurn(RIGHT);
 | 
				
			||||||
                Assertions.assertEquals(new PositionVector(1, 0), game.getCarVelocity(0));
 | 
					                Assertions.assertEquals(new PositionVector(1, 0), game.getCarVelocity(0));
 | 
				
			||||||
            } catch (PositionVectorNotValid positionVectorNotValid) {
 | 
					            } catch (PositionVectorNotValid positionVectorNotValid) {
 | 
				
			||||||
                positionVectorNotValid.printStackTrace();
 | 
					                positionVectorNotValid.printStackTrace();
 | 
				
			||||||
| 
						 | 
					@ -99,6 +102,102 @@ class GameTest {
 | 
				
			||||||
                positionVectorNotValid.printStackTrace();
 | 
					                positionVectorNotValid.printStackTrace();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nested
 | 
				
			||||||
 | 
					    @DisplayName("Playtrough")
 | 
				
			||||||
 | 
					    class Play {
 | 
				
			||||||
 | 
					        private Game game;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Test
 | 
				
			||||||
 | 
					        void winner() {
 | 
				
			||||||
 | 
					            game = new Game(new interFace("Test"));
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                game.initPhase();
 | 
				
			||||||
 | 
					                Assertions.assertEquals('a',game.gamePhase());
 | 
				
			||||||
 | 
					            } catch (InvalidTrackFormatException | PositionVectorNotValid e) {
 | 
				
			||||||
 | 
					                e.printStackTrace();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private class interFace extends UserInterface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private static PositionVector.Direction[] directions = {RIGHT,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            UP,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            UP_LEFT,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            DOWN_LEFT,
 | 
				
			||||||
 | 
					            DOWN_LEFT,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            LEFT,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            DOWN,
 | 
				
			||||||
 | 
					            DOWN,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            DOWN,
 | 
				
			||||||
 | 
					            NONE,
 | 
				
			||||||
 | 
					            UP_RIGHT,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            UP_RIGHT,
 | 
				
			||||||
 | 
					            UP_RIGHT,
 | 
				
			||||||
 | 
					            RIGHT,
 | 
				
			||||||
 | 
					            RIGHT};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private static int pointer = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public interFace(String welcometxt) {
 | 
				
			||||||
 | 
					            super(welcometxt);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public int selectOption(String text, List<String> options) {
 | 
				
			||||||
 | 
					            if (text.equals("Select Track file")) {
 | 
				
			||||||
 | 
					                return 1;
 | 
				
			||||||
 | 
					            } else if (text.contains("Select Strategy for Car")) {
 | 
				
			||||||
 | 
					                return 2;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void printInformation(String text) {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void printTrack(Track track) {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void quit(String text) {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public PositionVector.Direction selectDirection(int playingCarIndex, char playingCarID) {
 | 
				
			||||||
 | 
					            pointer += 1;
 | 
				
			||||||
 | 
					            if(pointer < directions.length) {
 | 
				
			||||||
 | 
					                return directions[pointer];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return NONE;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue