mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
commit
7b0dba3837
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.*;
|
||||
@ -115,6 +116,17 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
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);
|
||||
@ -149,33 +161,11 @@ 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);
|
||||
moveAllConveyorBelts();
|
||||
checkAllFlags();
|
||||
rotateCogwheels();
|
||||
makeMove(RobotID.ROBOT_7, Action.MOVE_1);
|
||||
runPhase(1);
|
||||
runPhase(2);
|
||||
runPhase(3);
|
||||
runPhase(4);
|
||||
runPhase(5);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -407,21 +397,26 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
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) {
|
||||
for (Player player : playerList) {
|
||||
List<ProgrammingCard> playerProgram = player.getProgram();
|
||||
if (!playerProgram.isEmpty()) {
|
||||
originalPriority.add(playerProgram.get(phase).getPriority());
|
||||
ProgrammingCard programmingCard = playerProgram.get(phase);
|
||||
originalPriority.add(programmingCard.getPriority());
|
||||
robotsToDoAction.add(player.getRobotID());
|
||||
programToBeRun.add(playerProgram.get(phase));
|
||||
programToBeRun.add(programmingCard);
|
||||
}
|
||||
}
|
||||
Collections.sort(programToBeRun);
|
||||
for (ProgrammingCard card:programToBeRun) {
|
||||
for (ProgrammingCard card : programToBeRun) {
|
||||
int i = originalPriority.indexOf(card.getPriority());
|
||||
RobotID robot = robotsToDoAction.get(i);
|
||||
makeMove(robot, card.getAction());
|
||||
|
Loading…
x
Reference in New Issue
Block a user