C language graduation thesis of seeking snakes
# Contains? & ltstdio.h & gt# contains? 450){ snake . x[0]= 50; /* If the snakehead crosses the right boundary, the snakehead enters from the left boundary */snake.y [0] = snake.y [0]; /* The ordinate is unchanged */for (I = snake. node-1; I>0; I-){ snake . x[I]= snake . x[I- 1]; snake . y[I]= snake . y[I- 1]; ? /* Other sections of the snake */}{setfillstyle(SOLID_FILL, 0); ? /* Set the filling mode and color, where 0 means black */bar (50,55,455,315); /*bar is the function */}} else if (snake.y [0] < 60) {snake.y [0] = 320; /* If the snakehead crosses the upper boundary, it will enter from the lower boundary */snake.x [0] = snake.x [0]; /* The abscissa remains unchanged */for (I = snake. node-1; I>0; I-){ snake . x[I]= snake . x[I- 1]; snake . y[I]= snake . y[I- 1]; ? /* Other sections of the snake */}{setfillstyle(SOLID_FILL, 0); ? /* Set the filling mode and color, where 0 means black */bar (50,55,455,315); /*bar is a function */}} else if (snake.y [0] > 320){ snake . y[0]= 60; /* If the snake head crosses the lower boundary, it will enter from the upper boundary */snake.x [0] = snake.x [0]; /* The abscissa remains unchanged */for (I = snake. node-1; I>0; I-){ snake . x[I]= snake . x[I- 1]; snake . y[I]= snake . y[I- 1]; ? /* Other sections of the snake */}{setfillstyle(SOLID_FILL, 0); ? /* Set the filling mode and color, where 0 means black */bar (50,55,455,315); /*bar is a function indicating the filling range */} if (snake. life = =1)/* If the snake dies, jump out of the inner loop and start again */break; if(snake . x[0]= = food . x & amp; & snake.y [0] = = food.y)/* After dinner */{set color (0); /* Remove food from the picture */rectangle (food.x, food.y, food.x+ 10, food.y-10); ? /* Draw a rectangle with the current line type and color */snake.x [snake.node] =-20; snake . y[snake . node]=-20; /* Put the new section in an invisible position first, and take the position of the previous section in the next cycle */snake.node++; /* The snake has a long body */food. Yes =1; /* New food needs to appear on the screen */score+=10; ? /* Every time you eat food, the score accumulates to 10 */if (score%100 = = 0) {level++; Gamespeed = 100000-400 * level -300 * level * level; /* Every time you eat 10 food, you will be promoted by one level and the speed will be accelerated */prscore (); /* Output new score */setcolor (yellow); ? /* Set the font color */settextstyle (0,0,4); ? /* Set the font type */outtextxy (150,200, "Level? UP”); ? /* display text */if (level = =10) {level =1,gamespeed =100000-400 * level-300 * level * level; } delay (6000000); ? Delay (6000000); ? Delay (6000000); ? Delay (6000000); ? Delay (6000000); Delay (6000000); ? Delay (6000000); bar(50,55,455,3 15); /*bar is a function indicating the filling range */} prscore (); /* Output new score */? }? set color(4); /* Draw a snake */? for(I = 0; I < snake. node; i++)? Rectangular (snake.x[i], snake.y[i], snake.x[i]+ 10,? snake . y[I]- 10); ? Game speed; ? /* control the game speed */setcolor (0); rectangle(snake . x[snake . node- 1],snake.y[snake.node- 1],? snake . x[snake . node- 1]+ 10,snake . y[snake . node- 1]- 10); ? }? /*endwhile(! kbhit)*/? /* Remove the last paragraph of the snake in black */? If(snake.life== 1)/* If the snake dies, jump out of the loop */? Break; ? key = BIOS key(0); /* Receive button */? If(key==ESC)/* Press ESC to exit */? Break; ? Or what? if(key = = UP & amp; & Snake, direction! =4)? /* Judge whether to move in the opposite direction */? snake . direction = 3; ? Or what? if(key = = RIGHT & amp; & Snake, direction! =2)? snake . direction = 1; ? Or what? if(key = = LEFT & amp; & Snake, direction! = 1)? snake . direction = 2; ? Or what? if(key = = DOWN & amp; & Snake, direction! =3)? snake . direction = 4; ? }/*endwhile( 1)*/? }? /* Game over */? Invalid? GameOver(void)? {? clear device(); ? /* clear screen */prscore (); ? Setcolor (red); ? /* Set the font color */settextstyle (0,0,4); ? /* Set the font type */outtextxy (200,200, "Game? Over "); ? /* Display text */getch (); ? }? /* Output results and game level */? Invalid? PrScore(void)? {? Charles? str 1[20]; /* Set character array */? setfillstyle(SOLID_FILL,0); ? Ba (50,15,390,35); ? /* Fill the rectangular box */setcolor (6); ? /* Set the text color */settextstyle (0,0,2); ? /* Set the array display position */sprintf(str 1, "score? %d? Level? %d ",score, grade); /* Display the contents of the array */outtextxy (55,20, str1); ? Setcolor (yellow); ? /* Set the font color */settextstyle (0,0,2); ? /* Set the font type */outtextxy (250,400, "EXIT=ESC?" ); /* Display text */}? Invalid? Close (void)? {? closegraph(); ? }