谢谢大神们了~
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
using namespace std;
#define N 20
#define M 40
#define S 100
void sleep(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
void prtcm(char(*p)[M])
{
int i,j;
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
cout<<p[i][j];
}
cout<<endl;
}
}
int main()
{
char cm[N][M];
int i,j;
char ch,k;
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
cm[i][j]=' ';
}
}
while(1)
{
ch=rand()%26+'A';
j=rand()%M;
i=0;
while(i<N)
{
cm[i][j]=ch;
if(_kbhit())
{
k=getch();
if(k==ch||k==ch+32)
{
cm[i][j]=' ';
system("cls");
prtcm(cm);
break;
}
}
system("cls");
prtcm(cm);
sleep(S);
cm[i][j]=' ';
i++;
}
}
return 0;
}
...加注释 发到邮箱里【strivation@gmail.com】
void sleep(unsigned int mseconds)\/\/自定义延时函数 参数为 无符号整型 { clock_t goal; \/\/声明goal 以备计时用 goal = mseconds + clock(); \/\/当前计时单元加参数 while (goal > clock()); \/\/当前计时单元是否大于goal } void prtcm(char(*p)[M])\/\/自定义打印函数,参数为字符指针数...