C语言牛人进!!! 白拿分咯 帮忙!

来源:百度知道 编辑:UC知道 时间:2024/09/24 04:15:24
我是C语言初学者 学期末要写一个大一点的程序 各位牛人帮我!
首先我自己写了个FUNCTION,能生成一个2D数组, 自定行,列,但第一个元素必须是X,例 行5,列7(行列范围为(6-24)
数组中元素最多有9种(1-9) 最少4种(1-4)不能为0;
X 3 4 6 7 3 4
1 3 6 8 4 3 2
2 3 3 3 5 7 3
2 5 8 4 8 9 3
3 6 3 8 5 2 9
void printarray(int array[25][25], int row, int col,int color) {
int a,b;
for (a=0; a < row; a++)
for(b=0;b<col;b++)
{
array[a][b]=rand()%(color-1)+1;

printf("%d ",array[a][b]);
if((b+1)%col==0)
printf("\n");
}
return;
}

这个游戏的要求是 已知生成的随即数组,然后输入一个数,如果这个数和X旁边(上下左右)的数相等,则把那个数吃掉,一直吃到不相等为止 例 输入数字3 上面的数组则变为:
X X 4 6 7 3 4
1 X 6 8 4 3 2
2 X X X 5 7 3
2 5 8 4 8 9 3
3 6 3 8 5 2 9
直到屏幕上全是X时 游戏结束.过程中要统计一共输入了多少次数字.并且保证游戏一定能被完成!
请各位牛人帮我写个符合要求的FUNCTION(函数)出来.
我QQ 396602081
E-mail: joseph.wang@utoronto.ca
wangjianyu3@hotmail.com
有什么我

#include<stdio.h>//算了,我把完整代码写出来了
#include<math.h>
#include<time.h>
#include<stdlib.h>
void printarray(int array[25][25], int row, int col,int color) {
int a,b;
srand(time(NULL));
for (a=0; a < row; a++)
for(b=0;b<col;b++)
{
array[a][b]=(rand()+a*3+b*7)%(color-1)+1;

printf("%d ",array[a][b]);
if((b+1)%col==0)
printf("\n");
}
}

void startGame(int arr[25][25],int row,int col,int color)
{int i,j,t,flag,count;
count=0;
arr[0][0]=-1; //用-1代表x
do
{flag=0; //初试flag为0,如矩阵全为-1则程序结束
printf("Input a number:(1~%d,exit=-1)\n",color-1); //输入-1强制推出
scanf("%d",&t);
if(t>=color)
{printf("invalid input,enter a small one(the number needs < %d)\n",color);
continue;}
count++;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{if(arr[i][j]==-1)
{if(i