Commit 12077fb8 authored by Yann Boucher's avatar Yann Boucher
Browse files

On peut maintenant jouer à Snake avec les flèches

parent 786fdc58
Pipeline #79690 passed with stages
in 17 seconds
......@@ -750,9 +750,12 @@ void MainWindow::play_snake()
on_pushButton_clicked(); // reset la grille
QWidget::grabKeyboard();
static auto restore = [&]
{
ui_update_alphabet(simulation.getAlphabet());
QWidget::releaseKeyboard();
snake_timer.stop();
on_pushButton_clicked(); // reset la grille
};
......@@ -889,26 +892,26 @@ void MainWindow::closeEvent(QCloseEvent *e)
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Q)
if (event->key() == Qt::Key_Q || event->key() == Qt::Key_Left)
m_arrow_key_state[0] = true;
if (event->key() == Qt::Key_S)
if (event->key() == Qt::Key_S || event->key() == Qt::Key_Down)
m_arrow_key_state[1] = true;
if (event->key() == Qt::Key_D)
if (event->key() == Qt::Key_D || event->key() == Qt::Key_Right)
m_arrow_key_state[2] = true;
if (event->key() == Qt::Key_Z)
if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Up)
m_arrow_key_state[3] = true;
QMainWindow::keyPressEvent(event);
}
void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Q)
if (event->key() == Qt::Key_Q || event->key() == Qt::Key_Left)
m_arrow_key_state[0] = false;
if (event->key() == Qt::Key_S)
if (event->key() == Qt::Key_S || event->key() == Qt::Key_Down)
m_arrow_key_state[1] = false;
if (event->key() == Qt::Key_D)
if (event->key() == Qt::Key_D || event->key() == Qt::Key_Right)
m_arrow_key_state[2] = false;
if (event->key() == Qt::Key_Z)
if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Up)
m_arrow_key_state[3] = false;
QMainWindow::keyReleaseEvent(event);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment