Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FenPendu.h"
- #include <time.h>
- #include <QDebug>
- FenPendu::FenPendu(QWidget *parent) : QMainWindow(parent)
- {
- setWindowTitle("Pendu par alexandre :p");
- cree_barre();
- choisir_mot();
- clavier_label();
- }
- void FenPendu::cree_barre()
- {
- m_menu_fichier = menuBar()->addMenu("&Fichier");
- m_menu_propos = menuBar()->addMenu("&A propos");
- m_act_nouveauMot = m_menu_fichier->addAction("&Nouveau mot");
- m_act_quitter = m_menu_fichier->addAction("&Quitter");
- m_act_APropos = m_menu_propos->addAction("&A propos");
- m_act_AProposQt = m_menu_propos->addAction("A propos de &Qt");
- m_act_nouveauMot->setShortcut(QKeySequence("CTRL+N"));
- m_act_quitter->setShortcut(QKeySequence("CTRL+Q"));
- m_act_APropos->setShortcut(QKeySequence(Qt::Key_Help));
- m_act_nouveauMot->setShortcut(QKeySequence("CTRL+A"));
- connect(m_act_quitter, SIGNAL(triggered()), qApp, SLOT(quit()));
- connect(m_act_APropos, SIGNAL(triggered()), this, SLOT(APropos()));
- connect(m_act_AProposQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
- }
- void FenPendu::clavier_label()
- {
- QVBoxLayout *vboxPrinc = new QVBoxLayout;
- layout = new QGridLayout;
- QWidget *conteneur = new QWidget(this);
- m_labelMot = new QLabel;
- QString stringLabel;
- for(int i = 0; i <= m_motTirer.length(); i++)
- stringLabel += "*";
- m_labelMot->setText(stringLabel);
- m_labelMot->setFrameStyle(QFrame::Panel);
- m_labelMot->setFont(QFont("arial", 25));
- vboxPrinc->addWidget(m_labelMot, 0, Qt::AlignCenter);
- QSignalMapper *mapper = new QSignalMapper(this);
- QPushButton *button;
- int col(0);
- int row(0);
- for ( char i('a'); i <= 'z'; i++ )
- {
- if ( (i - 'a')%7 == 0 )
- {
- col = 0;
- row++;
- }
- button = new QPushButton(QString(i));
- layout->addWidget(button, row, col, Qt::AlignCenter);
- connect(button, SIGNAL(clicked()), mapper, SLOT(map()));
- mapper->setMapping(button, QString(i));
- col++;
- }
- connect(mapper, SIGNAL(mapped(QString)), this, SLOT(analyserLettre(QString)));
- vboxPrinc->addLayout(layout);
- conteneur->setLayout(vboxPrinc);
- setCentralWidget(conteneur);
- }
- qint8 FenPendu::choisir_mot()
- {
- QFile dictionnaire("dico.dic");
- srand(time(NULL));
- if(dictionnaire.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- QTextStream flux(&dictionnaire);
- for(int i = rand()%22740; i != 0; i--)
- m_motTirer = flux.readLine();
- return m_motTirer.length();
- }
- else
- {
- QMessageBox::critical(0, "Erreur", "Le fichier \"dico.dic\" n'a pas été trouvé");
- exit(1);
- }
- }
- void FenPendu::analyserLettre(const QString lettre)
- {
- qDebug() << m_motTirer;
- for(int i = 0; i <= m_motTirer.length(); i++)
- {
- if(lettre == m_motTirer.at(i))
- qDebug() << m_motTirer.at(i);
- }
- }
- void FenPendu::APropos()
- {
- FenAPropos *FenetreAPropos = new FenAPropos(this);
- FenetreAPropos->exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement