moved files
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package worms.model;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.*;
|
||||
import worms.util.Tuple;
|
||||
import worms.util.IllegalNameException;
|
||||
|
||||
public class Worm {
|
||||
/**
|
||||
@@ -453,7 +455,7 @@ public class Worm {
|
||||
*
|
||||
* @post the worm jumps to his new place. The new place is the x-coordinate plus the jump distance
|
||||
* with the jump velocity
|
||||
* |Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2)
|
||||
* |worms.util.Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2)
|
||||
* @post the current action points schould be 0 after a jump
|
||||
* |this.points = 0
|
||||
* @throws IllegalStateException()
|
||||
|
59
OGP1718-Worms/src/worms/util/IllegalNameException.java
Normal file
59
OGP1718-Worms/src/worms/util/IllegalNameException.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package worms.util;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.*;
|
||||
|
||||
/**
|
||||
* A class for signalling illegal names for worms
|
||||
*
|
||||
* Each illegal name exception involves the name and the index of the character where the error occurred.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Arthur Bols / Leen Dereu
|
||||
*/
|
||||
public class IllegalNameException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Variable registering the index of this illegal name exception
|
||||
*/
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Variable referencing the naem of this illegal name exception
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Initalize this new illegal name exception with given operands
|
||||
*
|
||||
* @param index
|
||||
* The index of the character where the exception occurred.
|
||||
* @param name
|
||||
* The String where the error occurred.
|
||||
*
|
||||
* @post The index of this new illegal name exception is set to the given index
|
||||
* | new.getIndex() == index
|
||||
*
|
||||
* @post The name of this new illegal name exception is set to the given name
|
||||
* | new.getName() == name
|
||||
*/
|
||||
public IllegalNameException(int index, String name) {
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index of this illegal name exception.
|
||||
*/
|
||||
@Basic @Immutable
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of this illegal name exception.
|
||||
*/
|
||||
@Basic @Immutable
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
62
OGP1718-Worms/src/worms/util/Tuple.java
Normal file
62
OGP1718-Worms/src/worms/util/Tuple.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package worms.util;
|
||||
|
||||
import java.util.Objects;
|
||||
import be.kuleuven.cs.som.annotate.*;
|
||||
|
||||
|
||||
/**
|
||||
* A tuple (pair) implementation
|
||||
*
|
||||
* @param <T1> first element type
|
||||
* @param <T2> second element type
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Arthur Bols & Leen Dereu
|
||||
*/
|
||||
@Value
|
||||
public class Tuple<T1, T2> {
|
||||
|
||||
|
||||
public final T1 item1;
|
||||
public final T2 item2;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param item1
|
||||
* The first element for this tuple
|
||||
* @param item2
|
||||
* The second element for this tuple
|
||||
*/
|
||||
private Tuple(T1 item1, T2 item2) {
|
||||
|
||||
if (item1 == null)
|
||||
throw new IllegalArgumentException("item1 may not be null");
|
||||
if (item2 == null)
|
||||
throw new IllegalArgumentException("item2 may not be null");
|
||||
|
||||
this.item1 = item1;
|
||||
this.item2 = item2;
|
||||
}
|
||||
|
||||
@Immutable
|
||||
public static <T1, T2> Tuple<T1, T2> create(T1 item1, T2 item2){
|
||||
return new Tuple<>(item1, item2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Tuple)) return false;
|
||||
Tuple<?, ?> tuple = (Tuple<?, ?>) o;
|
||||
return Objects.equals(item1, tuple.item1) &&
|
||||
Objects.equals(item2, tuple.item2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(item1, item2);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user