Exemplo n.º 1
0
Arquivo: main.c Projeto: outsky/tetris
int main()
{
    struct sigaction sa;
    memset(&sa, 0, sizeof(struct sigaction));
    sa.sa_handler = sigint;
    sigaction(SIGINT, &sa, NULL);
    atexit(quit);
    prepare_input(&org);
    erase_display();

    srand(time(NULL));
    game_init();
    draw();

    pthread_mutex_init(&mut, NULL);
    pthread_cond_init(&cond, NULL);

    pthread_t tid;
    pthread_create(&tid, NULL, trd_timer, NULL);
    pthread_detach(tid);
    pthread_create(&tid, NULL, trd_draw, NULL);
    pthread_detach(tid);

    int c;
    while(EOF != (c=getchar())) {
        if(c == 'j') {
            move_down();
        } else if(c == 'k') {
            rotate();
        } else if(c == 'h') {
            move_left();
        } else if(c == 'l') {
            move_right();
        } else if(c == 32) {
            drop_down();
        } else if(c == 'q') {
            quit();
        } else {
            continue;
        }
    }

    return 0;
}
Exemplo n.º 2
0
void block_detect()
{
			stop();	
			ssss =SREG;
			cli();
			timer0_init();
			TIMSK |= (1 << OCIE0) | (1 << TOIE0); // timer 0 compare match and overflow interrupt enable 
			sei();
			SREG = ssss;
			drop_down();
			_delay_ms(2000);
			pickup();
			//drop_down();
			
			ssss =SREG;
			cli();
			timer2_init();
			sei();
			ssss = SREG;
			forward();	
}
Exemplo n.º 3
0
	size_t OccupancyGrid::check_lines()
	{
		size_t lines_cleared = 0;
		for (size_t i = 0; i < height; i++)
		{
			size_t cell_count = 0;
			for (size_t j = 0; j < width; j++)
			{
				if (cells[i][j].v == -1)
					break;
				cell_count++;
			}
			if (cell_count == width) 
			{
			//	animate_line(i);
				drop_down(i);
				i--;
				lines_cleared++;
			}
		}

		return lines_cleared;
	}