Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Feb 23, 2025
1 parent 101b2ca commit 7de044e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 76 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ set(HEADERS
)
set(QML_FILES
qml/Cell.qml
qml/SettingsPage.qml
qml/GameOverPopup.qml
qml/AboutPage.qml
qml/LoadWindow.qml
qml/SaveWindow.qml
qml/SettingsWindow.qml
qml/PostgamePopup.qml
qml/AboutPopup.qml
qml/LoadPopup.qml
qml/SavePopup.qml
qml/ErrorWindow.qml
qml/TopBar.qml
qml/LeaderboardPage.qml
qml/LeaderboardPopup.qml
qml/TempScrollBar.qml
qml/WelcomePage.qml
qml/WelcomePopup.qml
qml/Main.qml
qml/InfoIcon.qml
qml/GameGrid.qml
Expand Down
File renamed without changes.
36 changes: 15 additions & 21 deletions qml/GameGrid.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ GridView {
property bool initialAnimationPlayed: false
property int cellsCreated: 0
required property var leaderboardWindow
required property var gameOverPopup

GameAudio {
id: audioEngine
Expand Down Expand Up @@ -109,13 +108,11 @@ GridView {
if (GameState.mines.includes(currentIndex)) {
cell.isBombClicked = true
GameState.gameOver = true
GameState.gameWon = false
GameTimer.stop()
revealAllMines()
audioEngine.playLoose()
gameOverPopup.gameOverLabelText = "Game over"
gameOverPopup.gameOverLabelColor = "#d12844"
gameOverPopup.newRecordVisible = false
gameOverPopup.visible = true
GameState.displayPostGame = true
return
}

Expand Down Expand Up @@ -223,6 +220,7 @@ GridView {
function checkWin() {
if (GameState.revealedCount === GameState.gridSizeX * GameState.gridSizeY - GameState.mineCount && !GameState.gameOver) {
GameState.gameOver = true
GameState.gameWon = true
GameTimer.stop()

let leaderboardData = GameCore.loadGameState("leaderboard.json")
Expand Down Expand Up @@ -255,9 +253,7 @@ GridView {
leaderboard[timeField] = formattedTime;
leaderboard[centisecondsField] = centiseconds;
leaderboardWindow[timeField] = formattedTime;
gameOverPopup.newRecordVisible = true
} else {
gameOverPopup.newRecordVisible = false
GameState.displayNewRecord = true
}
}

Expand All @@ -271,22 +267,22 @@ GridView {
if (difficulty === 'easy') {
if (!SteamIntegration.isAchievementUnlocked("ACH_NO_HINT_EASY")) {
SteamIntegration.unlockAchievement("ACH_NO_HINT_EASY");
gameOverPopup.notificationText = qsTr("New flag unlocked!")
gameOverPopup.notificationVisible = true;
GameState.notificationText = qsTr("New flag unlocked!")
GameState.displayNotification = true;
GameState.flag1Unlocked = true;
}
} else if (difficulty === 'medium') {
if (!SteamIntegration.isAchievementUnlocked("ACH_NO_HINT_MEDIUM")) {
SteamIntegration.unlockAchievement("ACH_NO_HINT_MEDIUM");
gameOverPopup.notificationText = qsTr("New flag unlocked!")
gameOverPopup.notificationVisible = true;
GameState.notificationText = qsTr("New flag unlocked!")
GameState.displayNotification = true;
GameState.flag2Unlocked = true;
}
} else if (difficulty === 'hard') {
if (!SteamIntegration.isAchievementUnlocked("ACH_NO_HINT_HARD")) {
SteamIntegration.unlockAchievement("ACH_NO_HINT_HARD");
gameOverPopup.notificationText = qsTr("New flag unlocked!")
gameOverPopup.notificationVisible = true;
GameState.notificationText = qsTr("New flag unlocked!")
GameState.displayNotification = true;
GameState.flag3Unlocked = true;
}
}
Expand All @@ -295,14 +291,14 @@ GridView {
if (difficulty === 'easy') {
if (Math.floor(GameTimer.centiseconds / 100) < 15 && !SteamIntegration.isAchievementUnlocked("ACH_SPEED_DEMON")) {
SteamIntegration.unlockAchievement("ACH_SPEED_DEMON");
gameOverPopup.notificationText = qsTr("New grid animation unlocked!")
gameOverPopup.notificationVisible = true
GameState.notificationText = qsTr("New grid animation unlocked!")
GameState.displayNotification = true
GameState.anim2Unlocked = true
}
if (GameState.currentHintCount >= 20 && !SteamIntegration.isAchievementUnlocked("ACH_HINT_MASTER")) {
SteamIntegration.unlockAchievement("ACH_HINT_MASTER");
gameOverPopup.notificationText = qsTr("New grid animation unlocked!")
gameOverPopup.notificationVisible = true
GameState.notificationText = qsTr("New grid animation unlocked!")
GameState.displayNotification = true
GameState.anim1Unlocked = true
}
}
Expand All @@ -311,9 +307,7 @@ GridView {
}
}

gameOverPopup.gameOverLabelText = qsTr("Victory")
gameOverPopup.gameOverLabelColor = "#28d13c"
gameOverPopup.visible = true
GameState.displayPostGame = true
audioEngine.playWin()
} else {
audioEngine.playClick()
Expand Down
7 changes: 7 additions & 0 deletions qml/GameState.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ QtObject {
}
return null;
}
property bool gameWon: false
property string postgameText: gameWon ? qsTr("Victory") : qsTr("Game over")
property string postgameColor: gameWon ? "#28d13c" : "#d12844"
property string notificationText: ""
property bool displayNotification: false
property bool displayNewRecord: false
property bool displayPostGame: false
}
File renamed without changes.
File renamed without changes.
16 changes: 7 additions & 9 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ApplicationWindow {
anchors.fill: parent
active: GameCore.showWelcome
sourceComponent: Component {
WelcomePage {
WelcomePopup {
}
}
}
Expand All @@ -176,17 +176,16 @@ ApplicationWindow {
anchors.fill: parent
active: !SteamIntegration.initialized
sourceComponent: Component {
AboutPage {
AboutPopup {
}
}
}

GameOverPopup {
id: gameOverPopup
PostgamePopup {
grid: grid
}

SettingsPage {
SettingsWindow {
id: settingsWindow
grid: grid
rootWidth: root.width
Expand All @@ -195,15 +194,15 @@ ApplicationWindow {
rootY: root.y
}

LoadWindow {
LoadPopup {
id: loadWindow
}

SaveWindow {
SavePopup {
id: saveWindow
}

LeaderboardPage {
LeaderboardPopup {
id: leaderboardWindow
}

Expand Down Expand Up @@ -238,7 +237,6 @@ ApplicationWindow {
GameGrid {
id: grid
leaderboardWindow: leaderboardWindow
gameOverPopup: gameOverPopup
Component.onCompleted: SaveManager.setGrid(grid)
delegate: Cell {
root: root
Expand Down
55 changes: 16 additions & 39 deletions qml/GameOverPopup.qml → qml/PostgamePopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ Popup {
anchors.centerIn: parent
id: control
required property var grid
visible: false
visible: GameState.displayPostGame
modal: true
closePolicy: Popup.NoAutoClose
width: 300
property int buttonWidth: Math.max(retryButton.implicitWidth, closeButton.implicitWidth)
property string notificationText
property bool notificationVisible: false
property string gameOverLabelText: "Game Over"
property string gameOverLabelColor: "#d12844"
property bool newRecordVisible: false

Shortcut {
sequence: "Return"
Expand All @@ -29,58 +24,38 @@ Popup {
Shortcut {
sequence: "Esc"
enabled: control.visible
onActivated: control.visible = false
}

enter: Transition {
NumberAnimation {
property: "opacity"
from: 0.0
to: 1.0
duration: 200
easing.type: Easing.InOutQuad
}
}

exit: Transition {
NumberAnimation {
property: "opacity"
from: 1.0
to: 0.0
duration: 200
easing.type: Easing.InOutQuad
}
onActivated: retryButton.clicked()
}

GridLayout {
id: popupLayout
anchors.fill: parent
columns: 2
rowSpacing: 15
Label {
id: gameOverLabel
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: control.gameOverLabelText
color: control.gameOverLabelColor
text: GameState.postgameText
color: GameState.postgameColor
Layout.columnSpan: 2
font.family: GameConstants.numberFont.name
font.pixelSize: 16
}

Label {
id: notificationLabel
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: control.notificationText
visible: control.notificationVisible
text: GameState.notificationText
visible: GameState.displayNotification
font.pixelSize: 13
font.bold: true
Layout.columnSpan: 2
color: "#28d13c"
}

Label {
id: recordLabel
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: qsTr("New record saved")
visible: control.newRecordVisible
visible: GameState.displayNewRecord
Layout.columnSpan: 2
font.pixelSize: 13
}
Expand All @@ -90,10 +65,11 @@ Popup {
text: qsTr("Retry")
Layout.fillWidth: true
Layout.preferredWidth: control.buttonWidth
onClicked: {
control.visible = false
control.notificationVisible = false
onClicked: {
control.grid.initGame()
GameState.displayNewRecord = false
GameState.displayNotification = false
GameState.displayPostGame = false
}
}

Expand All @@ -103,8 +79,9 @@ Popup {
Layout.fillWidth: true
Layout.preferredWidth: control.buttonWidth
onClicked: {
control.visible = false
control.notificationVisible = false
GameState.displayNewRecord = false
GameState.displayNotification = false
GameState.displayPostGame = false
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7de044e

Please sign in to comment.