#include<windows.h>
#include<conio.h>
#include<stdio.h>
#include<iostream>
#include<assert.h>
#include<ctype.h>
#include<limits.h>
using namespace std;
#define ROWSIZE 15
#define COLSIZE 30
struct LetterType
{
char ch;
int row;
int col;
};
void Show_Letter(LetterType *p)
{
assert(p != NULL);
system("cls");
for (int i = 0; i < ROWSIZE; ++i)
{
if (i == p->row)
{
for (int j = 0; j < p->col; ++j)
{
printf("%c", ' ');
}
printf("%c
", p->ch);
}
else
{
printf("
");
}
}
}
int main()
{
LetterType let = { 'a',0,5 };
char ch;
for (;;)
{
Show_Letter(&let);
Sleep(1000);
if (kbhit())
{
ch = getch();
if (let.ch == ch)
{
int tag = rand() % 2 + 1;
if (tag == 1)
{
let.ch = rand() % 26 + 'a';
}
else
{
let.ch = rand() % 26 + 'A';
}
let.row = -1;
let.col = rand() % COLSIZE;
}
}
let.row += 1;
if (let.row > ROWSIZE)
{
printf("over
");
exit(0);
}
}
return 0;
}