Skip to content

Commit

Permalink
#14
Browse files Browse the repository at this point in the history
  • Loading branch information
FSaurenbach committed Mar 14, 2024
1 parent 6bd8e68 commit 367878e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
25 changes: 3 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")) }
3 changes: 1 addition & 2 deletions src/commonMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down Expand Up @@ -108,7 +107,7 @@ class GameScene(private val cont: SceneContainer) : PixelatedScene(512, 512) {
var newPosition: Pair<Int, Int>? = null
var currentPos: Pair<Int, Int>? = null
var selectedPiece: Piece? = null
var error = false
var error: Boolean

// Function to handle piece movement
for (piece in pieces) {
Expand Down
24 changes: 18 additions & 6 deletions src/commonMain/kotlin/Piece.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 367878e

Please sign in to comment.