展开全部
按方向键移动,按Esc退出
#include<stdio.h>
#include<bios.h>
#include<conio.h>
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ESC 0x11b
void main()
{
int l=15,r=35,u=10,d=18,x,y,key;
void frame(int,int,int,int);
void move(int,int *,int *,int *,int *,int *,int *);
clrscr();
x=(l+r)/2;
y=(u+d)/2;
textcolor(YELLOW);
frame(l,r,u,d);
gotoxy(x,y);
cprintf("%c",1);
key=bioskey(0);
while(key!=ESC)
{
move(key,&x,&y,&l,&r,&u,&d);
key=bioskey(0);
}
}
void frame(int l,int r,int u,int d)
{
int i;
for(i=l;i<r+1;i++)
{
gotoxy(i,u);
printf("%c",219);
gotoxy(i,d);
printf("%c",219);
}
for(i=u+1;i<d+1;i++)
{
gotoxy(l,i);
printf("%c",219);
gotoxy(r,i);
printf("%c",219);
}
}
void move(int key,int *x,int *y,int *l,int *r,int *u,int *d)
{
gotoxy(*x,*y);
putchar(32);
if(key==UP)
{
if(*y==*u+1)*y=*d-1;
else (*y)--;
}
if(key==DOWN)
{
if(*y==*d-1)*y=*u+1;
else (*y)++;
}
if(key==LEFT)
{
if(*x==*l+1)*x=*r-1;
else (*x)--;
}
if(key==RIGHT)
{
if(*x==*r-1)*x=*l+1;
else (*x)++;
}
gotoxy(*x,*y);
putchar(1);
}
#include<stdio.h>
#include<bios.h>
#include<conio.h>
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ESC 0x11b
void main()
{
int l=15,r=35,u=10,d=18,x,y,key;
void frame(int,int,int,int);
void move(int,int *,int *,int *,int *,int *,int *);
clrscr();
x=(l+r)/2;
y=(u+d)/2;
textcolor(YELLOW);
frame(l,r,u,d);
gotoxy(x,y);
cprintf("%c",1);
key=bioskey(0);
while(key!=ESC)
{
move(key,&x,&y,&l,&r,&u,&d);
key=bioskey(0);
}
}
void frame(int l,int r,int u,int d)
{
int i;
for(i=l;i<r+1;i++)
{
gotoxy(i,u);
printf("%c",219);
gotoxy(i,d);
printf("%c",219);
}
for(i=u+1;i<d+1;i++)
{
gotoxy(l,i);
printf("%c",219);
gotoxy(r,i);
printf("%c",219);
}
}
void move(int key,int *x,int *y,int *l,int *r,int *u,int *d)
{
gotoxy(*x,*y);
putchar(32);
if(key==UP)
{
if(*y==*u+1)*y=*d-1;
else (*y)--;
}
if(key==DOWN)
{
if(*y==*d-1)*y=*u+1;
else (*y)++;
}
if(key==LEFT)
{
if(*x==*l+1)*x=*r-1;
else (*x)--;
}
if(key==RIGHT)
{
if(*x==*r-1)*x=*l+1;
else (*x)++;
}
gotoxy(*x,*y);
putchar(1);
}
展开全部
#include<stdio.h>
#include <Windows.h>
struct move_point
{
int x,y;
int xv,yv;
}man;
void gotoxy(int x, int y) //x为列坐标,y为行坐标
{
COORD pos = {x,y};//定义坐标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);//设置一个句柄
SetConsoleCursorPosition(hOut, pos);
}
void main()
{
int i;
gotoxy(10, 10);
printf("%c", 2);
for(i = 0; i < 40; i++)
{
gotoxy(10 + i, 10);
printf(" ");
printf("%c", 2);
Sleep(100);
}
}
#include <Windows.h>
struct move_point
{
int x,y;
int xv,yv;
}man;
void gotoxy(int x, int y) //x为列坐标,y为行坐标
{
COORD pos = {x,y};//定义坐标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);//设置一个句柄
SetConsoleCursorPosition(hOut, pos);
}
void main()
{
int i;
gotoxy(10, 10);
printf("%c", 2);
for(i = 0; i < 40; i++)
{
gotoxy(10 + i, 10);
printf(" ");
printf("%c", 2);
Sleep(100);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询