Ejemplo n.º 1
0
int print_board(void)
{
    int i=0;
    int j=0;
    memset((u32_t *)fb_v.memo,0,fb_v.w*fb_v.h*fb_v.bpp/8);
    memset(chess_board,0,B_X*B_Y);                          //清屏
    current_player=1;
    current_color=BLACK;
    for (j=10; j<ST_Y+(SPACE*B_Y); j++)                   //打印棋盘并着色
    {
        for (i=20; i<ST_X+(SPACE*B_X); i++) 
        {
            fb_one_pixel(i,j,YELLOW);
        }
    }
    for (i=0; i<B_Y; i++)                                 //给格上色
    {
        fb_line(ST_X,ST_Y+i*SPACE,ST_X+(B_X-1)*SPACE,ST_Y+i*SPACE,BLACK);
    }
    for (i=0; i<B_X; i++) 
    {
        fb_line(ST_X+i*SPACE,ST_Y,ST_X+i*SPACE,ST_Y+(B_Y-1)*SPACE,BLACK);
    }
    fb_circle(60,100,18,BLACK);
    fb_circle(60,200,18,WHITE);
    return 0;
}
Ejemplo n.º 2
0
int print_one_chess (int mx,int my,int q)
{
    int i=0;
    int c=0;
    int x,y;
    //int t = 0;
    x=STARTING_X;
    y=STARTING_Y;
    for(i=0; i<24; i++)
    {
        for(c=0; c<31; c++)
        {
            x=STARTING_X + 30*c;
            if(c==30)
            {
                y+=30;
            }
            if((abs(mx-x)<15) && (abs(my-y)<15))
            {

                /* if(w1==x && w2==y)
                 break;
                 w1=x;
                 w2=y;*/
                //t=paduan(x,y,q);
                //if(t==0)break;
                mx=x;
                my=y;
                if(q%2==0)
                {
                    //  yuan(a,b,10,0x00ffffff);
                    //fb_one_pixel(mx,my,0x000000ff);
                    /* for(h=10.0;h>0;h-=0.01)
                     {
                         circle(a, b,h,0x00ffffff, 0);
                     }*/
                    fb_circle(mx,my,13,0x00ffffff);
                }
                if(q%2==1)
                {
                    // yuan(a,b,10,0x00000000);
                    //fb_one_pixel(a,b,0x000000ff);
                    /*for(h=10.0;h>0;h-=0.01)
                    {
                        circle(a, b,h,0x00000000, 0);
                    }*/
                    fb_circle(mx,my,13,0x00000000);
                }
                break;
            }
        }

        if((abs(mx-x)<15) && (abs(my-y)<15))
            break;
    }

    w = q%2;
    return w+1;
}
Ejemplo n.º 3
0
int chess_doing(void)
{
	int	rx = (mx-ST_X) % SPACE;
	int	ry = (my-ST_Y) % SPACE;
	int cx = mx - rx;
	int cy = my - ry;

	if ((mx < ST_X) || (mx > (ST_X+(X_NUM-1)*SPACE))) 
	{
		return 0;
	}

	if ((my < ST_Y) || (my > (ST_Y+(Y_NUM-1)*SPACE))) 
	{
		return 0;
	}

	if (rx > (SPACE/2)) 
	{
		cx += SPACE;
	}

	if (ry > (SPACE/2)) 
	{
		cy += SPACE;
	}
	
	fb_circle(cx, cy, 13, 0x00ff0000);

	return 0;
}
Ejemplo n.º 4
0
int print_one_chess(int x, int y)
{
	int c_x = x;
	int c_y = y;

	if((x < 100) || (x > (30*29+100)))
	{
		choose_color(x, y);
		return 1;	
	}
	if((y < 40) || (y > (30*23+40)))
	{
		choose_color(x, y);
		return 1;
	}

	x = (x-100)%30;
	y = (y-40)%30;

	c_x += ((x>15) ? (30-x) : -x);
	c_y += ((y>15) ? (30-y) : -y);

	fb_circle(c_x, c_y, 13, color_choice);

	return 0;
}
Ejemplo n.º 5
0
int recv_msg(void)
{

    int i = 0,j = 0;
    server_len = sizeof(server);

    recvfrom(client_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&server, &server_len);
    memcpy((char*)&i,(char *)&buffer[4],4);
    memcpy((char*)&j,(char *)&buffer[8],4);

    printf("%d %d\n",i,j);
    fb_circle(X_BEGUN+i*SIZE, Y_BEGUN+j*SIZE, 12, 0xffffffff);
    board[i+j*V_NUM]  = 2;

    check_all();
    return 0;
}
Ejemplo n.º 6
0
/**********************************************************
 *函数功能:放棋子在棋盘内的交叉点
 *
 *
 ********************************************************/
int chess_doing(void)
{
  /*  int rx = (mx-ST_X)%SPACE;
    int ry = (my-ST_Y)%SPACE;
    int cx = mx - rx;
    int cy = my - ry;*/
    if((mx < ST_X)||(mx > (ST_X + (X_NUM-1)*SPACE))||(my < ST_Y)||(my > (ST_Y + (Y_NUM-1)*SPACE)) )
    {
        return 0;
    }
  /*  if(rx > SPACE/2)
    {
        cx += SPACE;
    }
    if(ry > SPACE/2)
    {
        cy += SPACE;
    }
    fb_circle(cx,cy,8,0x00ff0000);*/
    int rx = (mx+15-ST_X)%SPACE;
    int ry = (my+15-ST_Y)%SPACE;
    int cx = mx+15 - rx;
    int cy = my+15 - ry;
    int flag = 0;
    fb_circle(cx,cy,8,current_color);
     flag =  chess_put((cx-ST_X)/SPACE,(cy-ST_Y)/SPACE);
     if(flag > 0)  // 判断是否有满足五个点
     {
        return flag;
     }
    if(current_color == BLACK)   //放了一个棋子后, 交换棋子的颜色
    {
        current_color = WHITE;
        player = 2;
    }
    else
    {
        current_color = BLACK;
        player = 1;
    }
    return 0;
}
Ejemplo n.º 7
0
int main(int argc, const char *argv[])
{
    init_data();                              
    print_board();
    mouse_doing();
//    save_bg(500, 300);
//    draw_cursor(500, 300);
//    sleep(1);
//    restore_bg(500, 300);
//    draw_cursor(600, 500);
#if 0 
    int i, j;
    for (i = 0; i < 100; i++)                       /*纵坐标*/
    {
        for (j = 0; j < 100; j++)                   /*横坐标*/ 
        {
            fb_one_pixel(500 + j, 300 + i, 0x0000ff00);
        }
    }
#endif
//    fb_line(0, 0, fb_v.w-1, fb_v.h-1, 0x00ff0000);   
//    fb_line(fb_v.w-1, 0, 0, fb_v.h-1, 0x00ff0000);
//    fb_line(300, fb_v.h-1, 500, 0, 0x0000ff00);
//    fb_line(0, 0, fb_v.w-1, 0, 0x00ffffff);
//    fb_line(0, 0, 0, fb_v.h-1, 0x00ffffff);
//    fb_line(fb_v.w-1, fb_v.h-1, fb_v.w-1, 0, 0x00ffffff);
//    fb_line(fb_v.w-1, fb_v.h-1, 0, fb_v.h-1, 0x00ffffff);
//      fb_circle(500, 300, 300, 0x00ff0000);
#if 1
    int i;
    for (i = 0; i < fb_v.w; i++)
    {
        fb_line(0, 0+i*30, fb_v.w-1, 0+i*30, 0x00ffffff);
    }

    printf("location:\n");
    scanf("%d",&i);

    fb_circle(st_x+i*space, st_y+i*space, 10, 0x0000ff00);
#endif
    return 0;
}
Ejemplo n.º 8
0
int chess_doing(void)
{
	int rx = (mx-ST_X)%SPACE;
	int ry = (my-ST_Y)%SPACE;
	int cx = mx - rx;
	int cy = my - ry;

	if((mx < ST_X) || (mx > (ST_X+(X_NUM-1)*SPACE)))
	{
		return 0;
	}
	if((my < ST_Y) || (my > (ST_Y+(Y_NUM-1)*SPACE)))
	{
		return 0;
	}
	if(rx > (SPACE/2))
	{
		cx += SPACE;	
	}
	if(ry > (SPACE/2))
	{
		cy += SPACE;
	}
	fb_circle(cx, cy, 13, current_color); //画棋子
	chess_put((cx-ST_X)/SPACE, (cy-ST_Y)/SPACE); //找坐标
	if(current_color == WHITE)
	{
		current_color = BLACK;
		player = 1;
	}
	else
	{
		current_color = WHITE;
		player = 2;
	}

	return 0;
}
Ejemplo n.º 9
0
void main(void)
{
    FBDEV fbdev;
    memset(&fbdev,0,sizeof(FBDEV));
    strcpy(fbdev.dev,"/dev/fb0");
    if (fb_open(&fbdev) == FALSE) 
    {
        printf("open frame buffer error\n");
        return ;
    }
    fb_memset((void *)(fbdev.fb_mem + fbdev.fb_mem_offset),0,fbdev.fb_fix.smem_len);
    //画点得函数:
    fb_drawpixel(&fbdev,512,384,0x00ff0000);
    fb_drawpixel(&fbdev,513,384,0x00ff0000);
    fb_drawpixel(&fbdev,512,385,0x00ff0000);
    fb_drawpixel(&fbdev,513,385,0x00ff0000);
    //画直线得函数:
    //fb_drawline(&fbdev,200,100,0x0000ff00);
    fb_line(&fbdev,100,200,300,500,0x000000ff);
    fb_circle(&fbdev,512,348,50,0x00ff0000);
    fb_close(&fbdev);
    getchar();
}
Ejemplo n.º 10
0
void recv_msg(void)
{
  
    client_len = sizeof(client);
    len = recvfrom(server_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&client, &client_len);
    if (len >= 0)
    {
       cx = p->x;
       cy = p->y;
       board[cx+cy*P_NUM] = 2;

       printf("%d\n",cx);
       printf("%d\n",cy);

       cx = (cx)*SIZE + X_BEGUN;    
       cy = (cy)*SIZE + Y_BEGUN;    

       color_choice = 0x01000000;  

       fb_circle(cx,cy, 12, 0xffffffff);
       check_all();
    }
    
}
Ejemplo n.º 11
0
int chess_do(void)
{
    int x = mx;
    int y = my;

    int lx = 0;
    int ly = 0;

    int winner = 0;

    if (flag == 0) 
    {
        print_board(GRAY, YELLOW);
        flag = 0xff;
        return 0;
    }

    if (x < ST_X || (x > ST_X + SPACE * (B_X -1)))      // change the player and color
    {
        if ((x > 42) && (x < 78) && (y > 82) && (y < 118)) 
        {
            current_color = BLACK;
            current_player = 1;
        }
        else if ((x > 42) && (x < 78) && (y > 182) && (y < 218)) 
        {
            current_color = WHITE;
            current_player = 2;
        }
        return 0;
    }
    if (y < ST_Y || (y > ST_Y + SPACE * (B_Y -1))) 
    {
        return 0;
    }

    x = (x - ST_X) % SPACE;
    y = (y - ST_Y) % SPACE;

    if (x < (SPACE / 2)) 
    {
        x = mx - x;
    }
    else 
    {
        x = mx + (SPACE - x);
    }
    if (y < (SPACE / 2)) 
    {
        y = my - y;
    }
    else 
    {
        y = my + (SPACE - y);
    }

    lx = (x - ST_X) / SPACE;
    ly = (y - ST_Y) / SPACE;

    chess_board[lx + ly * B_X] = current_player;
    fb_circle(x, y, 13, current_color);

    winner = check_win();
    if (winner > 0) 
    {
        write_world(50, 300, winner);
        return winner;
    }

    return 0;
}
Ejemplo n.º 12
0
int print_choice(void)
{
    fb_circle(40,60,20,0);
    fb_circle(10,140,20,0x00ffffff);
    return 0;
}
Ejemplo n.º 13
0
int chess_do(void)
{
    int x = mx;
    int y = my;

    int lx = 0;
    int ly = 0;
    int winner = 0;

    if (flag == 0) 
    {
        print_board();
        flag = 0xff;
        return 0;
    }

    if (x < ST_X || (x > ST_X+SPACE*(B_X-1))) 
    {
        if ((x > 42) && (x < 78) && (y > 82) && (y < 118))
        {
            current_color = BLACK;
            current_player = 1;//逻辑切换
            
        }
        else if((x > 42) && (x < 78) && (y > 182) && (y < 218))
        {
            current_color = WHITE;    
            current_player = 2;
        }
        return 0;
    }
    if (y < ST_Y || (y > ST_Y+SPACE*(B_Y-1))) 
    {
        return 0;
    }

    x = (x-ST_X) % SPACE;
    y = (y-ST_Y) % SPACE;
    if (x < (SPACE/2)) 
    {
        x = mx -x;
    }
    else
    {   
      x =  mx+(SPACE-x);
    }
    if (y < (SPACE/2)) 
    {
        y = my -y;
    }
    else
    {
        y = my+(SPACE-y);
    }

    lx = (x - ST_X)/SPACE;
    ly = (y - ST_Y)/SPACE;

    chess_board[lx + ly*B_X] = current_player;//指示who
    fb_circle(x, y, 13, current_color);
    
    winner = check_win();
    if (winner > 0)
    {
        printf("player %d won!\n", winner);        
//        fb_circle(512,350,300,0x0000ff00);
        return winner;

    }
    
    return 0;
}