Select Git revision
Main.qml 24.81 KiB
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
// Optionnel : utilisez un style non natif pour autoriser la personnalisation
// import QtQuick.Controls.Material 2.12
Window {
id: mainWindow
width: Screen.width
height: Screen.height
visible: true
visibility: Window.Maximized
title: qsTr("Motus")
// Propriétés de gestion
property int indice_case: 0
property int current_essai: 0
property var caseArray: [] // Rempli lors de la création de la grille
property var case_focus: null
property int nb_lettres: 5
property var arrayTry: [5,6,6,7,7,8,8,8,8]
property int nb_essais: arrayTry[nb_lettres - 4]
property string mot: ""
property var mot_split: []
property var keysArray: []
function changeKeyColor(letter, newColor) {
for (var i = 0; i < keysArray.length; i++) {
if (keysArray[i].keyLetter === letter) {
keysArray[i].keyColor = newColor;
}
}
}
// Rectangle principal qui couvre la fenêtre
Rectangle {
id: mainRect
anchors.fill: parent
color: "#323232"
focus: true
// Gestion des touches du clavier physique
Keys.onPressed: function(event) {
if (mot !== "" && !motusGame.loosetry && !motusGame.win && !motusGame.loosetime) {
// Saisie d'une lettre (de A à Z)
if (/^[a-zA-Z]$/.test(event.text)) {
if (indice_case < nb_lettres) {
var cellIndex = current_essai * nb_lettres + indice_case;
caseArray[cellIndex]._textText = event.text.toUpperCase();
indice_case++;
event.accepted = true;
}
}
// Gestion de la touche Backspace
else if (event.key === Qt.Key_Backspace) {
if (indice_case > 0) {
indice_case--;
var cellIndex = current_essai * nb_lettres + indice_case;
caseArray[cellIndex]._textText = "";
event.accepted = true;
}
}
// Passage à la ligne suivante avec la touche Entrée
else if (event.key === Qt.Key_Return) {
if (indice_case === nb_lettres) {
// Construire le mot entré en majuscules
var candidate = [];
for (var i = 0; i < nb_lettres; i++){