mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-03-03 16:49:45 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
commit
c931f459af
5
docs/team/referater/referat_12_03_2020.md
Normal file
5
docs/team/referater/referat_12_03_2020.md
Normal file
@ -0,0 +1,5 @@
|
||||
## Oppmøte
|
||||
Alle i teamet var tilstede.
|
||||
|
||||
## Gjennomgått
|
||||
Vi har jobbet med parprogrammering.
|
19
pom.xml
19
pom.xml
@ -20,6 +20,13 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>clojars</id>
|
||||
<url>http://clojars.org/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx -->
|
||||
<dependency>
|
||||
@ -53,6 +60,18 @@
|
||||
<classifier>natives-desktop</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
<version>5.0.0-RC5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>kryonet</groupId>
|
||||
<artifactId>kryonet</artifactId>
|
||||
<version>2.21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -251,7 +251,7 @@ public class Board {
|
||||
* @param position The position to check
|
||||
* @return The robot id of the robot on the position or null if there is no robot there
|
||||
*/
|
||||
private RobotID getRobotOnPosition(Position position) {
|
||||
RobotID getRobotOnPosition(Position position) {
|
||||
for (RobotID robotID : robots.keySet()) {
|
||||
Robot robot = robots.get(robotID);
|
||||
if (position.equals(robot.getPosition())) {
|
||||
@ -266,7 +266,7 @@ public class Board {
|
||||
* @param position The position to check
|
||||
* @return True if there is a robot on the specified position
|
||||
*/
|
||||
private boolean hasRobotOnPosition(Position position) {
|
||||
boolean hasRobotOnPosition(Position position) {
|
||||
return getRobotOnPosition(position) != null;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,9 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
this.cardList = new ArrayList<>(cardList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Randomises the order of the deck
|
||||
*/
|
||||
@Override
|
||||
public void shuffle() {
|
||||
Random randomGenerator = new Random();
|
||||
@ -31,12 +34,21 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws one card from the other deck
|
||||
* @param other The deck to draw the card from
|
||||
*/
|
||||
@Override
|
||||
public void draw(IDeck<T> other) {
|
||||
Deck<T> otherDeck = (Deck<T>) other;
|
||||
cardList.add(otherDeck.cardList.remove(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws multiple cards from the other deck
|
||||
* @param other The other deck to draw from
|
||||
* @param n The number of cards to draw
|
||||
*/
|
||||
@Override
|
||||
public void draw(IDeck<T> other, int n) {
|
||||
Deck<T> otherDeck = (Deck<T>) other;
|
||||
@ -48,27 +60,47 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the entire deck into the other deck
|
||||
* @param other The deck to move this deck's cards into
|
||||
*/
|
||||
@Override
|
||||
public void emptyInto(IDeck<T> other) {
|
||||
Deck<T> otherDeck = (Deck<T>) other;
|
||||
otherDeck.draw(this, this.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the deck is empty
|
||||
* @return Boolean for if the deck is empty
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return cardList.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the deck
|
||||
* @return int size of the deck
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return cardList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all the cards in the deck
|
||||
* @return ArrayList of cards from the deck
|
||||
*/
|
||||
@Override
|
||||
public List<T> getCards() {
|
||||
return new ArrayList<>(cardList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the card from the deck in String format
|
||||
* @return String the cards from the deck
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@ -78,11 +110,19 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks at the top card in the deck
|
||||
* @return ProgrammingCard the first card in the deck
|
||||
*/
|
||||
@Override
|
||||
public T peekTop() {
|
||||
return cardList.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks at the bottom card of the deck
|
||||
* @return ProgrammingCard the last card in the deck
|
||||
*/
|
||||
@Override
|
||||
public T peekBottom() {
|
||||
return cardList.get(size()-1);
|
||||
|
@ -5,6 +5,10 @@ import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This Class represents a player
|
||||
*/
|
||||
|
||||
public class Player {
|
||||
private final RobotID robotID;
|
||||
private final String name;
|
||||
@ -12,11 +16,21 @@ public class Player {
|
||||
private ProgrammingCardDeck playerDeck;
|
||||
private List <ProgrammingCard> program = new ArrayList();
|
||||
|
||||
// Constructor for the player class, it get assigned a Robot, a player nam and a deck
|
||||
/**
|
||||
* Instantiates a new player
|
||||
* @param robotID the global identifier of the robot
|
||||
* @param name the unique name of the player
|
||||
* @param playerDeck the hand of cards dealt to the player
|
||||
*/
|
||||
public Player(RobotID robotID, String name, ProgrammingCardDeck playerDeck) {
|
||||
this.robotID = robotID;
|
||||
this.name = name;
|
||||
this.playerDeck = playerDeck;
|
||||
program.add(0, null); //sets the initial values in program to null
|
||||
program.add(1, null);
|
||||
program.add(2, null);
|
||||
program.add(3, null);
|
||||
program.add(4, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,22 +39,42 @@ public class Player {
|
||||
*/
|
||||
public RobotID getRobotID(){return robotID;}
|
||||
|
||||
/**
|
||||
* Gives you the Name of the player
|
||||
* @return a player Name
|
||||
*/
|
||||
public String getName() {return name;}
|
||||
|
||||
/**
|
||||
* Gives you the players program
|
||||
* @return a list<ProgrammingCard>
|
||||
*/
|
||||
public List<ProgrammingCard> getProgram() {return program;}
|
||||
|
||||
/**
|
||||
* Gives you the player hand/deck
|
||||
* @return a deck
|
||||
*/
|
||||
public ProgrammingCardDeck getPlayerDeck() {return playerDeck;}
|
||||
|
||||
/**
|
||||
* Gives you the players powerdown status
|
||||
* @return a boolean
|
||||
*/
|
||||
public boolean getPowerDownNextRound() { return powerDownNextRound;}
|
||||
|
||||
/**
|
||||
* Sets the prowerdown status
|
||||
* @param powerDownStatus the boolean that determines if it goes to a powerdown or not
|
||||
*/
|
||||
public void setPowerDownNextRound(boolean powerDownStatus) { this.powerDownNextRound = powerDownStatus;}
|
||||
|
||||
/**
|
||||
* Places a card in to the player program
|
||||
* @param card the card that is placed in to the player program
|
||||
*/
|
||||
public void setCardInProgram(ProgrammingCard card) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (program.size() == 0) {
|
||||
program.add(i, card);
|
||||
return;
|
||||
}
|
||||
if (program.get(i) == null) {
|
||||
program.add(i, card);
|
||||
return;
|
||||
@ -49,10 +83,20 @@ public class Player {
|
||||
throw new IllegalArgumentException("Program deck is full,tried to add to many cards");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a card by the given index from the player program and returns it.
|
||||
* @param cardNr the index of the card that is being removed
|
||||
* @return the card that was removed from the program
|
||||
*/
|
||||
public ProgrammingCard removeProgramCard(int cardNr) {
|
||||
if(cardNr<5 && cardNr>-1) {
|
||||
program.add(cardNr, null);
|
||||
return program.remove(cardNr + 1);
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("cant remove more then index 4 or remove negatives");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package inf112.fiasko.roborally.objects;
|
||||
import inf112.fiasko.roborally.element_properties.Action;
|
||||
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 java.io.IOException;
|
||||
@ -141,14 +142,14 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
sleep();
|
||||
switch (action) {
|
||||
case MOVE_1:
|
||||
moveForward(robotID);
|
||||
gameBoard.moveRobotForward(robotID);
|
||||
break;
|
||||
case MOVE_2:
|
||||
moveForward(robotID);
|
||||
gameBoard.moveRobotForward(robotID);
|
||||
moveForward(robotID);
|
||||
break;
|
||||
case MOVE_3:
|
||||
moveForward(robotID);
|
||||
gameBoard.moveRobotForward(robotID);
|
||||
moveForward(robotID);
|
||||
moveForward(robotID);
|
||||
break;
|
||||
@ -182,4 +183,28 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
sleep();
|
||||
gameBoard.moveRobotForward(robotID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates all robots that are standing on cogWheel tiles on the board.
|
||||
* @throws InterruptedException If interrupted while sleeping.
|
||||
*/
|
||||
private void rotateCogwheels() throws InterruptedException {
|
||||
List<BoardElementContainer<Tile>> cogWheelsLeft = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
|
||||
List<BoardElementContainer<Tile>> cogWheelsRight = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT);
|
||||
|
||||
for (BoardElementContainer<Tile> cogLeft : cogWheelsLeft) {
|
||||
if (!gameBoard.hasRobotOnPosition(cogLeft.getPosition())) {
|
||||
return;
|
||||
}
|
||||
sleep();
|
||||
makeMove(gameBoard.getRobotOnPosition(cogLeft.getPosition()), Action.ROTATE_LEFT);
|
||||
}
|
||||
for (BoardElementContainer<Tile> cogRight : cogWheelsRight) {
|
||||
if (!gameBoard.hasRobotOnPosition(cogRight.getPosition())) {
|
||||
return;
|
||||
}
|
||||
sleep();
|
||||
makeMove(gameBoard.getRobotOnPosition(cogRight.getPosition()), Action.ROTATE_RIGHT);
|
||||
}
|
||||
}
|
||||
}
|
@ -40,4 +40,70 @@ public class PlayerTest {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
}
|
||||
@Test
|
||||
public void addMultipuleCards(){
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23452342,Action.MOVE_3));
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction());
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction());
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void addTooManyCardsGetsAError() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523242,Action.MOVE_3));
|
||||
}
|
||||
@Test
|
||||
public void removeCardsFromPlayerProgram() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3));
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction());
|
||||
playerTest.removeProgramCard(4);
|
||||
assertEquals(null,playerTest.getProgram().get(4));
|
||||
}
|
||||
@Test
|
||||
public void removeAllCardsFromPlayerProgram() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3));
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction());
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(3).getAction());
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction());
|
||||
assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction());
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
playerTest.removeProgramCard(4);
|
||||
playerTest.removeProgramCard(3);
|
||||
playerTest.removeProgramCard(2);
|
||||
playerTest.removeProgramCard(1);
|
||||
playerTest.removeProgramCard(0);
|
||||
assertEquals(null,playerTest.getProgram().get(4));
|
||||
assertEquals(null,playerTest.getProgram().get(3));
|
||||
assertEquals(null,playerTest.getProgram().get(2));
|
||||
assertEquals(null,playerTest.getProgram().get(1));
|
||||
assertEquals(null,playerTest.getProgram().get(0));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getErrorIfYouRemoveMoreThenIndexFive(){
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.removeProgramCard(5);
|
||||
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getErrorIfYouRemoveANegativIndex(){
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.removeProgramCard(-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user