学习笔记 c语言控制台 简单程序 游戏1024

#include
#include 
#include 

#define width 16
bool operating(int ch,int *value);
void show(int * value);
void init(int *value);
int main(void)
{
    int value[16] = {0};
    printf("%d\n",value);           //声明单元值
    init(value);
    int ch;                      //声明输入操作变量
    while(getch() != 27)       //循环开始
    {

            ch = getch();
            if(ch ==27)
            {
                return 0;
            }
            operating(ch,value);
            system("cls");
            show(value);

    }
    return 0;
}
bool operating(int ch,int *value)
{
    int team,member,initial_value;
    switch(ch)                              //方向与规律
    {
        case 75:{team = 4;member = 1;initial_value = 0;break;}
        case 72:{team = 1;member = 4;initial_value = 0;break;}
        case 77:{team = 4;member = -1;initial_value= 3;break;}
        case 80:{team = 1;member= -4;initial_value = 12;break;}
        default:puts("error");
    }
    for(int x =0;x<4;x++)
    {
        move(initial_value+x*team,member,value);
    }
    int a;
    while(1)                            //随机位置产生一个“2”值
    {
        a = rand()%16;
        if(value[a] == 0)
        {
            value[a] =2;
            break;
        }
    }
}
void move(int position,int displacement,int *value)
{
    for(int x =0;x<4;x++)                               //先移动值
    {
        if(value[position+displacement*x] != 0)
        {
            for(int y = 0;ymax_value)
        {
            max_value = value[x];
        }
        max_num += value[x];
    }
    printf("总分%d \n最高分%d",max_num,max_value);
}
简单版本   由于不会 没有测试

你可能感兴趣的:(学习列子)