求助:在C语言下怎么改字符颜色?随机颜色
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<windows.h>
void Print(int screen[25][80])//,int color[10],int star[10])
{
int i,j;
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(screen[i][j]!=0&&screen[i][j]!=-1)
{
printf("%c",'A'+screen[i][j]-1);
}
else if(screen[i][j]==-1)
printf("#");
else
printf(" ");
}
void End(int screen[25][80])
{
int i,j;
for(i=19;i<25;i++)
for(j=0;j<80;j++)
if(screen[i][j]==-1)
break;
if(i==25&&j==80)
exit(0);
}
void main()
{
int speed[10],dir[10],x[10],y[10],star[10];//速度
int i,j;
int screen[25][80]={0};
srand((int)time(0));// srand初始化随机种子rand产生随机数
for(i=19;i<25;i++)
for(j=0;j<80;j++)
screen[i][j] = -1;
for(i=0;i<10;i++)
{
x[i]=0;y[i]=rand()%80;
speed[i]=rand()%2+1;
dir[i]=rand()%5-2;
star[i] = rand()%26+1;//流星的产生
}
while(1)
{
for(i=0;i<10;i++)
screen[x[i]][y[i]] = star[i];
Print(screen);
for(i=0;i<10;i++)
screen[x[i]][y[i]] = 0;
Sleep(1);
system("cls");//清屏
for(i=0;i<10;i++)
{
x[i] += speed[i];
y[i] += dir[i];
if( y[i]>=80||y[i]<0||x[i]>=25 || screen[x[i]][y[i]]==-1)
{
if(screen[x[i]][y[i]]==-1&&y[i]>0&&y[i]<=80&&x[i]<25)
screen[x[i]][y[i]] = 0;
x[i]=0;y[i]=rand()%80;
speed[i]=rand()%2+1;
dir[i]=rand()%5-2;
star[i] = rand()%26+1;
}
}
End(screen);
// for(i=0;i<10;i++)
// screen[x[i]][y[i]] = 1;
}
}
给它加上颜色。。VC 6.0上