⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yqp.cpp

📁 C++写的
💻 CPP
字号:
#include "yqp.h"
void CSnake::init(void)
{

int i;
for(i=0;i<MAX;i++)
{
   place[i].x  = 0;
   place[i].y  = 0;
   place[i].st = FALSE;
   place[i].dir = 0;
   place[i].c = 0;
}
   control = 4;
   place[0].st = TRUE;
   place[0].dir = control;
   place[0].x = 1;
   place[0].y = 1;
   place[1].st = TRUE;
   place[1].dir = control;
   place[1].y = 2;
   place[1].x  = 2;
   keydown = FALSE;
   speed = 9;
   count = 0;
   score = 0;
   level = 1;
   head = 1;
   tear = 0;
   x = 1;
   y = 0;
   babyx = rand()%MAXX;
   babyy = rand()%MAXY;
   eat = FALSE;
   game = GAMESTART;
}
void CSnake::nextstatus(void)
{
int i;
int exit;
keydown = FALSE;
if (game != GAMESTART) return;
   if (place[head].dir != control)
   {
	   if ( (place[head].dir == 1) && (control == 3) )  place[head].c = 2;
	   if ( (place[head].dir == 1) && (control == 4) )  place[head].c = 4;
	   if ( (place[head].dir == 2) && (control == 3) )  place[head].c = 3;
	   if ( (place[head].dir == 2) && (control == 4) )  place[head].c = 1;
	   if ( (place[head].dir == 3) && (control == 1) )  place[head].c = 1;
	   if ( (place[head].dir == 3) && (control == 2) )  place[head].c = 4;
	   if ( (place[head].dir == 4) && (control == 1) )  place[head].c = 3;
	   if ( (place[head].dir == 4) && (control == 2) )  place[head].c = 2;

	   place[head].dir = control;
   }
   
   switch(control)
   {
   case 1: y--; break;
   case 2: y++; break;
   case 3: x--; break;
   case 4: x++; break;
   default: return;
   }


   if ( (y < 0) ||(y >= MAXY) ||
	(x < 0) ||(x >= MAXX) )
      {
      game = GAMEOVER;
      control = 0;
      return;
      }
   for (i = 0; i < MAX; i++)
     if ((place[i].st) &&
        (x == place[i].x) &&
        (y == place[i].y) )
        {
        game = GAMEOVER;
        control = 0;
        return;
        }
   if ( (x == babyx) && (y == babyy) )
   {
      eat = TRUE;
      count ++;
      score += (1+level) * 10;
   }

   head ++;
   if (head >= MAX) head = 0;
   place[head].x = x;
   place[head].y = y;
   place[head].st= TRUE;
   place[head].dir = control;
   if (eat == FALSE)
   {
      place[tear].st = FALSE;
	  place[tear].c  = FALSE;
	  place[tear].dir= FALSE;
      tear ++;
      if (tear >= MAX) tear = 0;
   }
   else
   {
      eat = FALSE;
      exit = TRUE;
      while(exit)
      {
      babyx = rand()%MAXX;
      babyy = rand()%MAXY;
      exit = FALSE;
      for( i = 0; i< MAX; i++ )
	 if( (place[i].st)&&( place[i].x == babyx) && (place[i].y == babyy))
	    exit ++;
      }

   }
   if (head == tear) game = GAMEHAPPY;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -