mirror of
				https://github.com/inf112-v20/Fiasko.git
				synced 2025-10-31 09:43:45 +01:00 
			
		
		
		
	Merge branch 'master' of https://github.com/inf112-v20/Fiasko
Conflicts: src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
This commit is contained in:
		
							
								
								
									
										11
									
								
								docs/team/referater/referat_24_03_2020.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								docs/team/referater/referat_24_03_2020.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| ## Oppmøte | ||||
| Tilstede: Steinar, Gabriel, Kristian, Torbjørn, Petter | ||||
| Ikke tilstede: | ||||
|  | ||||
| ## Agenda | ||||
| - Oppmøte | ||||
|  | ||||
| - Jobbe videre med oppgavene. | ||||
|  | ||||
| ## Møte | ||||
| Forteller hva som er forventet å bli gjort iløp av dagen og setter i gang med arbeidet. | ||||
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -35,6 +35,12 @@ | ||||
|       <version>1.9.9</version> | ||||
|     </dependency> | ||||
|  | ||||
|     <dependency> | ||||
|       <groupId>com.badlogicgames.gdx</groupId> | ||||
|       <artifactId>gdx-tools</artifactId> | ||||
|       <version>1.9.9</version> | ||||
|     </dependency> | ||||
|  | ||||
|     <dependency> | ||||
|       <groupId>com.badlogicgames.gdx</groupId> | ||||
|       <artifactId>gdx-backend-lwjgl</artifactId> | ||||
|   | ||||
| @@ -2,12 +2,18 @@ package inf112.fiasko.roborally.game_wrapper; | ||||
|  | ||||
| import com.badlogic.gdx.Gdx; | ||||
| import com.badlogic.gdx.InputAdapter; | ||||
| import com.badlogic.gdx.InputMultiplexer; | ||||
| import com.badlogic.gdx.Screen; | ||||
| import com.badlogic.gdx.graphics.GL20; | ||||
| import com.badlogic.gdx.graphics.OrthographicCamera; | ||||
| import com.badlogic.gdx.graphics.g2d.GlyphLayout; | ||||
| import com.badlogic.gdx.graphics.glutils.ShapeRenderer; | ||||
| import com.badlogic.gdx.math.Vector3; | ||||
| import com.badlogic.gdx.scenes.scene2d.InputEvent; | ||||
| import com.badlogic.gdx.scenes.scene2d.InputListener; | ||||
| import com.badlogic.gdx.scenes.scene2d.Stage; | ||||
| import com.badlogic.gdx.scenes.scene2d.Touchable; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||||
| import com.badlogic.gdx.utils.viewport.FitViewport; | ||||
| import com.badlogic.gdx.utils.viewport.Viewport; | ||||
| import inf112.fiasko.roborally.objects.IDeck; | ||||
| @@ -23,6 +29,9 @@ import static com.badlogic.gdx.graphics.Color.GREEN; | ||||
| import static com.badlogic.gdx.graphics.Color.RED; | ||||
| import static com.badlogic.gdx.graphics.Color.WHITE; | ||||
|  | ||||
| /** | ||||
|  * This screen is used to let the user choose their program | ||||
|  */ | ||||
| public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|     private final RoboRallyWrapper roboRallyWrapper; | ||||
|  | ||||
| @@ -32,7 +41,13 @@ public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|     private final Viewport viewport; | ||||
|     private final List<CardRectangle> chosenCards; | ||||
|     private final int maxCards; | ||||
|     private final Stage stage; | ||||
|     final TextButton confirmCards; | ||||
|  | ||||
|     /** | ||||
|      * Initializes a new card choice screen | ||||
|      * @param roboRallyWrapper The robo rally wrapper which is its parent | ||||
|      */ | ||||
|     public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { | ||||
|         this.roboRallyWrapper = roboRallyWrapper; | ||||
|         camera = new OrthographicCamera(); | ||||
| @@ -43,7 +58,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|         cardRectangles = new ArrayList<>(); | ||||
|         shapeRenderer = new ShapeRenderer(); | ||||
|         shapeRenderer.setAutoShapeType(true); | ||||
|         Gdx.input.setInputProcessor(this); | ||||
|  | ||||
|         InputMultiplexer inputMultiplexer = new InputMultiplexer(); | ||||
|         inputMultiplexer.addProcessor(this); | ||||
|  | ||||
|         try { | ||||
|             generateCards(); | ||||
|         } catch (IOException e) { | ||||
| @@ -51,6 +69,26 @@ public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|         } | ||||
|         this.chosenCards = new ArrayList<>(); | ||||
|         this.maxCards = 5; | ||||
|         stage = new Stage(); | ||||
|         inputMultiplexer.addProcessor(stage); | ||||
|  | ||||
|         confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton(); | ||||
|         stage.addActor(confirmCards); | ||||
|         confirmCards.setY(viewport.getWorldHeight() + 60); | ||||
|         confirmCards.setX(15); | ||||
|         confirmCards.setTouchable(Touchable.enabled); | ||||
|         confirmCards.addListener(new InputListener() { | ||||
|             @Override | ||||
|             public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { | ||||
|                 System.out.println(chosenCards.size()); | ||||
|                 System.out.println(maxCards); | ||||
|                 if (chosenCards.size() == maxCards) { | ||||
|                     System.out.println("Lock cards!"); | ||||
|                 } | ||||
|                 return false; | ||||
|             } | ||||
|         }); | ||||
|         Gdx.input.setInputProcessor(inputMultiplexer); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -60,10 +98,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|     private void generateCards() throws IOException { | ||||
|         IDeck<ProgrammingCard> deck = DeckLoaderUtil.loadProgrammingCardsDeck(); | ||||
|         deck.shuffle(); | ||||
|         //Get 16 programming cards | ||||
|         //Get 9 programming cards | ||||
|         List<ProgrammingCard> cardList = deck.getCards().subList(0, 9); | ||||
|         float cardWidth = viewport.getWorldWidth() / 3; | ||||
|         float cardHeight = viewport.getWorldHeight() / 3; | ||||
|         float cardHeight = (viewport.getWorldHeight() - 30) / 3; | ||||
|         for (int i = 0; i < 9; i++) { | ||||
|             int x = (int)(((i % 3)*cardWidth) + 10); | ||||
|             int y = (int)(((i / 3) * cardHeight + 10)); | ||||
| @@ -102,6 +140,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|             shapeRenderer.rect(cardRectangle.rectangle.x, cardRectangle.rectangle.y, | ||||
|                     cardRectangle.rectangle.width, cardRectangle.rectangle.height); | ||||
|         } | ||||
|  | ||||
|         shapeRenderer.end(); | ||||
|         roboRallyWrapper.batch.begin(); | ||||
|         for (CardRectangle cardRectangle : cardRectangles) { | ||||
| @@ -112,6 +151,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen { | ||||
|             drawCardSymbol(cardRectangle); | ||||
|         } | ||||
|         roboRallyWrapper.batch.end(); | ||||
|         stage.draw(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -0,0 +1,37 @@ | ||||
| package inf112.fiasko.roborally.game_wrapper; | ||||
|  | ||||
| import com.badlogic.gdx.Gdx; | ||||
| import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||||
| import com.badlogic.gdx.graphics.g2d.TextureAtlas; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Skin; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||||
|  | ||||
| /** | ||||
|  * This class generates a simple text button using a default skin | ||||
|  */ | ||||
| public class SimpleButton { | ||||
|     private TextButton button; | ||||
|  | ||||
|     /** | ||||
|      * Instantiates a new simple button | ||||
|      * @param text The text to display on the button | ||||
|      * @param font The font to use to draw button text | ||||
|      */ | ||||
|     public SimpleButton(String text, BitmapFont font) { | ||||
|         TextureAtlas buttonAtlas = new TextureAtlas(Gdx.files.internal("uiskin.atlas")); | ||||
|         Skin skin = new Skin(buttonAtlas); | ||||
|         TextButton.TextButtonStyle confirmCardsStyle = new TextButton.TextButtonStyle(); | ||||
|         confirmCardsStyle.font = font; | ||||
|         confirmCardsStyle.up = skin.getDrawable("default-round"); | ||||
|         confirmCardsStyle.down = skin.getDrawable("default-round-down"); | ||||
|         this.button = new TextButton(text, confirmCardsStyle); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Gets the button generated | ||||
|      * @return A button | ||||
|      */ | ||||
|     public TextButton getButton() { | ||||
|         return this.button; | ||||
|     } | ||||
| } | ||||
| @@ -538,7 +538,6 @@ public class Board { | ||||
|      */ | ||||
|     private void updateLaserDisplay(List<Position> laserTargets, Direction laserDirection, WallType laserType) { | ||||
|         for (Position laserTarget : laserTargets) { | ||||
|             System.out.println(laserTarget); | ||||
|             updateLaserBeamOnParticleGrid(laserTarget, laserDirection, laserType); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -43,6 +43,6 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> { | ||||
|  | ||||
|     @Override | ||||
|     public int compareTo(ProgrammingCard programmingCard) { | ||||
|         return this.cardPriority - programmingCard.cardPriority; | ||||
|         return programmingCard.cardPriority - this.cardPriority; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import inf112.fiasko.roborally.element_properties.Position; | ||||
| import inf112.fiasko.roborally.element_properties.RobotID; | ||||
| import inf112.fiasko.roborally.element_properties.TileType; | ||||
| import inf112.fiasko.roborally.utility.BoardLoaderUtil; | ||||
| import inf112.fiasko.roborally.utility.DeckLoaderUtil; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.util.ArrayList; | ||||
| @@ -22,6 +23,7 @@ public class RoboRallyGame implements IDrawableGame { | ||||
|     private List<BoardElementContainer<Tile>> cogwheels; | ||||
|     private List<BoardElementContainer<Tile>> conveyorBelts; | ||||
|     private List<BoardElementContainer<Tile>> fastConveyorBelts; | ||||
|     private List<Player> playerList; | ||||
|  | ||||
|     public RoboRallyGame(boolean debug) { | ||||
|         if (debug) { | ||||
| @@ -107,6 +109,26 @@ public class RoboRallyGame implements IDrawableGame { | ||||
|             robots.add(new Robot(RobotID.ROBOT_6, new Position(7, 7))); | ||||
|             robots.add(new Robot(RobotID.ROBOT_7, new Position(6, 7))); | ||||
|             robots.add(new Robot(RobotID.ROBOT_8, new Position(6, 8))); | ||||
|             playerList = new ArrayList<>(); | ||||
|             playerList.add(new Player(RobotID.ROBOT_1, "Player1")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_2, "Player2")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_3, "Player3")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_4, "Player4")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_5, "Player5")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_6, "Player6")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_7, "Player7")); | ||||
|             playerList.add(new Player(RobotID.ROBOT_8, "Player8")); | ||||
|             Deck<ProgrammingCard> cards =  DeckLoaderUtil.loadProgrammingCardsDeck(); | ||||
|             for (Player player : playerList) { | ||||
|                 cards.shuffle(); | ||||
|                 List<ProgrammingCard> testProgram = new ArrayList<>(); | ||||
|                 for (int i = 0; i < 5; i++) { | ||||
|                     cards.shuffle(); | ||||
|                     testProgram.add(cards.peekTop()); | ||||
|                 } | ||||
|                 player.setInProgram(testProgram); | ||||
|             } | ||||
|  | ||||
|             gameBoard = BoardLoaderUtil.loadBoard("boards/Dizzy_Dash.txt", robots); | ||||
|             cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT, | ||||
|                     TileType.COGWHEEL_LEFT); | ||||
| @@ -141,33 +163,26 @@ public class RoboRallyGame implements IDrawableGame { | ||||
|      */ | ||||
|     private void runGameLoop() throws InterruptedException { | ||||
|         TimeUnit.SECONDS.sleep(3); | ||||
|         makeMove(RobotID.ROBOT_1, Action.MOVE_1); | ||||
|         makeMove(RobotID.ROBOT_1, Action.MOVE_2); | ||||
|         fireAllLasers(); | ||||
|         makeMove(RobotID.ROBOT_1, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_1, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_1, Action.MOVE_3); | ||||
|         makeMove(RobotID.ROBOT_1, Action.ROTATE_LEFT); | ||||
|         makeMove(RobotID.ROBOT_1, Action.U_TURN); | ||||
|         makeMove(RobotID.ROBOT_1, Action.ROTATE_RIGHT); | ||||
|         makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT); | ||||
|         makeMove(RobotID.ROBOT_2, Action.MOVE_3); | ||||
|         makeMove(RobotID.ROBOT_2, Action.MOVE_3); | ||||
|         makeMove(RobotID.ROBOT_2, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_2, Action.U_TURN); | ||||
|         makeMove(RobotID.ROBOT_2, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_2, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_2, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_2, Action.MOVE_3); | ||||
|         makeMove(RobotID.ROBOT_2, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_2, Action.BACK_UP); | ||||
|         makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT); | ||||
|         makeMove(RobotID.ROBOT_2, Action.U_TURN); | ||||
|         makeMove(RobotID.ROBOT_2, Action.MOVE_1); | ||||
|         runPhase(1); | ||||
|         runPhase(2); | ||||
|         runPhase(3); | ||||
|         runPhase(4); | ||||
|         runPhase(5); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Runs one phase as defined in the Robo Rally rulebook | ||||
|      * @param phaseNumber The number of the phase to run | ||||
|      * @throws InterruptedException If interrupted wile trying to sleep | ||||
|      */ | ||||
|     private void runPhase(int phaseNumber) throws InterruptedException { | ||||
|         runProgramCards(phaseNumber); | ||||
|  | ||||
|         moveAllConveyorBelts(); | ||||
|         checkAllFlags(); | ||||
|         rotateCogwheels(); | ||||
|         makeMove(RobotID.ROBOT_7, Action.MOVE_1); | ||||
|  | ||||
|         fireAllLasers(); | ||||
|         checkAllFlags(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -474,4 +489,30 @@ public class RoboRallyGame implements IDrawableGame { | ||||
|         sleep(); | ||||
|         gameBoard.doLaserCleanup(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Runs all programming cards for a phase | ||||
|      * @param phase The number of the phase to run cards for | ||||
|      * @throws InterruptedException If it gets interrupted while trying to sleep | ||||
|      */ | ||||
|     private void runProgramCards(int phase) throws InterruptedException { | ||||
|         List<RobotID> robotsToDoAction = new ArrayList<>(); | ||||
|         List<ProgrammingCard> programToBeRun = new ArrayList<>(); | ||||
|         List<Integer> originalPriority = new ArrayList<>(); | ||||
|         for (Player player : playerList) { | ||||
|             List<ProgrammingCard> playerProgram = player.getProgram(); | ||||
|             if (!playerProgram.isEmpty()) { | ||||
|                 ProgrammingCard programmingCard = playerProgram.get(phase); | ||||
|                 originalPriority.add(programmingCard.getPriority()); | ||||
|                 robotsToDoAction.add(player.getRobotID()); | ||||
|                 programToBeRun.add(programmingCard); | ||||
|             } | ||||
|         } | ||||
|         Collections.sort(programToBeRun); | ||||
|         for (ProgrammingCard card : programToBeRun) { | ||||
|             int i = originalPriority.indexOf(card.getPriority()); | ||||
|             RobotID robot = robotsToDoAction.get(i); | ||||
|             makeMove(robot, card.getAction()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 GabrielMagnus
					GabrielMagnus