编写这个程序也是一步一步慢慢想。从解决每一个关键问题做起。
第一步:turbo c下实现一个星号的移动:
功能内容:在从键盘键入下一个方向前,星号一直按前一个键入的方向前进,直到键盘键入新的方向才改变运行方向。
#include<stdio.h>
#include<stdlib.h>
#include<bios.h>
#define TIME 100
#define MAXSIZE 3
#define KEY_UP 0x4800
#define KEY_DOWN 0x5000
#define KEY_LEFT 0x4b00
#define KEY_RIGHT 0x4d00
typedef struct Address{
int col;
int row;
}Address;
void showSnack(Address locate);
void moveSnack(Address locate);
void moveSnack(Address locate) {
int key;
int i;
char Aste[MAXSIZE];
strcpy(Aste,"***");
key = bioskey(0);
while(283 != key) {
if(KEY_UP == key) {
while(!bioskey(1)) {
gotoxy(locate.col,locate.row);
cprintf(" ");
if(0 == locate.row) {
cprintf("Die!");
break;
}
locate.row--;
gotoxy(locate.col,locate.row);
for(i=0;i<MAXSIZE;i++) {
cprintf("%s",Aste[i]);
}
delay(TIM