linux控制台下实现2048小游戏

2019-10-14 10:57:09于丽

        //arr[arr1[j][0]][arr1[j][1]]=2;
      }
    else
        arr[arr1[j][0]][arr1[j][1]]=2;
}
int mov_left()
{
    int count=0;
    count=mov_l()+count;
    count=sum_2048_l()+count;
    if(count==-2)
        print_appear_flag=1;
    mov_l();
    ran_appear();
    print_num();
    return 0;
}
int mov_right()
{
    int count=0;
    count=mov_r()+count;
    count=sum_2048_r()+count;
    if(count==-2)
        print_appear_flag=1;
    mov_r();
    ran_appear();
    print_num();
    return 0;
}
int mov_up()
{
    int count=0;
    count=mov_u()+count;
    count=sum_2048_u()+count;
    if(count==-2)
        print_appear_flag=1;
    mov_u();
    ran_appear();
    print_num();
    return 0;
}
int mov_down()
{
    int count=0;
    count=mov_d()+count;
    count=sum_2048_d()+count;
    if(count==-2)
        print_appear_flag=1;
    mov_d();
    ran_appear();
    print_num();
    return 0;
}
int swap(int *a,int *b)
{
    int tmp;
    tmp=*a;
    *a=*b;
    *b=tmp;
}
int mov_l()
{
    int line,row;
    int i=3;
    int count=0;
    while(i--)
    {
        for(line=0;line<4;line++)
         for(row=0;row<3;row++)
        {
            if(arr[line][row]==0&&arr[line][row+1]!=0)
            {  
                swap(&arr[line][row],&arr[line][row+1]);
                count++;
                print_appear_flag=0;