solitare/qml/ThrowawayPile.qml

34 lines
1.1 KiB
QML
Raw Normal View History

2024-12-04 18:20:06 +00:00
import QtQuick
2024-12-05 00:22:18 +00:00
import Solitare
2024-12-04 18:20:06 +00:00
// The throwaway pile (shows last 3 cards)
Row {
// This allows makes the cards overlap
spacing: -60
Repeater {
model: Math.min(GameState.throwawayPile.length, 3)
2024-12-05 02:24:09 +00:00
2024-12-05 00:22:18 +00:00
delegate: CardModel {
2024-12-04 18:20:06 +00:00
required property int index // passed from repeater
2024-12-05 00:22:18 +00:00
property int reversedIndex: Math.min(GameState.throwawayPile.length, 3) - 1 - index
2024-12-05 02:24:09 +00:00
2024-12-04 18:20:06 +00:00
card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - reversedIndex]
isFaceDown: false
onClicked: {
// Only auto-move the last card in the throwaway pile
// cards below it are shown, but shouldn't have a click effect
2024-12-06 03:55:48 +00:00
if (reversedIndex == 0) {
if (GameState.autoMoveThrownCard()) {
if (GameState.isWinnable()) {
console.log("Still winnable")
} else {
console.log("Game is lost")
}
}
}
2024-12-04 18:20:06 +00:00
}
}
}
}