2024-12-04 18:15:50 +00:00
|
|
|
import QtQuick
|
2024-12-05 00:22:18 +00:00
|
|
|
import Solitare
|
2024-12-04 18:15:50 +00:00
|
|
|
|
|
|
|
// In solitare, Tableau refers to the part of the board where all of the columns are placed
|
|
|
|
Row {
|
2024-12-07 22:49:38 +00:00
|
|
|
id: tableau
|
2024-12-08 10:41:28 +00:00
|
|
|
|
|
|
|
required property real cardWidth
|
|
|
|
required property real cardHeight
|
|
|
|
|
|
|
|
spacing: cardWidth * 0.125
|
2024-12-04 18:15:50 +00:00
|
|
|
|
|
|
|
Repeater {
|
2024-12-07 22:49:38 +00:00
|
|
|
id: colRepeater
|
2024-12-04 18:15:50 +00:00
|
|
|
model: GameState.columns.length
|
|
|
|
|
|
|
|
delegate: Column {
|
|
|
|
required property int index // passed from repeater
|
2024-12-05 02:24:09 +00:00
|
|
|
|
2024-12-08 10:41:28 +00:00
|
|
|
spacing: -tableau.cardHeight * 0.8 // Overlap
|
2024-12-04 18:15:50 +00:00
|
|
|
|
|
|
|
Repeater {
|
2024-12-07 22:49:38 +00:00
|
|
|
id: slotRepeater
|
2024-12-05 00:22:18 +00:00
|
|
|
model: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index].length : 1 // Render an empty slot for an empty column
|
2024-12-05 02:24:09 +00:00
|
|
|
|
2024-12-07 22:49:38 +00:00
|
|
|
delegate: ColumnSlotModel {
|
|
|
|
required property int index // passed from repeater
|
|
|
|
cardId: index
|
|
|
|
columnId: parent.index // this is actually passed from the Column, not the Repeater
|
2024-12-08 10:41:28 +00:00
|
|
|
|
|
|
|
width: tableau.cardWidth
|
|
|
|
height: tableau.cardHeight
|
2024-12-07 22:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
component ColumnSlotModel: Item {
|
|
|
|
required property int columnId
|
|
|
|
required property int cardId
|
|
|
|
property ColumnSlot colSlot: GameState.columns[columnId].length > 0 ? GameState.columns[columnId][cardId] : null
|
|
|
|
|
|
|
|
CardModel {
|
|
|
|
id: colCard
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
visible: parent.colSlot !== null
|
|
|
|
|
|
|
|
card: parent.colSlot ? parent.colSlot.card : null
|
|
|
|
isFaceDown: parent.colSlot ? !parent.colSlot.revealed : false
|
|
|
|
onClicked: {
|
|
|
|
if (parent.colSlot && parent.colSlot.revealed) {
|
|
|
|
if (GameState.autoMoveColumnCard(parent.columnId, parent.cardId)) {
|
|
|
|
if (GameState.isWinnable()) {
|
|
|
|
console.log("Still winnable");
|
|
|
|
} else {
|
|
|
|
console.log("Game is lost");
|
2024-12-06 03:55:48 +00:00
|
|
|
}
|
2024-12-04 18:15:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-07 22:49:38 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: emptySlotRect
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
visible: parent.colSlot === null
|
|
|
|
|
|
|
|
color: "gray"
|
|
|
|
border.color: "white"
|
2024-12-08 10:41:28 +00:00
|
|
|
border.width: width * 0.025
|
2024-12-07 22:49:38 +00:00
|
|
|
opacity: 0.2
|
2024-12-08 10:41:28 +00:00
|
|
|
radius: width * 0.05
|
2024-12-07 22:49:38 +00:00
|
|
|
}
|
2024-12-04 18:15:50 +00:00
|
|
|
}
|
|
|
|
}
|