Currently I'm working on a game like Mau-Mau (card game). The inner workings of the game do their job, just like they should. But for some reason when the player is able to lay several cards the game only detects a mouse click on the first card which can be layed. The mouse clicks are detected like this:
private var screenX = -1
private var screenY = -1
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (button == Input.Buttons.LEFT) {
this.screenX = screenX
this.screenY = screenY
}
return false
}
fun isCardClicked(card: Card): Boolean {
if (card.getSprite().boundingRectangle.contains(screenX.toFloat(), (Gdx.graphics.height - screenY).toFloat())) {
screenX = -1
screenY = -1
return true
}
screenX = -1
screenY = -1
return false
}
The method isCardClicked()
is called in my Game
class:
while (cardIterator.hasNext() && !cardLayed) {
val card = cardIterator.next()
if (player.isPlayable(card, deliCard)) {
if (inputHandler.isCardClicked(card)) {
println("player: $card")
deliStack.take(card)
cardIterator.remove()
cardLayed = true
changeTurns()
}
}
}
Does anybody know why I'm only able to lay the first layable card but not every other layable card in the player hand?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…