Ejemplo n.º 1
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);
    }
}
Ejemplo n.º 2
0
int mouse_doing(void)
{
    m_event mevent;
    fd_set input_fd;
    int fd;
    char c,victory = -1;
    int w=0;
    int who,n,flag1 = 1;;
    u32_t color = 0x00ffffff;
    int mx = 521;
    int my = 384;
    bzero(&board,sizeof(board));
    fd = open("/dev/input/mice",O_RDWR|O_NONBLOCK);
    if(fd < 0)
    {
        perror("open");
        exit(1);
    }
    draw_cursor(mx ,my);
    while(1)
    {
        FD_ZERO(&input_fd);
        FD_SET(client_sock,&input_fd);
        FD_SET(fd,&input_fd);
        if((select(fd+1,&input_fd,NULL,NULL,NULL)) < 0)
        {
            perror("select error");
            continue;
        }
        if((FD_ISSET(fd,&input_fd))&&(get_m_info(fd,&mevent)>0))
        {
            restore_shape(mx,my);
            mx += mevent.dx;
            my += mevent.dy;

            mx = ((mx >= 0)? mx:0);
            my = ((my >= 0)? my:0);
            if(mx >= (fb_v.w-C_WIDTH))
                mx = (fb_v.w-C_WIDTH);
            if(my >= (fb_v.h-C_HEIGHT))
                my = (fb_v.h-C_HEIGHT);

            switch(mevent.button)
            {
                case 1: 
                       if(flag1 == 1)
                       {
                            if((mx > 335)&&(mx < 1235)&&(my >55)&&(my < 775))
                            {
                                if( !check(mx,my) )
                                {
                                    color = ~color;
                                    who = create_spot(mx,my,color,w);
                                    save_shape(mx,my);
                                    chess_count(mx,my,who);
                                    victory = check_all();
                                    server_len = sizeof(server);
                                    n = sendto(client_sock, buffer, 12, 0, (struct sockaddr *)&server, server_len);
                                    flag1 = 0;
                                    w++;
                                }
                            }
                        }
                        break;
                case 2: break;
                case 4: break;
                default :break;
            }
            draw_cursor(mx,my);
        }
        usleep(1000);
        if(FD_ISSET(client_sock,&input_fd))
        {
            restore_shape(mx,my);
            server_len = sizeof(server);
            n = recvfrom(client_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&server, &server_len);
            mx = (p->x)*30 + 350;
            my = (p->y)*30 +70;
            if( !check(mx,my) )
            {
                color = ~color;
                who = create_spot(mx,my,color,w);
                save_shape(mx,my);
                chess_count(mx,my,who);
                victory = check_all();
                w++;
            }
            flag1 = 1;
            draw_cursor(mx,my);
        }
        if( victory == 1)
        {
            printf("play%d won!\n",who);
            printf("continue ? y/n\n");
            scanf("%c",&c);
            getchar();
            if( c=='n')
                break;
           else
            {
                create_scr_fb();
                print_board(350,70,0x008b6914);
                victory = -1;
                w=0;
                color = 0x00ffffff;
                mx = 521;
                my = 384;
                flag1 = 1;
                bzero(&board,sizeof(board)); 
                draw_cursor(mx,my);
            }
        }
     }
     close(fd); 
     return 0;
}
Ejemplo n.º 3
0
int mouse_doing(void)                // zheng chang hua qi zi (dan  ji)
{
    m_event mevent;
    int kkk,a;
    int p = 0;
    int fd;
    int mx = 512;
    int my = 384;
    fd = open("/dev/input/mice",O_RDWR|O_NONBLOCK);
    if(fd < 0)
    {
        perror("open");
        exit(1);
    }
    draw_cursor(mx, my);
    while(1)
    {
        if(get_m_info(fd, &mevent) > 0)
        {
            restore_shape(mx ,my);

            mx += mevent.dx;
            my += mevent.dy;

            mx = ((mx >= 0) ? mx : 0);
            my = ((my >= 0) ? my : 0);
            if(mx >= (fb_v.w-C_WIDTH))
            {
                mx = (fb_v.w-C_WIDTH);
            
            }
            if(my >= (fb_v.h-C_HEIGHT))
            {
                my = (fb_v.h-C_HEIGHT);
            
            }
            switch(mevent.button)
            {
                case 1 :
                         w= print_one_chess(mx, my,p) ;
                         save_shape(mx ,my);
                         chess_count(mx,my,w);
                         a = check_all();
                         if(a == 1)
                         break;
                         p++;
                         break;
                case 2 : break;
                case 4 : break;
                default: break;
            
            }
            if(a != 1)
            draw_cursor(mx ,my);
          if(a == 1)
            {
                bzero(&board,sizeof(board));
                printf("go: 0   exit: 1\n");
                scanf("%d",&kkk);
                break;
            }
        }
        usleep(1000);
    }
    if(kkk == 1) close(fd);  
    return kkk;
}
Ejemplo n.º 4
0
int mouse_doing1(void)//(int x,int y)             //wang luo  hua qi zi  (zuo wei fu wu qi)
{
    m_event mevent;
	int len;
    int x,y;
    int kkk;
    int a;
    int p = 0;
    int fd;
    int k1,k2;
    int mx = 512;
    int my = 384;
    int aaaa;
    fd_set input_fd;
    fd = open("/dev/input/mice",O_RDWR);
    if(fd < 0)
    {
        perror("open");
        exit(1);
    }
    draw_cursor(mx, my);
    aaaa = fd > server_sock ? fd : server_sock;
    while(1)
    {
        FD_ZERO(&input_fd);
        FD_SET(fd,&input_fd);
        FD_SET(server_sock,&input_fd);
        if((select(aaaa+1,&input_fd,NULL,NULL,NULL)) < 0)
        {
            perror("select");
            continue;
        }
        if(FD_ISSET(fd,&input_fd))
        {
        if(get_m_info(fd, &mevent) > 0)
        {
            restore_shape(mx ,my);

            mx += mevent.dx;
            my += mevent.dy;

            mx = ((mx >= 0) ? mx : 0);
            my = ((my >= 0) ? my : 0);
            if(mx >= (fb_v.w-C_WIDTH))
            {
                mx = (fb_v.w-C_WIDTH);
            
            }
            if(my>= (fb_v.h-C_HEIGHT))
            {
                my = (fb_v.h-C_HEIGHT);
            
            }
            if(p%2 == 1)
            {
                switch(mevent.button)
                {
                    case 1 :

                             w= print_one_chess(mx,my,p);
                             save_shape(mx ,my);
                             chess_count(mx,my,w);
                             a = check_all();
                             p++;
	                  	     sendto(server_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&client, client_len);
                             break;
                    case 2 : break;
                    case 4 : break;
                    default: break;
            
                }
            }
//            if(a != 1)
            draw_cursor(mx ,my);
            if(a == 1)
            {
                bzero(&board,sizeof(board));
                printf("go: 0   exit: 1\n");
                scanf("%d",&kkk);
                break;
            }
        }
        usleep(1000);
        if(kkk == 1) close(fd);  
    }
    if(FD_ISSET(server_sock,&input_fd))
    {
    
        printf("dsads\n");
        restore_shape(mx,my);
		client_len = sizeof(client);
        printf("sdfsdf\n");
		len = recvfrom(server_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&client, &client_len);
        printf("%d\n",len);
		if (len < 0)
		{
			close(server_sock);
			fprintf(stderr, "%s\n", strerror(errno));
			exit(EXIT_FAILURE);
		}
		else
		{
			printf("recvfrom client ok!\n");
			in.s_addr = client.sin_addr.s_addr;
			printf("client ip  : %s\n", inet_ntoa(in));
			printf("client port: %d\n", ntohs(client.sin_port));
			printf("\n");
            x= pp->x ;
            y= pp->y ;
            printf("%d\n",pp->x);
            printf("%d\n",y);
            k1=x*30+100;
            k2=y*30+40;
            w= print_one1_chess(k1,k2);
            p++;
            chess_count(k1,k2,w);
            a = check_all();
		}
    }
    }
    return 0;
}
Ejemplo n.º 5
0
int mouse_doing(void)
{
    m_event mevent;
    //int fd;
    //int mx = 512;
    //int my = 384;
    char victory = -1;

    //fd = open("/dev/input/mice", O_RDWR|O_NONBLOCK);
    //if(fd < 0)
    //{
    //perror("open");
    //exit(1);
    //}

    //print_color();
    //mouse_cursor(mx, my);
    //while(1)
    //{
    if(get_m_info(fd, &mevent) > 0)
    {
        restore_shape(mx, my);
        mx += mevent.dx;
        my += mevent.dy;

        mx = ((mx >= 0) ? mx : 0);
        my = ((my >= 0) ? my : 0);
        if(mx >= (fb_v.w-C_WIDTH))
        {
            mx = (fb_v.w-C_WIDTH);
        }
        if(my >= (fb_v.h-C_HEIGHT))
        {
            my = (fb_v.h-C_HEIGHT);
        }

        mouse_cursor(mx, my);
        switch(mevent.mode)
        {
        case 1:
            restore_shape(mx, my);
            if (scan_point(mx, my) == 0)
            {
                //if(global_color == 0x00ffffff)
                //{
                //global_color = 0x00000000;
                //who = 1;
                //}
                //else
                //{
                //global_color = 0x00ffffff;
                //who = 2;
                //}
                flag = 1;
                chess_count(mx, my);
                //global_x = mx - STARTX;
                //global_y = my - STARTY;
                //global_x = mx;
                //global_y = my;
                victory = check_all();
            }
            mouse_cursor(mx, my);
            break;
        case 2:
            break;
        case 4:
            break;
        default:
            break;
        }
#if 0
        if(victory == 1)
        {
            printf("play%d won!\n", who);
            printf("contniue ? y/n\n");
            if(getchar() == 'n')
                return 0;
            else
            {
                memset((u8_t *)fb_v.fb_men, 0, fb_v.h * fb_v.w *fb_v.bpp/8);
                memset(board, 0, H_NUM * V_NUM);
                fb_backgound(0, 0, fb_v.w - 1, fb_v.h - 1, 0x00996600);
                fb_backgound(STARTX, STARTY, STARTX + (V_NUM - 1) * SPACE, STARTY + (H_NUM - 1) * SPACE, 0x00ffcc33);
                fb_board(0x000000ff);
                print_color();
                mouse_cursor(512, 384);
                global_color = 0xffffffff;
                who = 1;
                victory = -1;
                mx = 512;
                my = 384;
                mouse_cursor(mx, my);
            }
            getchar();
        }
#endif
    }
    usleep(1000);
    //}
    return 0;
}