Exemple #1
0
void snake_show(int signum)
{
     snake_show_or_hide(BLANK);
     if(!snake_move())
     {
	  endwin();
	  exit(0);
     }

     if(is_touch_food(&food))
     {
	  snake_eat(&food);
	  food_create();
     }
     snake_show_or_hide(SNAKE_BODY);
}
Exemple #2
0
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));
}