#include<stdio.h> #include<string.h> #include<windows.h> #include<time.h> #include<conio.h>
#define up 'w' #define down 's' #define left 'a' #define right 'd' #define space 'q' #define slow 'e'
void gotoxy(int x, int y); int ClickControl(); void moveobject(); void food(); int color(int c); void border(); void wall(); //srand((unsigned)time(0));
int j,i,k,click,length=5; int _time=100000000; typedef struct Snake { int x; int y; struct Snake *next; }snake; snake s={15,15}; snake *head; snake ss[100];
main() {
// printf(" 0"); }
// printf(""); printf("⊙"); } } gotoxy(68,3); printf("你的得分是:%d",length*100-500); // system("cls"); for(i=0;i<_time;i++); for(i=0;i<length;i++) { gotoxy(ss[i].x,ss[i].y); printf(" "); } // _time=100000000; } }
void gotoxy(int x, int y) { COORD pos; HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); pos.X = x; pos.Y = y; SetConsoleCursorPosition(hOutput, pos);
}
void moveobject() { int x,y; x=ss[0].x; y=ss[0].y;
}
int ClickControl() { char c; while (1) { if (_kbhit() == 0) return 0; if (_kbhit()) { click = _getch(); } moveobject(); } return 1; }
void food() { int static foodx,foody,h_food=0; srand((unsigned)time(0)); if(!h_food) { foodx=rand()%29*2+3; foody=rand()%25+1; gotoxy(foodx,foody); // printf("■"); h_food=1; } gotoxy(foodx,foody); color(4); printf("■"); for(i=0;i<length;i++) if(ss[i].xfoodx&&ss[i].yfoody) { length+=1; h_food=0; } }
int color(int c) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); //更改文字颜色 return 0; }
void border() { if(head->x<=1) head->x=61; else if(head->x>=61) head->x=1; if(head->y<=0) head->y=28; else if(head->y>=28) head->y=0; }
void wall() { color(5); gotoxy(0,0); for(i=0;i<=61;i+=2) { printf("■"); } gotoxy(0,28); for(i=0;i<=61;i+=2) { printf("■"); } for(i=0;i<=28;i++) { gotoxy(0,i); printf("■"); } for(i=0;i<=28;i++) { gotoxy(62,i); printf("■"); } }