问一下,怎么达到这个效果?

来源:百度知道 编辑:UC知道 时间:2024/06/28 09:38:01
当老鼠吃到粮食后,要统计吃到的粮食数sc,并且要把成绩显示在第一行上。若吃满20粒粮食时。还要在屏幕中央显示” mouse win!”。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
main()
{ int cx,cy, x, y, fx, fy, n, kb, r=0, sc=0;
int set[25][41]={0},mx[5]={0,1,0,-1,0},my[5]={0,0,-1,0,1};
clrscr(); textmode(C40); randomize(); n=0;
while (n<50)
{
fy=rand()%23+2;
fx=rand()%40+1;
set[fy][fx]=1;
gotoxy(fx,fy);putch('.');
n++;
}
gotoxy(30,1); printf("SCORE=%d",sc);
cx=2; cy=2; gotoxy(cx, cy); putch('&');
x=39; y=23; gotoxy(x,y); putch('@');
while(1)
{
delay(32000);
if(kbhit())
{ kb=getch();
if(kb == 27) exit(0);
if(kb == 0)
{ kb=getch();
if(kb == 77) r=1;
if(kb == 72) r=2;
if(kb == 75) r=3;
if(kb == 80

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
main()
{ int cx,cy, x, y, fx, fy, n, kb, r=0, sc=0;
int set[25][41]={0},mx[5]={0,1,0,-1,0},my[5]={0,0,-1,0,1};
clrscr(); textmode(C40); randomize(); n=0;
while (n<50)
{
fy=rand()%23+2;
fx=rand()%40+1;
set[fy][fx]=1;
gotoxy(fx,fy);putch('.');
n++;
}
gotoxy(30,1); printf("SCORE=%d",sc);
cx=2; cy=2; gotoxy(cx, cy); putch('&');
x=39; y=23; gotoxy(x,y); putch('@');
while(1)
{
r=0;/*我觉得如果要屏蔽掉其它键造成的移动,最好添上这一句*/
delay(32000);
if(kbhit())
{ kb=getch();
if(kb == 27) exit(0);
if(kb == 0)
{ kb=getch();
if(kb == 77) r=1;
if(kb == 72) r=2;
if(kb == 75) r=3;
if(kb == 80) r=4;
gotoxy(x,y); putch(' ');
}
x=x+mx[r] ; y=y+my[r] ;
if(x<1 || x>40) x=x-mx[r]; if(y<2 || y>24) y=y