Skip to content

Commit

Permalink
feat(plugin24): make some actions Addable
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Oct 2, 2023
1 parent eb47f0b commit f13dedd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ The version should always be in sync with the [GUI](https://github.com/software-
A `y` version of 0 marks the beta of the current year
and likely contains breaking changes between patches.

### 24.2.X - 2023-10-XX
- Crash oversped ships
### 24.2.0 - 2023-10-XX
- Disqualify oversped ship
- Allow other player to move on when one is disqualified
- Grey out winning ship so second player can follow

### 24.1.2 Stable Release - 2023-09-20

Expand Down
4 changes: 4 additions & 0 deletions plugin/src/main/kotlin/sc/plugin2024/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ import sc.shared.IMoveMistake
interface Action {
fun perform(state: GameState): IMoveMistake?
}

interface Addable<T> {
operator fun plus(other: T): T
}
4 changes: 3 additions & 1 deletion plugin/src/main/kotlin/sc/plugin2024/actions/Accelerate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class Accelerate(
* Darf nicht 0 sein.
*/
@XStreamAsAttribute val acc: Int,
): Action {
): Action, Addable<Accelerate> {

/**
*
Expand Down Expand Up @@ -68,4 +68,6 @@ data class Accelerate(
}

override fun toString(): String = "Beschleunige um $acc"

override fun plus(other: Accelerate): Accelerate = Accelerate(acc + other.acc)
}
9 changes: 3 additions & 6 deletions plugin/src/main/kotlin/sc/plugin2024/actions/Advance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package sc.plugin2024.actions
import com.thoughtworks.xstream.annotations.XStreamAlias
import com.thoughtworks.xstream.annotations.XStreamAsAttribute
import sc.api.plugins.CubeDirection
import sc.plugin2024.Action
import sc.plugin2024.Field
import sc.plugin2024.GameState
import sc.plugin2024.Ship
import sc.plugin2024.*
import sc.plugin2024.mistake.AdvanceProblem
import sc.plugin2024.util.PluginConstants
import kotlin.math.absoluteValue
Expand All @@ -30,7 +27,7 @@ import kotlin.math.absoluteValue
data class Advance(
/** Anzahl der Felder, die zurückgelegt werden. */
@XStreamAsAttribute val distance: Int,
): Action {
): Action, Addable<Advance> {

override fun perform(state: GameState): AdvanceProblem? {
if(distance < PluginConstants.MIN_SPEED &&
Expand All @@ -51,5 +48,5 @@ data class Advance(

override fun toString(): String = if(distance >= 0) "Gehe $distance Felder vor" else "Gehe $distance Felder zurück"

operator fun plus(other: Advance) = Advance(distance + other.distance)
override operator fun plus(other: Advance) = Advance(distance + other.distance)
}

0 comments on commit f13dedd

Please sign in to comment.