int main(int argc, const char *argv[]) { fb_info fb_v; fb_info * temp; pthread_t id; int ret; Dot mid; mid.x = 512; mid.y = 275; char ip_address[20]; int mode; create_fb(&fb_v); system("clear"); mode = startup(fb_v, ip_address); draw_pic(fb_v,OFFSET - 20,0,940,720,gImage_chessboard); draw_pic(fb_v,OFFSET - 120,200,100,100,gImage_chessboard); draw_pic(fb_v,OFFSET - 120,500,100,100,gImage_chessboard); draw_piece(fb_v,OFFSET - 70,250,40,0x00000000); draw_piece(fb_v,OFFSET - 70,550,40,0xffffffff); print_board(fb_v,23,30,30,OFFSET,15,0x00000000); temp = &fb_v; if((ret = pthread_create(&id, NULL, (void *) mouse_test,(void *)temp)) != 0) { printf("Create pthread error!\n"); exit(1); } if(mode == 1) udp_server(fb_v); else udp_client(fb_v, ip_address); return 0; }
int mouse_test(fb_info fb) { int fd; int xx = 123, yy = 234; if((fd = mouse_open("/dev/input/mice")) < 0) { perror("mouse_open"); exit(1); } mevent_t mevent; u8_t buf[] = {0xf3,0xc8,0xf3,0x64,0xf3,0x50}; if(write(fd, buf, sizeof(buf)) < sizeof(buf)) { perror("mouse_write"); fprintf(stderr, "Error write to mice device\n"); } save_cursor(fb,xx,yy,cursor_save); while(1) { if(mouse_parse(fd, &mevent) == 0 && (mevent.x || mevent.y || mevent.z || mevent.button)) { restore_cursor(fb,xx,yy,cursor_save); xx += mevent.x; yy += mevent.y; if(xx > 1366) xx = 1366; if(xx < 0) xx = 0; if(yy > 721) yy = 721; if(yy < 0) yy = 0; if(mevent.button == 1 && xx < 420) { if(xx >= 300 && yy >=210 && yy <= 290) who = 2; else if(xx >= 300 && yy >= 510 && yy <= 590) who = 1; } if(mevent.button == 1 && xx >= 420 && yy <= 710 && xx <= 1320) { if(! check(xx,yy)) { draw_piece(fb,(xx + 15)/30 * 30,yy/30 * 30 + 15,13,(who - 1) ? 0x00000000 : 0xffffffff); chess_count(xx, yy); if(check_all(fb)) exit(0); printf("%d %d\n",(xx + 15 - 420) / 30, (yy) / 30); who = (who - 1) ? 1 : 2; } } save_cursor(fb,xx,yy,cursor_save); draw_cursor(fb,xx,yy,cursor_16_25); } usleep(100); } }
// initialize void init() { int i,j,cnt=1; int randKey; //int arr_numlist[MAXP*MAXP]; //BOOL duplicated=0; //랜덤 난수 생성 시 중복 판별 srand(time(NULL)); //랜덤 초기화 for(i=0;i<size;i++) { for(j=0;j<size;j++) { if((i+1)*(j+1) != (size*size)) { piece[i][j] = cnt++; } else { piece[i][j] = 0; } } } blank_i = size - 1; blank_j = size - 1; //2차배열 piece를 초기화, 빈조각의 위치는 blank_i, blank_j로 나타낸다. //랜덤 숫자 배열을 들어내서 섞고 집어넣지 않고, 퍼즐 틀 내에서만 섞는다. for(i=0;i<300;i++) { randKey = rand() % 4; switch(randKey) { case 0: randKey = KEY_2; break; case 1: randKey = KEY_4; break; case 2: randKey = KEY_6; break; case 3: randKey = KEY_8; break; } move(randKey); } // draw pieces for(i=0;i<size;i++) { for(j=0;j<size;j++) { draw_piece(i,j); } } }
int main(void) //메인 함수 { BOOL isEndloop = 0; printf("enter a number (3 - 7): "); scanf("%d",&size); /*사용자로부터 크기를 입력받는다. 범위(MINP: 3 - MAXP: 7)을 벗어나면 최소크기 MINP: 3으로 고정*/ if(!(MINP<=size && size<=MAXP)) size=MINP;//입력된 크기가 3보다 작거나 7보다 크면, 최소인 3으로 출력 printf("Press ESC to exit.\n"); printf("Left(4, A), Right(6, D), Down(2, X), Up(8, W)\n"); // initilize the game init(); // play while(!isEndloop) { int i,j; /* judge()함수가 1을 리턴할 때까지 사용자로부터 키를 입력받아(_getch()) 퍼즐 조각을 움직이면서 게임 진행 */ move(_getch()); isEndloop = judge(); //draw each puzzle for(i=0;i<size;i++) { for(j=0;j<size;j++) { draw_piece(i,j); } } } // exit the game gotoxy(0, size*3+1 + OFFSET); printf("Done!\n\n"); return 0; }
void main_loop() { struct colour *board[WIDTH_CELLS][HEIGHT_CELLS]; SDL_Event e = {0}; bool running = false; bool game_over = false; int i = 0; int x = 0; int y = 0; int score = 0; int last_x = 0; int last_y = 1; struct piece held; new_piece(&held); TTF_Font *font = TTF_OpenFont(FONT_FILE, FONT_SIZE); if (!font) { printf("TTF_OpenFont: %s\n", TTF_GetError()); return; } for (y = 0; y < HEIGHT_CELLS; y++) for (x = 0; x < WIDTH_CELLS; x++) board[x][y] = &(palette[0]); running = true; last_x = last_y = x = y = 0; SDL_AddTimer(INTERVAL_NORMAL, &gravity_callback, NULL); char lockout; while (running) { lockout = 0; score += clear_rows(&board); if (hit_side(x, y, &held, &board)) x = last_x; if (hit_floor(x, y, &held, &board)) lockout = 1; draw_board(&board); if (!game_over) draw_piece(x, y, held.colour, held.bitmap); char score_string[16]; snprintf(score_string, sizeof(score_string), "Score: %d", score); score_string[sizeof(score_string) - 1] = '\0'; plot_text(score_string, font, ((SDL_Color){255,255,255,255}), 10, 10); if (game_over) plot_text("Game over", font, ((SDL_Color){255,255,255,255}), 90, 50); plot_update(); SDL_WaitEvent(&e); if (pause_mode) { if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_p) { pause_mode = 0; } continue; } switch (e.type) { case SDL_USEREVENT: if (lockout && !game_over) { drop_piece(x, y, &held, &board); last_x = last_y = x = y = 0; new_piece(&held); if (piece_overlaps(&held, &board, x, y)) { game_over = true; } lockout = 0; } else { last_y = y++; /* gravity */ last_x = x; } break; case SDL_QUIT: fprintf(stderr, "quit\n"); running = false; break; case SDL_KEYDOWN: switch (e.key.keysym.sym) { case SDLK_p: pause_mode = 1; break; case SDLK_a: last_x = x--; break; case SDLK_d: last_x = x++; break; case SDLK_w: i = 0; do { rotate(&held, 1); } while(hit_side(x, y, &held, &board) && i++ < 4); break; case SDLK_s: speed_mode = 1; break; case SDLK_q: running = false; break; default: break; } break; case SDL_KEYUP: switch (e.key.keysym.sym) { case SDLK_s: speed_mode = 0; break; default: break; } default: break; } } }