mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-27 18:55:55 +00:00
Clean up unused code
This commit is contained in:
parent
672be521d7
commit
4dd3d872a2
@ -82,17 +82,22 @@ public abstract class Rail {
|
|||||||
public abstract Vector2D getDirectionFrom(Vector2D position);
|
public abstract Vector2D getDirectionFrom(Vector2D position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a train can be placed on this rail in the specified direction.
|
* Check whether a train can be placed on this rail facing the specified direction.
|
||||||
|
*
|
||||||
|
* @param position train front position
|
||||||
|
* @param direction the normalized direction vector to check
|
||||||
|
* @return whether a train can be placed on this rail facing that direction
|
||||||
|
*/
|
||||||
|
public abstract boolean allowsPlacement(Vector2D position, Vector2D direction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a train can be move on this rail in the specified direction.
|
||||||
*
|
*
|
||||||
* @param position start position
|
* @param position start position
|
||||||
* @param direction the normalized direction vector to check
|
* @param direction the normalized direction vector to check
|
||||||
* @return whether a train can be placed on this rail in that direction
|
* @return whether a train can move on this rail in the direction
|
||||||
*/
|
*/
|
||||||
public abstract boolean allowsDirectionFrom(Vector2D position, Vector2D direction);
|
public abstract boolean allowsMovement(Vector2D position, Vector2D direction);
|
||||||
|
|
||||||
public abstract boolean allowsPlacementInDirection(Vector2D position, Vector2D direction);
|
|
||||||
|
|
||||||
public abstract boolean allowsMovementInDirection(Vector2D position, Vector2D direction);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a position along this rail in the specified direction for the specified amount of steps. This method will
|
* Move a position along this rail in the specified direction for the specified amount of steps. This method will
|
||||||
|
@ -100,47 +100,14 @@ public final class Switch extends Rail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowsDirectionFrom(Vector2D position, Vector2D direction) {
|
public boolean allowsPlacement(Vector2D position, Vector2D direction) {
|
||||||
/*
|
return selection.allowsPlacement(position, direction);
|
||||||
if (positionOne.connectsTo(position) && positionTwo.connectsTo(position)) {
|
|
||||||
// trying to connect to start position
|
|
||||||
final boolean a = selection.allowsDirectionFrom(position, direction);
|
|
||||||
final boolean b = (selection == positionOne && positionTwo.allowsDirectionFrom(position, direction.negated()));
|
|
||||||
final boolean c = (selection == positionTwo && positionOne.allowsDirectionFrom(position, direction.negated()));
|
|
||||||
return a || b || c;
|
|
||||||
} else {
|
|
||||||
return selection.allowsDirectionFrom(position, direction);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
if (selection != null) {
|
|
||||||
if (positionOne.connectsTo(position) && positionTwo.connectsTo(position)) {
|
|
||||||
return positionOne.allowsDirectionFrom(position, direction)
|
|
||||||
|| positionTwo.allowsDirectionFrom(position, direction)
|
|
||||||
|| selection.allowsDirectionFrom(position, direction.negated());
|
|
||||||
}
|
|
||||||
return selection.allowsDirectionFrom(position, direction)
|
|
||||||
|| selection.allowsDirectionFrom(position, direction.negated());
|
|
||||||
} else {
|
|
||||||
return (positionOne.connectsTo(position) && positionOne.allowsDirectionFrom(position, direction))
|
|
||||||
|| (positionTwo.connectsTo(position) && positionTwo.allowsDirectionFrom(position, direction));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return (selection != null && selection.contains(position))
|
|
||||||
|| (positionOne.connectsTo(position) && positionOne.allowsDirectionFrom(position, direction))
|
|
||||||
|| (positionTwo.connectsTo(position) && positionTwo.allowsDirectionFrom(position, direction));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowsPlacementInDirection(Vector2D position, Vector2D direction) {
|
public boolean allowsMovement(Vector2D position, Vector2D direction) {
|
||||||
return selection.allowsPlacementInDirection(position, direction);
|
return positionOne.allowsMovement(position, direction)
|
||||||
}
|
|| positionTwo.allowsMovement(position, direction);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowsMovementInDirection(Vector2D position, Vector2D direction) {
|
|
||||||
return positionOne.allowsMovementInDirection(position, direction)
|
|
||||||
|| positionTwo.allowsMovementInDirection(position, direction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,23 +109,13 @@ public final class Track extends Rail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowsDirectionFrom(Vector2D position, Vector2D direction) {
|
public boolean allowsPlacement(Vector2D position, Vector2D direction) {
|
||||||
if (connectsTo(position)) {
|
|
||||||
return getDirectionFrom(position).negated().equals(direction);
|
|
||||||
} else if (contains(position)) {
|
|
||||||
return getDirectionFrom(position).isParallelTo(direction);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowsPlacementInDirection(Vector2D position, Vector2D direction) {
|
|
||||||
return contains(position) && getDirectionFrom(position).isParallelTo(direction)
|
return contains(position) && getDirectionFrom(position).isParallelTo(direction)
|
||||||
|| connectsTo(position) && getDirectionFrom(position).negated().equals(direction);
|
|| connectsTo(position) && getDirectionFrom(position).negated().equals(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowsMovementInDirection(Vector2D position, Vector2D direction) {
|
public boolean allowsMovement(Vector2D position, Vector2D direction) {
|
||||||
return contains(position) && getDirectionFrom(position).isParallelTo(direction)
|
return contains(position) && getDirectionFrom(position).isParallelTo(direction)
|
||||||
|| connectsTo(position) && getDirectionFrom(position).equals(direction);
|
|| connectsTo(position) && getDirectionFrom(position).equals(direction);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package edu.kit.informatik.model;
|
|||||||
import edu.kit.informatik.ui.InvalidInputException;
|
import edu.kit.informatik.ui.InvalidInputException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -158,20 +157,20 @@ public final class Train {
|
|||||||
final Rail[] touchingRails = railNetwork.findTouchingRails(position);
|
final Rail[] touchingRails = railNetwork.findTouchingRails(position);
|
||||||
if (touchingRails.length == 0) {
|
if (touchingRails.length == 0) {
|
||||||
if (!railNetwork.findContainingRail(position)
|
if (!railNetwork.findContainingRail(position)
|
||||||
.map(rail -> rail.allowsPlacementInDirection(position, direction))
|
.map(rail -> rail.allowsPlacement(position, direction))
|
||||||
.orElse(false)) {
|
.orElse(false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (touchingRails.length == 1) {
|
} else if (touchingRails.length == 1) {
|
||||||
if (!(touchingRails[0].allowsPlacementInDirection(position, direction)
|
if (!(touchingRails[0].allowsPlacement(position, direction)
|
||||||
|| touchingRails[0].allowsMovementInDirection(position, direction))) {
|
|| touchingRails[0].allowsMovement(position, direction))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (touchingRails.length == 2
|
} else if (touchingRails.length == 2
|
||||||
&& !touchingRails[0].allowsPlacementInDirection(position, direction)
|
&& !touchingRails[0].allowsPlacement(position, direction)
|
||||||
&& !touchingRails[1].allowsPlacementInDirection(position, direction)
|
&& !touchingRails[1].allowsPlacement(position, direction)
|
||||||
&& !(touchingRails[0].allowsMovementInDirection(position, direction)
|
&& !(touchingRails[0].allowsMovement(position, direction)
|
||||||
|| touchingRails[1].allowsMovementInDirection(position, direction))) {
|
|| touchingRails[1].allowsMovement(position, direction))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Set<Rail> occupiedRailsSet = new HashSet<>();
|
final Set<Rail> occupiedRailsSet = new HashSet<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user