static void snake_colission (short x, short y) { if (x==BOARD_WIDTH || x<0 || y==BOARD_HEIGHT || y<0) { snake_die(); return; } switch (board[x][y]) { case 0: break; case -1: snakelength+=2; score+=level; apple=false; break; default: snake_die(); break; } }
GamePainter::GamePainter(QWidget *parent) : QWidget(parent) { m_cellSize = QSize( 30, 30 ); m_field = new Field( 15, 15 ); m_snake = new Snake( QPoint( 7, 7) ); m_IsPlay = false; m_gameTimer = new QTimer; m_gameSpeed = 160; m_score = 0; resize( m_cellSize.width() * ( m_field->getNumWCells() - 2 ) , m_cellSize.height() * (m_field->getNumHCells() - 2 ) + 30 ); QPixmap background("../snake_work_version/background.jpg" ); background.scaled( this->size() ); QPalette p; p.setBrush( this->backgroundRole(), QBrush( background ) ); this->setPalette(p); QIcon windowIcon("../snake_work_version/icon1.png"); window()->setWindowTitle("Snake"); window()->setWindowIcon( windowIcon ); connect( m_snake, SIGNAL(newStep(QPoint,QPoint)), m_field, SLOT(snake_move(QPoint,QPoint)) ); connect( m_field, SIGNAL(snake_dead()), SLOT(snake_die()) ); connect( m_field, SIGNAL(snake_ate()), SLOT(snake_eat())); connect( m_gameTimer, SIGNAL(timeout()), SLOT(game()) ); m_settings = new QSettings( "HOME", "Snake" ); m_highScore = m_settings->value( HIGH_SCORE_KEY, 0 ).toInt() ; QLabel* high_score = new QLabel("<font face=\"mv boli\" color=#40E0D0><strong>High Score: </strong></font>", this ); high_score->move( 20, -160 ); high_score->resize( 300, 350 ); QLabel* score = new QLabel("<font face=\"mv boli\" color=#40E0D0><strong>Score: </strong></font>", this ); score->move( width() - 100, -160 ); score->resize( 300, 350 ); srand(time(0)); }