分模块
// 用函数模块化对 2048 进行重构 下面是项目经历 列出函数原型
// void rand_map(); //在二维数组中随机位置产生一个2
// void show_map(); //显示
// void up();// 向上移动
// void down ();// 向下移动
// void left();// 向左移动
// void right();// 向右移动
int isfull(); //判断游戏是否满了 该结束
上面的函数都要访问4*4 的二维数组 将二维数组声明全局
// 二维数组
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int a[4][4] = {
0};
int i = 0, j = 0;
int c=0;
int score=0;
int x;
int y;
// int isfull(); //判断游戏是否满了 该结束
int isfull(){
int b;
int t=0;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(a[i][j]==0){
t=1;
}
if(a[i][j]==2048){
b=1;
}
}
}
if(b==1){
printf("you are winer");
return -1;
}
if(t==0){
printf("game over");
return 0;
}
}
// void rand_map(); //在二维数组中随机位置产生一个2
void rand_map(){
// //在此位置补充代码 使得数组某个随机的位置 赋值为2
//
// int s = time(0);
//
//
// srand(s); // 将 s 作为 rand 函数的种子值
// int x;
// int y;
// x= rand() % 4 ;
// y = rand() % 4 ;;
// a[x][y]=2;
do{
x = rand() % 4 ;
y = rand() % 4 ;
}while(a[x][y]!=0)