diff --git a/build.gradle.kts b/build.gradle.kts index e88741e..d1d8c76 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,34 +1,15 @@ -import com.android.build.gradle.internal.tasks.* import korlibs.korge.gradle.* -plugins { - alias(libs.plugins.korge) - -} - +plugins { alias(libs.plugins.korge) } korge { - id = "com.sample.demo" - -// To enable all targets at once - - //targetAll() - -// To enable targets based on properties/environment variables - //targetDefault() - -// To selectively enable targets + id = "de.fsaurenbach.sauronchess" targetJvm() targetJs() serializationJson() jvmMainClassName = "MainKt" - } -dependencies { - add("commonMainApi", project(":deps")) - //add("commonMainApi", project(":korge-dragonbones")) -} -// Jacoco report generation +dependencies { add("commonMainApi", project(":deps")) } diff --git a/src/commonMain/kotlin/Main.kt b/src/commonMain/kotlin/Main.kt index bc9216b..56960f3 100644 --- a/src/commonMain/kotlin/Main.kt +++ b/src/commonMain/kotlin/Main.kt @@ -39,7 +39,6 @@ suspend fun main() = blackKnight = resourcesVfs["b_knight.png"].readBitmap() whiteKing = resourcesVfs["w_king.png"].readBitmap() blackKing = resourcesVfs["b_king.png"].readBitmap() - // Change the scene to the game scene sceneContainer.changeTo { GameScene(sceneContainer) } } @@ -108,7 +107,7 @@ class GameScene(private val cont: SceneContainer) : PixelatedScene(512, 512) { var newPosition: Pair? = null var currentPos: Pair? = null var selectedPiece: Piece? = null - var error = false + var error: Boolean // Function to handle piece movement for (piece in pieces) { diff --git a/src/commonMain/kotlin/Piece.kt b/src/commonMain/kotlin/Piece.kt index 9e0d4d4..d43bb6f 100644 --- a/src/commonMain/kotlin/Piece.kt +++ b/src/commonMain/kotlin/Piece.kt @@ -45,18 +45,26 @@ class Piece( private val cont: SceneContainer, ) : View() { - var pieceKind: PieceKind = kind + private var pieceKind: PieceKind = kind private lateinit var piece: Image var position = board[cx][cy].pos + + + init { if (color == Colors.WHITE) { // If the piece is white, set the piece image to the white pawn or rook or knight piece = Image( - if (kind == PieceKind.WhitePawn) whitePawn!! - else if (kind == PieceKind.WhiteRook) whiteRook!! - else if (kind == PieceKind.WhiteKnight) whiteKnight!! else throw Error("bruh")) + when (kind) { + PieceKind.WhitePawn -> whitePawn!! + PieceKind.WhiteRook -> whiteRook!! + PieceKind.WhiteKnight -> whiteKnight!! + else -> throw Error("Invalid Piece !?") + } + ) + piece.size(Size(64, 64)) piece.addTo(cont) moveTo(cx, cy) @@ -67,8 +75,12 @@ class Piece( kind == PieceKind.BlackKnight) { piece = Image( - if (kind == PieceKind.BlackPawn) blackPawn!! - else if (kind == PieceKind.BlackRook) blackRook!! else blackKnight!!) + when (kind) { + PieceKind.BlackPawn -> blackPawn!! + PieceKind.BlackRook -> blackRook!! + else -> blackKnight!! + } + ) piece.size(Size(64, 64)) piece.addTo(cont) moveTo(cx, cy)