diff --git a/usr/share/calamares/branding/biglinux/Cell.qml b/usr/share/calamares/branding/biglinux/Cell.qml new file mode 100644 index 0000000..7cd0489 --- /dev/null +++ b/usr/share/calamares/branding/biglinux/Cell.qml @@ -0,0 +1,40 @@ +import QtQuick 2.15 + +Item { + property int row + property int column + property bool isMine + property bool isOpened + property bool isFlagged + property int neighborMines + signal leftClick + signal rightClick + + Rectangle { + width: parent.width + height: parent.height + border.color: "black" + color: isOpened ? "lightgrey" : (isFlagged ? "white" : "grey") + + MouseArea { + acceptedButtons: Qt.LeftButton | Qt.RightButton + anchors.fill: parent + onClicked: { + if (mouse.button === Qt.LeftButton && !isFlagged) { + leftClick() + } + if (mouse.button === Qt.RightButton) { + rightClick() + } + } + + } + + Text { + anchors.centerIn: parent + text: isOpened ? (isMine ? "💣" : (neighborMines > 0 ? neighborMines : "")) : (isFlagged ? "🚩" : "") + font.pointSize: 20 + color: isMine ? "red" : "black" + } + } +} diff --git a/usr/share/calamares/branding/biglinux/MinesModel.qml b/usr/share/calamares/branding/biglinux/MinesModel.qml new file mode 100644 index 0000000..af8c6d9 --- /dev/null +++ b/usr/share/calamares/branding/biglinux/MinesModel.qml @@ -0,0 +1,117 @@ +import QtQuick 2.15 + +ListModel { + id: minesModel + + property int rows: 15 + property int columns: 20 + signal gameOver() + + function initialize() { + clearModel() + generateMines() + calculateNeighborMines() + } + + function clearModel() { + clear() + for (var row = 0; row < rows; ++row) { + for (var col = 0; col < columns; ++col) { + append({ + row: row, + column: col, + isMine: false, + isOpened: false, + isFlagged: false, + neighborMines: 0 + }) + } + } + } + + function generateMines() { + var mineCount = 40 // Número de minas + while (mineCount > 0) { + var row = Math.floor(Math.random() * rows) + var col = Math.floor(Math.random() * columns) + var index = row * columns + col + if (!get(index).isMine) { + get(index).isMine = true + --mineCount + } + } + } + + function calculateNeighborMines() { + for (var row = 0; row < rows; ++row) { + for (var col = 0; col < columns; ++col) { + var index = row * columns + col + if (!get(index).isMine) { + var count = 0 + for (var i = -1; i <= 1; ++i) { + for (var j = -1; j <= 1; ++j) { + var r = row + i + var c = col + j + if (r >= 0 && r < rows && c >= 0 && c < columns) { + var neighborIndex = r * columns + c + if (get(neighborIndex).isMine) { + ++count + } + } + } + } + get(index).neighborMines = count + } + } + } + } + + function openCell(row, column) { + var index = row * columns + column + var cell = get(index) + if (cell.isOpened || cell.isFlagged) { + return + } + + var stack = [] + stack.push(cell) + + while (stack.length > 0) { + var currentCell = stack.pop() + currentCell.isOpened = true + + if (currentCell.isMine) { + gameOver() + return + } + + if (currentCell.neighborMines === 0) { + for (var i = -1; i <= 1; ++i) { + for (var j = -1; j <= 1; ++j) { + var r = currentCell.row + i + var c = currentCell.column + j + if (r >= 0 && r < rows && c >= 0 && c < columns) { + var neighborIndex = r * columns + c + var neighborCell = get(neighborIndex) + if (!neighborCell.isOpened && !neighborCell.isMine) { + stack.push(neighborCell) + } + } + } + } + } + } + } + + function toggleFlag(row, column) { + var index = row * columns + column + var cell = get(index) + if (!cell.isOpened) { + cell.isFlagged = !cell.isFlagged + // Emitir uma mudança no modelo para atualizar a exibição + set(index, cell) + } + } + + Component.onCompleted: initialize() +} diff --git a/usr/share/calamares/branding/biglinux/branding.desc b/usr/share/calamares/branding/biglinux/branding.desc index 88a1e03..c93c5eb 100644 --- a/usr/share/calamares/branding/biglinux/branding.desc +++ b/usr/share/calamares/branding/biglinux/branding.desc @@ -22,7 +22,7 @@ images: productIcon: "/usr/share/icons/hicolor/scalable/apps/icon-big-hd-install.svg" productWelcome: "big-welcome.svg" -slideshow: "show.qml" +slideshow: "mines.qml" slideshowAPI: 1 style: diff --git a/usr/share/calamares/branding/biglinux/mines.qml b/usr/share/calamares/branding/biglinux/mines.qml new file mode 100644 index 0000000..7ad3150 --- /dev/null +++ b/usr/share/calamares/branding/biglinux/mines.qml @@ -0,0 +1,63 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Controls 2.15 + +Window { + visible: true + width: 800 + height: 600 + title: "Mines" + + MinesModel { + id: minesModel + rows: 15 + columns: 20 + onGameOver: { + overlay.visible = true + restartButton.visible = true + } + } + + GridView { + id: gridView + anchors.fill: parent + model: minesModel + cellWidth: width / minesModel.columns + cellHeight: height / minesModel.rows + anchors.margins: 5 + + delegate: Cell { + width: gridView.cellWidth + height: gridView.cellHeight + row: model.row + column: model.column + isMine: model.isMine + isOpened: model.isOpened + isFlagged: model.isFlagged + neighborMines: model.neighborMines + onLeftClick: minesModel.openCell(row, column) + onRightClick: minesModel.toggleFlag(row, column) + } + } + + Rectangle { + id: overlay + anchors.fill: parent + color: "black" + opacity: 0.7 + visible: false + } + + Button { + id: restartButton + text: "Restart" + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + visible: false + onClicked: { + minesModel.initialize() + overlay.visible = false + restartButton.visible = false + } + } +} diff --git a/usr/share/calamares/branding/biglinux/show.qml b/usr/share/calamares/branding/biglinux/pong.qml similarity index 100% rename from usr/share/calamares/branding/biglinux/show.qml rename to usr/share/calamares/branding/biglinux/pong.qml