1
1
Fork 0

Rename: mobile/preventMovement -> sharesCell

This commit is contained in:
Svetlana Isakova 2019-08-03 22:28:04 +02:00
parent 727f6e47e7
commit b0843b287f
6 changed files with 14 additions and 14 deletions

View File

@ -6,7 +6,7 @@ interface Position
interface GameElement {
val symbol: Char
val mobile: Boolean
val sharesCell: Boolean
fun interact(
maze: Maze,
sameCellElements: Set<GameElement>
@ -14,7 +14,7 @@ interface GameElement {
}
abstract class StaticElement(
override val mobile: Boolean // [1]
override val sharesCell: Boolean // [1]
): GameElement {
override fun interact(
maze: Maze,
@ -25,7 +25,7 @@ abstract class StaticElement(
}
class Wall:
StaticElement(mobile = false) { // [2]
StaticElement(sharesCell = false) { // [2]
override val symbol: Char
get() = '#' // [3]
get() = '#' // [3]
}

View File

@ -2,7 +2,7 @@
package gameelements
abstract class MobileElement: GameElement {
override val mobile: Boolean
override val sharesCell: Boolean
get() = true
abstract fun move( // [1]
currentPosition: Position,

View File

@ -2,14 +2,14 @@ package abstractClasses1
interface GameElement {
val symbol: Char
val preventMovement: Boolean
val sharesCell: Boolean
fun interact(maze: Maze, sameCellElements: Set<GameElement>)
}
open class ImmovableElement(
override val symbol: Char,
override val preventMovement: Boolean
override val sharesCell: Boolean
) : GameElement {
override fun interact(maze: Maze, sameCellElements: Set<GameElement>) {
// Default implementation: do nothing
@ -18,9 +18,9 @@ open class ImmovableElement(
override fun toString() = symbol.toString()
}
class Wall : ImmovableElement('#', preventMovement = true)
class Wall : ImmovableElement('#', sharesCell = false)
class Food : ImmovableElement('.', preventMovement = false)
class Food : ImmovableElement('.', sharesCell = true)
fun createGameElement(char: Char?): GameElement? = when (char) {
'#' -> Wall()

View File

@ -106,5 +106,5 @@ fun Maze.isPassable(position: Position): Boolean {
return false
}
val elementsAtNewPosition = allAt(position)
return elementsAtNewPosition.none { it.preventMovement }
return elementsAtNewPosition.none { it.sharesCell }
}

View File

@ -4,11 +4,11 @@ import abstractClasses1.Move.*
abstract class MovableElement : GameElement {
override val preventMovement: Boolean get() = false
override val sharesCell: Boolean get() = false
abstract fun makeMove(currentPosition: Position, maze: Maze): Position
abstract fun makeMove(currentPosition: Position, maze: Maze): Position
override fun toString() = symbol.toString()
override fun toString() = symbol.toString()
}
enum class Move {

View File

@ -4,7 +4,7 @@ files:
visible: true
placeholders:
- offset: 590
length: 388
length: 394
placeholder_text: TODO()
- name: src/GameMatrix.kt
visible: true