1331com银河游戏

ƽ̨ûĻоѡصģ1c ̰ 2CԵ̰Դ 3CԱд̰ҪЩ?? 4̰ôCԱд 5c̰ôԼ 6cԱд̰ʳϷ 7C̰ߴDEV̰ͨߣҪTCϵİʦϿθDEVһ 8 ̰CԴ 9c̰ߵٶȿƳô 10c̰Դô?
ƽ̨û 2018-06-06 16:49:07

Ǿѡƽ̨ûʱ




c ̰

Ҫݣ ƲʵһֻϷ̰ߡijһܱյΧǽ˶ͨϵĸͷĸƶΧǽһʳͷײʳʾʳﱻ߳Եʱߵ峤һڣͬʱӷֳ֣ʳ... Ҫݣ
ƲʵһֻϷ̰ߡijһܱյΧǽ˶ͨϵĸͷĸƶΧǽһʳͷײʳʾʳﱻ߳Եʱߵ峤һڣͬʱӷֳ֣ʳȴ߳ԵƶУײǽڡ彻ͷײԼϷ

Ҫ
γҪպʵ¹ܺͷ
1ջͼԭͼκʹ÷
2ϷлĶʵַ
3ռӦҪͷ
4˽Ϸײķ
5ʵϷٹܣټܺ𲽼ٹܣ

չҪ
1 ʵϰ﹦ܣ
2 ʵԹʽΧǽ
3 ʵֹʽϷʽ

ĵҪ
ϵͳɺҪύʽ淶ĵݣ
1 Ĺܣ
2 Ϸƺͼκʹã
3 ˼·
4 еݽṹ
5 ײʵַ
6 㷨ͼ
7 Ľ룻
8 ܽᡣ
1 Ĺ
ƲʵһֻϷ̰ߡijһܱյΧǽ˶ͨϵĸͷĸƶΧǽһʳͷײʳʾʳﱻ߳Եʱߵ峤һڣͬʱӷֳ֣ʳȴ߳ԵƶУײǽڻͷײԼϷ

2 Ϸƺͼκʹ
/* οָ1.3.1ͻ溯 */
3 ˼·
/* οָ1.3.2 */
4 еݽṹ
/* οָ1.3.2 */
5 ײʵַ
/* οָϷ̺ */
6 㷨ͼ
/* ο˵ */
7 Ľ
/* ԼϹĥɣ */
8 ܽ
ͨογƣǿҶC֪ʶգѧ˻Ϸ̷ҸӳƵ˸߼ԳԼ ˴ɾ֣ɣ
Ľѱ5107˵
/* ̰߳ by champking */

#define N 200

#include
#include
#include

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b

int i,key;
int score = 0;/*÷*/
int gamespeed = 100000;/*ϷٶԼ*/

struct Food
{
int x;/*ʳĺ*/
int y;/*ʳ*/
int yes;/*жǷҪʳı*/
}food;/*ʳĽṹ*/

struct Snake
{
int x[N];
int y[N];
int node;/*ߵĽ*/
int direction;/*ƶ*/
int life;/* ߵ,0,1*/
}snake;

void Init(void);/*ͼ*/
void Close(void);/*ͼν*/
void DrawK(void);/*ʼ*/
void GameOver(void);/*Ϸ*/
void GamePlay(void);/*Ϸ*/
void PrScore(void);/*ɼ*/

/**/
void main(void)
{
Init();/*ͼ*/
DrawK();/*ʼ*/
GamePlay();/*Ϸ*/
Close();/*ͼν*/
}

/*ͼ*/
void Init(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc");
cleardevice();
}
/*ʼ,ϽΪ(50,40),½Ϊ(610,460)Χǽ*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);/**/

for(i = 50; i <= 600; i += 10)/*Χǽ*/
{
rectangle(i, 40, i + 10, 49); /*ϱ*/
rectangle(i, 451, i + 10, 460);/*±*/
}

for(i = 40; i <= 450; i += 10)
{
rectangle(50, i, 59, i + 10); /**/
rectangle(601, i, 610, i + 10);/*ұ*/
}
}
/*Ϸ*/
void GamePlay(void)
{
randomize();/**/
food.yes = 1;/*1ʾҪʳ,0ʾѾʳ*/
snake.life = 0;/**/
snake.direction = 1;/**/
snake.x[0] = 100; snake.y[0] = 100;/*ͷ*/
snake.x[1] = 110; snake.y[1] = 100;
snake.node = 2;/**/
PrScore();/*÷*/

while(1)/*ظϷ,ѹESC*/
{
while(!kbhit())/*ûа,Լƶ*/
{
if(food.yes == 1)/*Ҫʳ*/
{
food.x = rand() % 400 + 60;
food.y = rand() % 350 + 60;

while(food.x % 10 != 0)/*ʳֺʳܹ,ſ߳Ե*/
food.x++;
while(food.y % 10 != 0)
food.y++;
food.yes = 0;/*ʳ*/
}

if(food.yes == 0)/*ʳ˾Ҫʾ*/
{
setcolor(GREEN);
rectangle(food.x, food.y, food.x + 10, food.y - 10);
}

for(i = snake.node - 1; i > 0; i--)/*ߵÿǰƶ,Ҳ̰ߵĹؼ㷨*/
{
snake.x[i] = snake.x[i-1];
snake.y[i] = snake.y[i-1];
}

/*1,2,3,4ʾ,,,ĸ,ͨжƶͷ*/
switch(snake.direction)
{
case 1: snake.x[0] += 10; break;
case 2: snake.x[0] -= 10; break;
case 3: snake.y[0] -= 10; break;
case 4: snake.y[0] += 10; break;
}

for(i = 3; i < snake.node; i++)/*ߵĵĽڿʼжǷײԼ,ΪͷΪ,ڲܹչ*/
{
if(snake.x[i] == snake.x[0] && snake.y[i] == snake.y[0])
{
GameOver();/*ʾʧ*/
snake.life = 1;
break;
}
}

if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*Ƿײǽ*/
{
GameOver();/*Ϸ*/
snake.life=1; /**/
}

if(snake.life == 1)/*жԺ,ѭ,¿ʼ*/
break;

if(snake.x[0] == food.x && snake.y[0] == food.y)/*ԵʳԺ*/
{
setcolor(0);/*ѻϵʳﶫȥ*/
rectangle(food.x, food.y, food.x + 10, food.y - 10);
snake.x[snake.node] =- 20; snake.y[snake.node] =- 20;
/*µһȷڿλ,´ѭȡǰһڵλ*/
snake.node++;/*ߵ峤һ*/
food.yes = 1;/*Ҫµʳ*/
score += 10;
PrScore();/*µ÷*/
}

setcolor(4);/**/

for(i = 0; i < snake.node; i++)
rectangle(snake.x[i], snake.y[i], snake.x[i] + 10,
snake.y[i] - 10);

delay(gamespeed);

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)*/

if(snake.life == 1)/*ѭ*/
break;

key = bioskey(0);/*հ*/

if(key == ESC)/*ESC˳*/
break;
else
if(key == UP&&snake.direction!=4)
/*жǷ෴ķƶ*/
snake.direction=3;
else
if(key == RIGHT &&snake.direction != 2)
snake.direction=1;
else
if(key == LEFT && snake.direction != 1)
snake.direction = 2;
else
if(key == DOWN && snake.direction != 3)
snake.direction = 4;
}/*endwhile(1)*/
}

/*Ϸ*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0, 0, 4);
outtextxy(200, 200, "GAME OVER");
getch();
}

/*ɼ*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL, YELLOW);
bar(50, 15, 220, 35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str, "score:%d", score);
outtextxy(55, 20, str);
}

/*ͼν*/
void Close(void)
{
getch();
closegraph();
}

һα༭ʱ Ƽ2017-09-18 05:24:38
7302159
7302159


7302159CԵ̰Դ

ԵĻ׷55֡ķ~~ϣǰԼдѷңʱ䲻 ã 471929895@qq.com ٶȺֲܶ÷~~
Ľѱ4014˵

 
//******ʾ:ٶȿ,С_sleep(500)в*****  

#include   
#include   
#include   
#include   
#include   
const int H = 8;   //ͼĸ  
const int L = 16;  //ͼij  
char GameMap[H][L];   //Ϸͼ  
int  key;  //  
int  sum = 1, over = 0;  //ߵij, Ϸ(ԳԻǽ)  
int  dx[4] = {0, 0, -1, 1};  //ҡϡµķ  
int  dy[4] = {-1, 1, 0, 0};  
struct Snake   //ߵÿڵ  
{  
 int x, y;  //λ  
 int now;   //浱ǰڵķ, 0,1,2,3ֱΪ  
}Snake[H*L];  
const char Shead = '@';  //ͷ  
const char Sbody = '#';  //  
const char Sfood = '*';  //ʳ  
const char Snode = '.';  //'.'ڵͼϱʾΪ  
void Initial();  //ͼijʼ  
void Create_Food(); //ڵͼʳ  
void Show();   //ˢʾͼ  
void Button();  //ȡ,жϷ  
void Move();   //ߵƶ  
void Check_Border();  //ͷǷԽ  
void Check_Head(int x, int y);   //ͷƶλ  
int main()   
{  
 Initial();  
 Show();  
 return 0;  
}  
void Initial()  //ͼijʼ  
{  
 int i, j;  
 int hx, hy;  
 system("title ̰");  //̨ı  
 memset(GameMap, '.', sizeof(GameMap));  //ʼͼȫΪ'.'  
 system("cls");  
 srand(time(0));   //  
 hx = rand()%H;    //ͷ  
 hy = rand()%L;  
 GameMap[hx][hy] = Shead;  
 Snake[0].x = hx;  Snake[0].y = hy;  
 Snake[0].now = -1;  
 Create_Food();   //ʳ  
 for(i = 0; i < H; i++)   //ͼʾ  
 {   
  for(j = 0; j < L; j++)  
   printf("%c", GameMap[i][j]);  
  printf("\n");  
 }  
     
 printf("\nССC̰\n");  
 printf("ⷽʼϷ\n");  
    
 getch();   //Ƚһ,ʹ߿ʼ÷  
 Button();  //ȡ,жϷ  
}  
void Create_Food()  //ڵͼʳ  
{  
 int fx, fy;  
 while(1)  
 {  
  fx = rand()%H;  
     fy = rand()%L;  
     
  if(GameMap[fx][fy] == '.')  //ܳռеλ  
  {   
   GameMap[fx][fy] = Sfood;  
      break;  
  }  
 }  
}  
void Show()  //ˢʾͼ  
{  
 int i, j;  
 while(1)  
 {    
  _sleep(500); //ӳٰ(1000Ϊ1s),ÿˢһεͼ  
  Button();   //жϰƶ  
  Move();  
  if(over)  //ԳԻǽϷ  
  {   
   printf("\n**Ϸ**\n");  
   printf("     >_<\n");  
   getchar();  
      break;  
  }  
  system("cls");   //յͼʾˢºĵͼ  
  for(i = 0; i < H; i++)   
  {   
   for(j = 0; j < L; j++)  
    printf("%c", GameMap[i][j]);  
   printf("\n");  
  }  
     
  printf("\nССC̰\n");  
  printf("ⷽʼϷ\n");  
 }  
}  
void Button()  //ȡ,жϷ  
{  
 if(kbhit() != 0) //鵱ǰǷм룬򷵻һ0ֵ򷵻0  
 {   
  while(kbhit() != 0)  //ܴڶ,Ҫȫȡ,һΪ  
      key = getch(); //ӿ̨ȡ浽key  
  switch(key)  
  {   //  
   case 75:  Snake[0].now = 0;  
          break;  
            //  
            case 77:  Snake[0].now = 1;       
          break;  
            //  
   case 72:  Snake[0].now = 2;  
          break;  
            //  
   case 80:  Snake[0].now = 3;  
          break;  
  }  
 }  
}  
void Move()   //ߵƶ  
{  
 int i, x, y;  
    int t = sum;  //浱ǰߵij  
 //¼ǰͷλ,Ϊ,ͷƶ  
 x = Snake[0].x;  y = Snake[0].y;  GameMap[x][y] = '.';  
 Snake[0].x = Snake[0].x + dx[ Snake[0].now ];  
 Snake[0].y = Snake[0].y + dy[ Snake[0].now ];  
 Check_Border();   //ͷǷԽ  
 Check_Head(x, y);  //ͷƶλ,Ϊ: ͷĿʼλ  
 if(sum == t)  //δԵʳTƶŶ  
    for(i = 1; i < sum; i++)  //ҪβڵǰƶŶ,ǰһڵΪ  
 {  
  if(i == 1)   //βڵΪƶ  
   GameMap[ Snake[i].x ][ Snake[i].y ] = '.';  
     
  if(i == sum-1)  //Ϊͷڵ,⴦  
  {  
   Snake[i].x = x;  
         Snake[i].y = y;  
      Snake[i].now = Snake[0].now;  
  }  
  else   //ߵǰһλ  
  {  
   Snake[i].x = Snake[i+1].x;  
         Snake[i].y = Snake[i+1].y;  
      Snake[i].now = Snake[i+1].now;  
  }  
      
  GameMap[ Snake[i].x ][ Snake[i].y ] = '#'; //ƶҪΪ'#'   
 }  
}  
void Check_Border()  //ͷǷԽ  
{  
 if(Snake[0].x < 0 || Snake[0].x >= H  
 || Snake[0].y < 0 || Snake[0].y >= L)  
     over = 1;  
}  
void Check_Head(int x, int y)  //ͷƶλ  
{  
    
 if(GameMap[ Snake[0].x ][ Snake[0].y ] == '.')  //Ϊ  
  GameMap[ Snake[0].x ][ Snake[0].y ] = '@';  
 else 
  if(GameMap[ Snake[0].x ][ Snake[0].y ] == '*')  //Ϊʳ  
  {  
   GameMap[ Snake[0].x ][ Snake[0].y ] = '@';    
   Snake[sum].x = x;   //ӵΪͷǸ  
      Snake[sum].y = y;  
      Snake[sum].now = Snake[0].now;  
         GameMap[ Snake[sum].x ][ Snake[sum].y ] = '#';   
   sum++;  
   Create_Food();  //ʳٲһʳ  
  }  
  else 
   over = 1;  
}

һα༭ʱ Ƽ2017-11-17 20:26:41
ƽİI
ƽİI


ƽİI⣺CԱд̰ҪЩ??

ҪԴ룬Ҫ˼·ֻҪҪõЩ֪ˣллˡ
Ľѱ9171˵
д
#include

int main(void)
{
return 0;
}
Ȼǽô
Ŀƣ
״̬ߵȫռųһߵǰ
귶Χ
ϰ
ͷ귶Χײϰ
ӳԵʳʱȫ겻䣬ֻβϳһ
ʱÿʱʱ䵽βϵһʧ겻䣬һΪͷ+򣬴Ϊµͷ
֯һͿ
echo '++++++++++[>++++++++++[>+<-]<-]>>-.+++++++.---------.++++++++.>>++++[<++++[<+>-]>-]<<+.-------..' | sed '
s/\([-+]\)/\1\1*p;/g
s/s/>/p++;/g
s/\./putchar(*p);/g
s/\[/while(*p){/g
s/\]/}/g
1s/^/main(){char*p=calloc(1,6);/
$s/$/}/
/./!d'|gcc -xc - 2>/dev/null&&./a.out
һα༭ʱ 2015-07-04
Ե0RM
Ե0RM


Ե0RM̰ôCԱд

Ľѱ2383˵
#include 
#include
#include
#include /*õĿ⺯*/
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b/*궨*/
#define N 200
int i,key;
int level;/*Ϸȼ*/
int score=0;/*÷*/
int gamespeed;/*Ϸٶ*/
struct Food
{
int x;/*ʳĺ*/
int y;/*ʳ*/
int yes;/*жǷҪʳı*/
}food;/*ʳĽṹ*/
struct Snake
{
int x[N];
int y[N];
int node;/*ߵĽ*/
int direction;/*ƶ*/
int life;/* ߵ,0,1*/
}snake;/*ߵĽṹ*/
void Choicelevle(void);/*ѡϷȼ*/
void Init(void);/*ͼ*/
void Close(void);/*ͼν*/
void DRAW(void);/*Ϸ*/
void GameOver(void);/*Ϸ*/
void GamePlay(void);/*Ϸ*/
void PrScore(void);/*ɼ*/
/**/
void main(void)
{
Init();/*ͼ*/
Choicelevle();/*ѡϷȼ*/
DRAW();/*Ϸ*/
GamePlay();/*Ϸ*/
Close();/*ͼν*/
}

/*ͼ*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\turboc2"); /*ʼͼϵͳ*/
cleardevice(); /*ͼν*/
}
/*ѡϷȼ*/
void Choicelevle(void)
{char name[20];setcolor(YELLOW);settextstyle(0,0,6);outtextxy(150,150,"Snake");setcolor(GREEN);settextstyle(0,0,1);outtextxy(200,250,"please put in your English name:");outtextxy(200,270,"Choice levle from 1-9.");outtextxy(300,320,"name:yangzilong");/**/outtextxy(300,350,"number:0902060226");/*ѧ*/outtextxy(300,380,"class:computer science 0602");/*˰༶*/getch();printf("please putin your name:");gets(name);printf("please choice levle:");scanf("%d",&level);gamespeed=100000-400*level-300*level*level;if(level>9||level<1){cleardevice(); /*ͼν*/setcolor(YELLOW); /*ɫ*/settextstyle(0,0,2); /**/outtextxy(150,200,"level input error"); /*ʾı*/getch();level=1;}
}
void DRAW(void)
{cleardevice(); /**/setcolor(2);setlinestyle(SOLID_LINE,0,THICK_WIDTH);/**/rectangle(45,45,465,325);}
/*Ϸ*/
void GamePlay(void)
{setcolor(5);setlinestyle(SOLID_LINE,0,THICK_WIDTH);/**/randomize();/**/food.yes=1;/*1ʾҪʳ,0ʾѾʳ*/snake.life=0;/**/snake.direction=1;/**/snake.x[0]=320;snake.y[0]=240;/*ͷ*/snake.x[1]=330;snake.y[1]=240; /*ߵĵڶλ*/snake.node=3;/**/PrScore();/*÷*/while(1)/*ظϷ,ѹESC*/{while(!kbhit())/*ûа,Լƶ*/{if(food.yes==1)/*Ҫʳ*/{food.x=rand()%360+70;food.y=rand()%250+60;while(food.x%10!=0)/*ʳֺʳܹ,ſ߳Ե*/food.x++;while(food.y%10!=0)food.y++;food.yes=0;/*ʳ*/}
if(food.yes==0)/*ʳ˾Ҫʾ*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*ߵÿǰƶ*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4ʾ,,,ĸ,ͨƶͷ*/
switch(snake.direction)
{
case 1: snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*ʾʧ*/
snake.life=1; /**/
break;
}
}

/*ͷǽڣͷӶǽ*/
if(snake.x[0]<50)
{snake.x[0]=450;/*ͷԽ߽,ұ߽*/snake.y[0]=snake.y[0];/*겻*/for(i=snake.node-1;i>0;i--){snake.x[i]=snake.x[i-1];snake.y[i]=snake.y[i-1]; /*ߵǰƽ*/}
{
setfillstyle(SOLID_FILL,0); /*ģʽɫ0ʾɫ*/
bar(50,55,455,315);/*barDZʾķΧĺ*/
}
}
else
if(snake.x[0]>450)
{snake.x[0]=50;/*ͷԽұ߽,ͷ߽*/snake.y[0]=snake.y[0];/*겻*/for(i=snake.node-1;i>0;i--){snake.x[i]=snake.x[i-1];snake.y[i]=snake.y[i-1]; /*ߵǰƽ*/}
{
setfillstyle(SOLID_FILL,0); /*ģʽɫ0ʾɫ*/
bar(50,55,455,315);/*barDZʾķΧĺ*/
}
}
else
if(snake.y[0]<60)
{snake.y[0]=320;/*ͷԽϱ߽,±߽*/snake.x[0]=snake.x[0];/*겻*/for(i=snake.node-1;i>0;i--){snake.x[i]=snake.x[i-1];snake.y[i]=snake.y[i-1]; /*ߵǰƽ*/}
{
setfillstyle(SOLID_FILL,0); /*ģʽɫ0ʾɫ*/
bar(50,55,455,315);/*barDZʾķΧĺ*/
}
}
else
if(snake.y[0]>320)
{snake.y[0]=60;/*ͷԽ±߽,ϱ߽*/snake.x[0]=snake.x[0];/*겻*/for(i=snake.node-1;i>0;i--){snake.x[i]=snake.x[i-1];snake.y[i]=snake.y[i-1]; /*ߵǰƽ*/}
{
setfillstyle(SOLID_FILL,0); /*ģʽɫ0ʾɫ*/
bar(50,55,455,315);/*barDZʾķΧĺ*/
}
}
if(snake.life==1)/*ѭ¿ʼ*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*ԵʳԺ*/
{
setcolor(0);/*ѻϵʳﶫȥ*/
rectangle(food.x,food.y,food.x+10,food.y-10); /*õǰͺɫһ*/
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*µһȷڿλ,´ѭȡǰһڵλ*/
snake.node++;/*ߵ峤һ*/
food.yes=1;/*Ҫµʳ*/
score+=10; /*ÿԵһʳ,÷ۼ10*/
if(score%100==0)
{level++;gamespeed=100000-400*level-300*level*level;/*ÿԵ10ʳһ,ٶȼӿ*/PrScore();/*µ÷*/setcolor(YELLOW); /*ɫ*/settextstyle(0,0,4); /**/outtextxy(150,200,"LEVEL UP"); /*ʾı*/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,315);/*barDZʾķΧĺ*/
}
PrScore();/*µ÷*/
}
setcolor(4);/**/
for(i=0;irectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed); /*Ϸٶ*/
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);
} /*endwhilekbhit*/ /*úɫȥߵĵһ*/
if(snake.life==1)/*ѭ*/
break;
key=bioskey(0);/*հ*/
if(key==ESC)/*ESC˳*/
break;
else
if(key==UP&&snake.direction!=4)
/*жǷ෴ķƶ*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*Ϸ*/
void GameOver(void)
{
cleardevice(); /**/
PrScore();
setcolor(RED); /*ɫ*/
settextstyle(0,0,4); /**/
outtextxy(200,200,"GAME OVER"); /*ʾı*/
getch();
}
/*ɼϷȼ*/
void PrScore(void)
{
char str1[20];/*ַ*/
setfillstyle(SOLID_FILL,0);
bar(50,15,390,35); /*ο*/
setcolor(6); /*ıɫ*/
settextstyle(0,0,2); /*ʾλ*/
sprintf(str1,"score %d level %d",score,level);/*ʾ*/
outtextxy(55,20,str1);
setcolor(YELLOW); /*ɫ*/
settextstyle(0,0,2); /**/
outtextxy(250,400,"EXIT=ESC ");/*ʾı*/
}
void Close(void)
{
closegraph();
}
һα༭ʱ Ƽ2017-09-15 03:14:25
li455381165
li455381165


li455381165c̰ôԼ

ѧ̷ǿc
ϸ
Ľѱ3683˵
ѭ+Sleepܵ
˵ڶһС飬Զƶ
int i,j;
int a[25][80]={0};
//н
int x=10,y=0;
//һx,yʾ鵱ǰλ
while(1)
{
//֮ǰϢ
system("cls");//ǵõУ
a[x][y]=1;
//ԪΪ1ͱʾڽϵλʾ
//ĻӦλ
for( i = 0; i<25 ; i++)
for( j=0; j<80 ;j++)
if(a[i][j]==0) printf(" ");
//0ͱʾλòǷ飬һո
else printf("%c",2);
//
//Ȼ飬Ժһѭϲһ
for( i = 0; i<25 ; i++)
for( j=0; j<80 ;j++)
a[i][j]=0;
// ķڵλ
// x=x-1;
// x=x+1;
// y=y-1;
// y=y-1;
//ľ䱣һͿ
//ȻϢϢ
Sleep(300);
}
㷨ʾ
Ŀ϶Чһ
˵Ҫߵķ
ǸıλõʱҪж
ңıһߺ͸ıһҲһ
˼·ӵ
ο
עһ㣬Sleepwindowͷļ
Ҫwindowͷļ
Windowsϵͳ滻ΪӦĺ
һα༭ʱ Ƽ2017-09-30 10:23:06
bianchenggaosh
bianchenggaosh


bianchenggaoshcԱд̰ʳϷ

鷳עϸ㣬עÿһ仰˼
Ľѱ4041˵
һɹ̰ߴ루cԱдģϣܿ
#define N 200
#include
#include
#include
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*÷*/
int gamespeed=50000;/*ϷٶԼ*/
struct Food
{
int x;/*ʳĺ*/
int y;/*ʳ*/
int yes;/*жǷҪʳı*/
}food;/*ʳĽṹ*/
struct Snake
{
int x[N];
int y[N];
int node;/*ߵĽ*/
int direction;/*ƶ*/
int life;/* ߵ,0,1*/
}snake;
void Init(void);/*ͼ*/
void Close(void);/*ͼν*/
void DrawK(void);/*ʼ*/
void GameOver(void);/*Ϸ*/
void GamePlay(void);/*Ϸ*/
void PrScore(void);/*ɼ*/
/**/
void main(void)
{
Init();/*ͼ*/
DrawK();/*ʼ*/
GamePlay();/*Ϸ*/
Close();/*ͼν*/
}
/*ͼ*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*ʼ棬ϽΪ5040½Ϊ610460Χǽ*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/**/
for(i=50;i<=600;i+=10)/*Χǽ*/
{
rectangle(i,40,i+10,49); /*ϱ*/
rectangle(i,451,i+10,460);/*±*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /**/
rectangle(601,i,610,i+10);/*ұ*/
}
}
/*Ϸ*/
void GamePlay(void)
{
randomize();/**/
food.yes=1;/*1ʾҪʳ,0ʾѾʳ*/
snake.life=0;/**/
snake.direction=1;/**/
snake.x[0]=100;snake.y[0]=100;/*ͷ*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/**/
PrScore();/*÷*/
while(1)/*ظϷ,ѹESC*/
{
while(!kbhit())/*ûа,Լƶ*/
{
if(food.yes==1)/*Ҫʳ*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*ʳֺʳܹ,ſ߳Ե*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*ʳ*/
}
if(food.yes==0)/*ʳ˾Ҫʾ*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*ߵÿǰƶ,Ҳ̰ߵĹؼ㷨*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4ʾ,,,ĸ,ͨжƶͷ*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i {
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*ʾʧ*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*Ƿײǽ*/
{
GameOver();/*Ϸ*/
snake.life=1; /**/
}
if(snake.life==1)/*жԺ,ѭ¿ʼ*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*ԵʳԺ*/
{
setcolor(0);/*ѻϵʳﶫȥ*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*µһȷڿλ,´ѭȡǰһڵλ*/
snake.node++;/*ߵ峤һ*/
food.yes=1;/*Ҫµʳ*/
score+=10;
PrScore();/*µ÷*/
}
setcolor(4);/**/
for(i=0;i rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
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);
} /*endwhilekbhit*/
if(snake.life==1)/*ѭ*/
break;
key=bioskey(0);/*հ*/
if(key==ESC)/*ESC˳*/
break;
else
if(key==UP&&snake.direction!=4)
/*жǷ෴ķƶ*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*Ϸ*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*ɼ*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*ͼν*/
void Close(void)
{
getch();
closegraph();
}
һα༭ʱ Ƽ2017-09-18 11:51:53



ˣC̰ߴDEV̰ͨߣҪTCϵİʦϿθDEVһ

C̰ߴDEV̰ͨߣҪTCϵİʦϿθDEVһι😭😭😭😭😭
Ľѱ7378˵

#include 
#include 
#include 
#include 


#define U 1
#define D 2
#define L 3
#define R 4       //ߵ״̬U D£L: R

typedef struct SNAKE { //һڵ
    int x;
    int y;
    struct SNAKE *next;
} snake;

//ȫֱ//
int score=0,add=10;//ܵ÷ÿγʳ÷֡
int status,sleeptime=200;//ÿеʱ
snake *head, *food;//ͷָ룬ʳָ
snake *q;//ߵʱõָ
int endgamestatus=0; //Ϸ1ײǽ2ҧԼ3˳Ϸ

//ȫ//
void Pos();
void creatMap();
void initsnake();
int biteself();
void createfood();
void cantcrosswall();
void snakemove();
void pause();
void gamecircle();
void welcometogame();
void endgame();
void gamestart();

void Pos(int x,int y)//ùλ
{
    COORD pos;
    HANDLE hOutput;
    pos.X=x;
    pos.Y=y;
    hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOutput,pos);
}

void creatMap()//ͼ
{
    int i;
    for(i=0; i<58; i+=2) { //ӡ±߿
        Pos(i,0);
        printf("");
        Pos(i,26);
        printf("");
    }
    for(i=1; i<26; i++) { //ӡұ߿
        Pos(0,i);
        printf("");
        Pos(56,i);
        printf("");
    }
}

void initsnake()//ʼ
{
    snake *tail;
    int i;
    tail=(snake*)malloc(sizeof(snake));//βʼͷ巨x,y趨ʼλ//
    tail->x=24;
    tail->y=5;
    tail->next=NULL;
    for(i=1; i<=4; i++) {
        head=(snake*)malloc(sizeof(snake));
        head->next=tail;
        head->x=24+2*i;
        head->y=5;
        tail=head;
    }
    while(tail!=NULL) { //ͷΪ
        Pos(tail->x,tail->y);
        printf("");
        tail=tail->next;
    }
}

int biteself()//жǷҧԼ
{
    snake *self;
    self=head->next;
    while(self!=NULL) {
        if(self->x==head->x && self->y==head->y) {
            return 1;
        }
        self=self->next;
    }
    return 0;
}

void createfood()//ʳ
{
    snake *food_1;
    srand((unsigned)time(NULL));
    food_1=(snake*)malloc(sizeof(snake));
    while((food_1->x%2)!=0) {  //֤Ϊżʹʳͷ
        food_1->x=rand()%52+2;
    }
    food_1->y=rand()%24+1;
    q=head;
    while(q->next==NULL) {
        if(q->x==food_1->x && q->y==food_1->y) { //жǷʳغ
            free(food_1);
            createfood();
        }
        q=q->next;
    }
    Pos(food_1->x,food_1->y);
    food=food_1;
    printf("");
}

void cantcrosswall()//ܴǽ
{
    if(head->x==0 || head->x==56 ||head->y==0 || head->y==26) {
        endgamestatus=1;
        endgame();
    }
}

void snakemove()//ǰ,U,D,L,R
{
    snake * nexthead;
    cantcrosswall();

    nexthead=(snake*)malloc(sizeof(snake));
    if(status==U) {
        nexthead->x=head->x;
        nexthead->y=head->y-1;
        if(nexthead->x==food->x && nexthead->y==food->y) { //һʳ//
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            score=score+add;
            createfood();
        } else {                                           //ûʳ//
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q->next->next!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            Pos(q->next->x,q->next->y);
            printf("  ");
            free(q->next);
            q->next=NULL;
        }
    }
    if(status==D) {
        nexthead->x=head->x;
        nexthead->y=head->y+1;
        if(nexthead->x==food->x && nexthead->y==food->y) { //ʳ
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            score=score+add;
            createfood();
        } else {                           //ûʳ
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q->next->next!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            Pos(q->next->x,q->next->y);
            printf("  ");
            free(q->next);
            q->next=NULL;
        }
    }
    if(status==L) {
        nexthead->x=head->x-2;
        nexthead->y=head->y;
        if(nexthead->x==food->x && nexthead->y==food->y) { //ʳ
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            score=score+add;
            createfood();
        } else {                            //ûʳ
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q->next->next!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            Pos(q->next->x,q->next->y);
            printf("  ");
            free(q->next);
            q->next=NULL;
        }
    }
    if(status==R) {
        nexthead->x=head->x+2;
        nexthead->y=head->y;
        if(nexthead->x==food->x && nexthead->y==food->y) { //ʳ
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            score=score+add;
            createfood();
        } else {                                     //ûʳ
            nexthead->next=head;
            head=nexthead;
            q=head;
            while(q->next->next!=NULL) {
                Pos(q->x,q->y);
                printf("");
                q=q->next;
            }
            Pos(q->next->x,q->next->y);
            printf("  ");
            free(q->next);
            q->next=NULL;
        }
    }
    if(biteself()==1) {     //жǷҧԼ
        endgamestatus=2;
        endgame();
    }
}

void pause()//ͣ
{
    while(1) {
        Sleep(300);
        if(GetAsyncKeyState(VK_SPACE)) {
            break;
        }

    }
}

void gamecircle()//Ϸ
{

    Pos(64,15);
    printf("ܴǽҧԼ\n");
    Pos(64,16);
    printf("á...ֱߵƶ.");
    Pos(64,17);
    printf("F1 Ϊ٣F2 Ϊ\n");
    Pos(64,18);
    printf("ESC ˳Ϸ.spaceͣϷ.");
    Pos(64,20);
    //
    status=R;
    while(1) {
        Pos(64,10);
        printf("÷֣%d  ",score);
        Pos(64,11);
        printf("ÿʳ÷֣%d",add);
        if(GetAsyncKeyState(VK_UP) && status!=D) {
            status=U;
        } else if(GetAsyncKeyState(VK_DOWN) && status!=U) {
            status=D;
        } else if(GetAsyncKeyState(VK_LEFT)&& status!=R) {
            status=L;
        } else if(GetAsyncKeyState(VK_RIGHT)&& status!=L) {
            status=R;
        } else if(GetAsyncKeyState(VK_SPACE)) {
            pause();
        } else if(GetAsyncKeyState(VK_ESCAPE)) {
            endgamestatus=3;
            break;
        } else if(GetAsyncKeyState(VK_F1)) {
            if(sleeptime>=50) {
                sleeptime=sleeptime-30;
                add=add+2;
                if(sleeptime==320) {
                    add=2;//ֹ1֮ټӻд
                }
            }
        } else if(GetAsyncKeyState(VK_F2)) {
            if(sleeptime<350) {
                sleeptime=sleeptime+30;
                add=add-2;
                if(sleeptime==350) {
                    add=1;  //֤ͷΪ1
                }
            }
        }
        Sleep(sleeptime);
        snakemove();
    }
}

void welcometogame()//ʼ
{
    Pos(40,12);

    //
    printf("ӭ̰ʳϷ");
    Pos(40,25);
    //
    system("pause");
    system("cls");
    Pos(25,12);
    printf("á...ֱߵƶ F1 Ϊ٣2 Ϊ\n");
    Pos(25,13);
    printf("ٽܵõߵķ\n");
    system("pause");
    system("cls");
}

void endgame()//Ϸ
{

    system("cls");
    Pos(24,12);
    if(endgamestatus==1) {
        printf("ԲײǽˡϷ.");
    } else if(endgamestatus==2) {
        printf("ԲҧԼˡϷ.");
    } else if(endgamestatus==3) {
        printf("ѾϷ");
    }
    Pos(24,13);
    printf("ĵ÷%d\n",score);
    exit(0);
}

void gamestart()//Ϸʼ
{
    system("mode con cols=100 lines=30");
    welcometogame();
    creatMap();
    initsnake();
    createfood();
}

int main()
{
    gamestart();
    gamecircle();
    endgame();
    return 0;
}

һα༭ʱ Ƽ2017-11-22 20:12:24
lck32578
lck32578


lck32578 ̰CԴ

һ̰ߵĴ룬Ҫõͼο⺯ģֻtimestlibstdioͺˣлл
Ľѱ6960˵
#include 
#include
#include
#include
#include
#include
#define N 21

int apple[3],num;
char score[3];
char tail[3];

void gotoxy(int x, int y) //
{
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void color(int b) //ɫ
{
HANDLE hConsole = GetStdHandle((STD_OUTPUT_HANDLE)) ;
SetConsoleTextAttribute(hConsole,b) ;
}

int Block(char head[2]) //жϳ
{
if ((head[0] < 1) || (head[0] > N) || (head[1] < 1) || (head[1] > N))
return 1;
return 0;
}

int Eat(char snake[2]) //ƻ
{
if ((snake[0] == apple[0]) && (snake[1] == apple[1]))
{
apple[0] = apple[1] = apple[2] = 0;
gotoxy(N+44,10);
color(13);
printf("%d",score[0]*10);
color(11);
return 1;
}
return 0;
}

void Draw(char **snake, int len) //ƶ
{
if (apple[2])
{
gotoxy(apple[1] * 2, apple[0]);
color(12);
printf("");
color(11);
}
gotoxy(tail[1] * 2, tail[0]);
if (tail[2])
{
color(num);
printf("");
color(num);
}
else
printf("");
gotoxy(snake[0][1] * 2, snake[0][0]);
color(num);
printf("");
color(num);
putchar('\n');
}

char** Move(char **snake, char dirx, int *len) //Ʒ
{
int i, full = Eat(snake[0]);
memcpy(tail, snake[(*len)-1], 2);
for (i = (*len) - 1; i > 0; --i)
memcpy(snake[i], snake[i-1], 2);
switch (dirx)
{
case 'w': case 'W': --snake[0][0]; break;
case 's': case 'S': ++snake[0][0]; break;
case 'a': case 'A': --snake[0][1]; break;
case 'd': case 'D': ++snake[0][1]; break;
default: ;
}
if (full)
{
snake = (char **)realloc(snake, sizeof(char *) * ((*len) + 1));
snake[(*len)] = (char *)malloc(sizeof(char) * 2);
memcpy(snake[(*len)], tail, 2);
++(*len);
++score[0];
if(score[3] < 16)
++score[3];
tail[2] = 1;
}
else
tail[2] = 0;
return snake;
}

void init(char plate[N+2][N+2], char ***snake_x, int *len) //ʼ
{
int i, j;
char **snake = NULL;

*len = 3;
score[0] = score[3] =3;
snake = (char **)realloc(snake, sizeof(char *) * (*len));
for (i = 0; i < *len; ++i)
snake[i] = (char *)malloc(sizeof(char) * 2);

for (i = 0; i < 3; ++i)
{
snake[i][0] = N/2 + 1;
snake[i][1] = N/2 + 1 + i;
}

for (i = 1; i <= N; ++i)
for (j = 1; j <= N; ++j)
plate[i][j] = 1;

apple[0] = rand()%N + 1; apple[1] = rand()%N + 1;
apple[2] = 1;

for (i = 0; i < N + 2; ++i)
{
gotoxy(0, i);
for (j = 0; j < N + 2; ++j)
{
switch (plate[i][j])
{
case 0:
color(12);printf("");color(11); continue;
case 1: printf(""); continue;
default: ;
}
}
putchar('\n');
}
for (i = 0; i < (*len); ++i)
{
gotoxy(snake[i][1] * 2, snake[i][0]);
printf("");
}
putchar('\n');
*snake_x = snake;
}

void Manual()
{
gotoxy(N+30,2);
color(10);
printf(" W S A D ƶ");
gotoxy(N+30,4);
printf(" space ͣ");
gotoxy(N+30,8);
color(11);
printf("ʷ߷Ϊ: ");
color(12);
gotoxy(N+44,8);
printf("%d",score[1]*10);
color(11);
gotoxy(N+30,12);
printf("ڵ÷Ϊ: 0");
}

int File_in() //ȡ¼ķ
{
FILE *fp;
if((fp = fopen("C:\\tcs.txt","a+")) == NULL)
{
gotoxy(N+18, N+2);
printf("ļܴ\n");
exit(0);
}
if((score[1] = fgetc(fp)) != EOF);
else
score[1] = 0;
return 0;
}

int File_out() //
{

FILE *fp;
if(score[1] > score[0])
{gotoxy(10,10);
color(12);
puts("ʧ Ү");
gotoxy(0,N+2);
return 0;
}
if((fp = fopen("C:\\tcs.txt","w+")) == NULL)
{
printf("ļܴ\n");
exit(0);
}
if(fputc(--score[0],fp)==EOF)
printf("ʧ\n");
gotoxy(10,10);
color(12);
puts("ϲƼ¼");
gotoxy(0,N+2);
return 0;
}

void Free(char **snake, int len) //ͷſռ
{
int i;
for (i = 0; i < len; ++i)
free(snake[i]);
free(snake);
}

int main(void)
{
int len;
char ch = 'g';
char a[N+2][N+2] = {{0}};
char **snake;
srand((unsigned)time(NULL));
color(11);
File_in();
init(a, &snake, &len);
Manual();
while (ch != 0x1B) // ESC
{
Draw(snake, len);
if (!apple[2]) {
apple[0] = rand()%N + 1;
apple[1] = rand()%N + 1;
apple[2] = 1;
num++;
if(num>8)
num=0;
}
Sleep(200-score[3]*10);
setbuf(stdin, NULL);
if (kbhit())
{
gotoxy(0, N+2);
ch = getche();
}
snake = Move(snake, ch, &len);
if (Block(snake[0])==1)
{
gotoxy(N+2, N+2);
puts("");
File_out();
Free(snake, len);
getche();
exit(0);
}
}
Free(snake, len);
exit(0);
}

׷

DEVԱ룬ֳļܴ
ֻļ

һα༭ʱ Ƽ2017-09-16 17:48:18
СӷǷ
СӷǷ


СӷǷǣc̰ߵٶȿƳô

鷳ЩҴ𰸣лл
Ľѱ3985˵

  1. Sleepʱ̰ߵٶȡ

    Sleep
    ܣ ִйһʱ
    void Sleep(DWORD dwMilliseconds);
    VCʹôͷļ
    #include
    SleepͷļWinBase.h
    gccУʹõͷļgcc汾IJͬͬ
    #include
    Sleep()λΪ룬sleep()λΪ루ҪȷusleepλΪ΢룩
    ֵ
    /̹߳𵽲ָʱ򷵻0źж򷵻ʣ

  2. ̣

    / *--------------------snake.h --------------------*/
    #ifndef SNAKE_H
    #define SNAKE_H
     
    #define LEFT 'a'
    #define RIGHT 'd'
    #define DOWN 's'
    #define UP 'w'
    #define ESC 27
     
    #define N 200               /*ߵ󳤶*/
     
    char key;                   /*ư*/
     
    struct Food
    {
         int x;                   /*ʳĺ*/
         int y;                   /*ʳ*/
         int yes;                 /*жǷҪʳı*/
    }food;                        /*ʳĽṹ*/
     
    struct Snake
    {
         int x[N];
         int y[N];
         int node;                /*ߵĽ*/
         int direction;           /*ƶ*/
         int life;                /* ߵ,0,1*/
    }snake;
    #endif



    / *--------------------snake.c --------------------*/
    #include 
    #include 
    #include 
    #include 
    #include 
    #include "snake.h"
     
    int score = 0;
    int gamespeed = 100;                //ٶ
     
    static void Init(void);             /*ͼ*/
    static void Close(void);            /*ͼν*/
    static void Game_interface(void);   /*Ϸ*/
    static void GameOver(void);         /*Ϸ*/
    static void GamePlay(void);         /*Ϸ*/
    static void PrScore(void);          /*ɼ*/
     
    /**/
    int main(void)
    {
         Init();                
         Game_interface();                
         GamePlay();             
         Close();                
         return 0;
    }
     
    /*ͼ*/
    static void Init(void)
    {
        int gd=9,gm=2;
     
        initgraph(&gd,&gm," ");
        cleardevice();
    }
     
    /* ʼ棬ϽΪ5040½Ϊ610460Χǽ */
    static void Game_interface(void)
    {
         int i;
     
         setcolor(LIGHTCYAN);                           /*setbkcolor(LIGHTGREEN);*/
         setlinestyle(PS_SOLID,0,1);                    /**/
         for(i=50;i<=600;i+=10)                          /*߿*/
         {
             rectangle(i,40,i+10,49);                   /*ϱ߿*/
             rectangle(i,451,i+10,460);                 /*±߿*/
         }
         for(i=40;i<=450;i+=10)
         {
             rectangle(50,i,59,i+10);                   /*߿*/
             rectangle(601,i,610,i+10);                 /*ұ߿*/
         }
    }
     
    /* Ϸ */
    static void GamePlay(void)
    {
         int i;
          
         srand(time(NULL));                             /**/
         food.yes = 1;                                  /*1ʾҪʳ,0ʾѾʳ*/
         snake.life = 0;                                /**/
         snake.direction = 1;                           /**/
         snake.x[0] = 100;
         snake.y[0] = 100;                             
         snake.x[1] = 110;
         snake.y[1] = 100;
         snake.node = 2;                                /**/
     
         PrScore();                                     /*÷*/
         while(1)                                       /*ظϷ,ѹESC*/
         {
             while( !kbhit() )                          /*ûа,Լƶ*/
             {
                 if(food.yes == 1)                      /*Ҫʳ*/
                 {
                     food.x = rand()%400 + 60;
                     food.y = rand()%350 + 60;
                     while(food.x%10 != 0)              /*ʳֺʳܹ,ſ߳Ե*/
                         food.x++;
                     while(food.y%10 != 0)
                         food.y++;
                     food.yes = 0;                      /*ʳ*/
                 }
                 if(food.yes == 0)                      /*ʳ˾Ҫʾ*/
                 {
                     setcolor(GREEN);
                     rectangle(food.x,food.y,food.x + 10,food.y - 10);
                 }
     
     
                 for(i=snake.node-1;i>0;i--)          /*ߵÿǰƶ,Ҳ̰ߵĹؼ㷨*/
                 {
                     snake.x[i] = snake.x[i-1];
                     snake.y[i] = snake.y[i-1];
                 }
                 /*1,2,3,4ʾ,,,ĸ,ͨжƶͷ*/
                 switch(snake.direction)
                 {
                     case 1:
                         snake.x[0] += 10;
                         break;
                     case 2:
                         snake.x[0] -= 10;
                         break;
                     case 3:
                         snake.y[0] -= 10;
                         break;
                     case 4:
                         snake.y[0] += 10;
                         break;
                 }
                 /* ߵĵĽڿʼжǷײԼ */
                 for(i=3;i             {
                     if((snake.x[i] == snake.x[0]) && (snake.y[i] == snake.y[0]))
                     {
                         GameOver();                  /*ʾʧ*/
                         snake.life = 1;
                         break;
                     }
                 }
                 if((snake.x[0] < 55) || (snake.x[0] > 595) || (snake.y[0] < 55) || (snake.y[0] > 455))     /*Ƿײǽ*/
                 {
     
     
                     GameOver();                                            /*Ϸ*/
                     snake.life = 1;                                        /**/
                 }
                 if(snake.life == 1)                                        /*жԺ,ѭ¿ʼ*/
                     break;
                 if((snake.x[0] == food.x) && (snake.y[0] == food.y))       /*ԵʳԺ*/
                 {
                     setcolor(BLACK);                                       /*ѻϵʳﶫȥ*/
                     rectangle(food.x,food.y,food.x+10,food.y-10);
                     snake.x[snake.node] = -20;
                     snake.y[snake.node] = -20;
     
                     /* µһȷڿλ,´ѭȡǰһڵλ */
     
                     snake.node++;                      /*ߵ峤һ*/
                     food.yes = 1;                      /*Ҫµʳ*/
                     score += 10;
                     PrScore();                         /*µ÷*/
                 }
                 setcolor(RED);                         /**/
     
     
                 for(i=0;i                 rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
                 Sleep(gamespeed);                        /*ӳٿ̰ٶ*/                
                 setcolor(BLACK);                        /*úɫȥߵĵһ*/
                 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*/
              
             if(snake.life == 1)                        /*ѭ*/
                 break;
              
             key=getch();                          /*հ*/
             if (key == ESC) break;                  /*ESC˳*/
              
             switch(key)
             {                                
                 case UP:
                     if(snake.direction != 4)           /*жǷ෴ķƶ*/
                         snake.direction = 3;
                     break;
                 case RIGHT:
                     if(snake.direction != 2)
                         snake.direction = 1;
                     break;
                 case LEFT:
                     if(snake.direction != 1)
                         snake.direction = 2;
                     break;
                 case DOWN:
                     if(snake.direction != 3)
                         snake.direction = 4;
                     break;
             }
     
         }/*endwhile(1)*/
    }
     
    /*Ϸ*/
    static void GameOver(void)
    {
         cleardevice();
         PrScore();
         setcolor(RED);
         setfont(56,0,"");
         outtextxy(200,200,"GAME OVER");
         getch();
    }
     
    /*ɼ*/
    static void PrScore(void)
    {
         char str[10];
     
         setfillstyle(YELLOW);
         bar(50,15,220,35);
         setcolor(BROWN);
         setfont(16,0,"");
         sprintf(str,"score:%d",score);
         outtextxy(55,16,str);
    }
     
    static void Close(void)
    {
         closegraph();
    }

һα༭ʱ Ƽ2017-09-01 20:05:54
j78903
j78903


j78903c̰Դô?

Ľѱ1144˵

    C̰Դ뾭ӦC/C++EXEļС

    ͨʹõIJϵͳWindowsϵͳڸϵͳõC/C++VC++ĿǰڴרԺУõİ汾VC++6.0

   VC++6.0˵̣

1.VC++6.0ͨFile˵µ OpenӲ˵̰ߴ

 

2.VC++6.0ͨBuild˵µ Compile xxxx.xxӲ˵̰ߴ

 

3.VC++6.0ͨBuild˵µ Execute xxxx.exeӲ˵̰߳

 

 

    VC++6¿еC/C++̰Դ루ްȨԼдӭ޸Ŀ

/*
C/C++̰Ϸzjlj,2015.3.16
*/
#define DEBUG 0 //ڵԽ׶ʱ DEBUGΪ 1
#include
#include
#include
#include
using namespace std;
void readini(FILE **fphead, int *score, char *argv[]) //һļӦiniļ,ȡ߼¼
{
 char filename[200],*pfilename;
 int flag=-1,i;
    
    strcpy(filename,argv[0]);
    for(i=0;filename[i]!='\0';i++)
 {
  if ('.'==filename[i])flag=1;
 }
 
 if(1==flag)
 {
 filename[i-1]='i';
    filename[i-2]='n';
 filename[i-3]='i';
 }
 else
 {
  filename[i]='.';
 filename[i+1]='i';
 filename[i+2]='n';
    filename[i+3]='i';
    filename[i+4]='\0';
 }
 for(;filename[i]!='\\'&&i>=0;i--)pfilename=&filename[i];
    if ( (*fphead=fopen(pfilename, "rb+"))==NULL)
 {
        if ( (*fphead=fopen(pfilename, "wb+"))==NULL)
  {
    printf("޷\"%s\"ļ\n",pfilename);
    system("pause");
       exit(0);
  }
    }
 else
 {
  fread(score,sizeof(int),1,*fphead);
 }
}
void writeini(FILE **fphead, int *score, char *argv[])  //һļӦiniļ,д߼¼
{
 char filename[200],*pfilename;
 int flag=-1,i;
   
    strcpy(filename,argv[0]);
    for(i=0;filename[i]!='\0';i++)
 {
  if ('.'==filename[i])flag=1;
 }
 
 if(1==flag)
 {
 filename[i-1]='i';
    filename[i-2]='n';
 filename[i-3]='i';
 }
 else
 {
  filename[i]='.';
 filename[i+1]='i';
 filename[i+2]='n';
    filename[i+3]='i';
    filename[i+4]='\0';
 }
 for(;filename[i]!='\\'&&i>=0;i--)pfilename=&filename[i];
    if ( (*fphead=fopen(pfilename, "wb+"))==NULL)
 {
          printf("޷д\"%s\"ļд!\n",pfilename);
    system("pause");
       exit(0);
 }
 else
 {
  rewind(*fphead);
  fwrite(score,sizeof(int),1,*fphead);
  fclose(*fphead);
 }
}
void gotoxy(int x,int y)//궨λ,궨λSetConsoleCursorPositionϽλ0,0Ȼ
{
COORD pos;
pos.X=2*y;
pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a)//ɫ
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}

void Refresh(int q[][22], int grade, int gamespeed, int length,int score) //  ̰
{
 int i,j;
 for(i=0;i<22;i++)
 {
  for(j=0;j<22;j++)
  {
   if(q[i][j]==0)//̿հ
   {
    gotoxy(i,j);
    color(11);
    cout<<"";
   }
   if(q[i][j]==1||q[i][j]==2)//ǽ
   {  
    gotoxy(i,j);
    color(11);
    cout<<"";
   }
   if(q[i][j]==3)//ͷ
   {  
    gotoxy(i,j);
    color(14);
    cout<<"";
   }
   if(q[i][j]==4)//
   {  
    gotoxy(i,j);
    color(12);
    cout<<"";
   }
     if(q[i][j]==5)//
   {  
    gotoxy(i,j);
    color(12);
    cout<<"";
   }
  }
  if(i==0) cout << "\t***********************";
  if(i==1) cout << "\tȼΪ" << grade;//ʾȼ
  if(i==3) cout << "\tԶǰʱ";
  if(i==4) cout << "\tΪ" << gamespeed << "ms";//ʾʱ
     if(i==6) cout << "\tʷ߷Ϊ:" << score << "";
  if(i==7) cout << "\tڵ÷Ϊ:" << (length+(grade-1)*8)*10 << "";
  if(i==8) cout << "\t**********************";
     if(i==9) cout << "\tϷ˵";
     if(i==10) cout << "\t(1)С̷";
  if(i==11) cout << "\tͷ˶;";
  if(i==12) cout << "\t(2)ÿһ";
  if(i==13) cout << "\tһ;";
  if(i==14) cout << "\t(3)ҧԼǽ";
  if(i==15) cout << "\tϷ";
  if(i==18) cout << "\t**********************";
     if(i==19) cout << "\tC/C++ҵ";
     if(i==20) cout << "\tzjlj,2015.03.16 ";
 }
}
 
int main(int argc, char *argv[]){
    int tcsQipan[22][22];     //  ̰һά(22*22ǽ)
    int i,j,score,directiontemp;
 FILE  *fpini;//*fpini Ϣļ
 readini(&fpini, &score, argv);//ȡiniļ߼¼
 if (score<0)//߳ɼСΪ㣬ļǸ
  score=0;
 while(1)
 {
  for(i=1;i<=20;i++)
   for(j=1;j<=20;j++)
    tcsQipan[i][j]=0;    //̰Ӧмհײֵı־0
  for(i=0;i<=21;i++)
   tcsQipan[0][i] = tcsQipan[21][i] = 1;      //̰Ӧǽڵı־1
  for(i=1;i<=20;i++)
   tcsQipan[i][0] = tcsQipan[i][21] = 2;      //̰Ӧǽڵı־2
  int tcsZuobiao[2][500];     //ߵ
  for(i=0; i<4; i++)
  {
   tcsZuobiao[0][i] = 1;//ͷx
   tcsZuobiao[1][i] = i + 1;//ͷy
  }
  int head = 3,tail = 0;//ʾͷβƫ
  for(i=1;i<=3;i++)
   tcsQipan[1][i]=4;    //
  tcsQipan[1][4]=3;       //ͷ
  int x1, y1;           // 
  srand(time(0));//
  do
  {
   x1=rand()%20+1;
   y1=rand()%20+1;
  }
  while(tcsQipan[x1][y1]!=0);//ڿհ״³
  tcsQipan[x1][y1]=5;//̰ӦϹӵı־5
  color(12);
  cout<<"\n\n\t\t\t\t̰Ϸʼ !"<  long start,starttemp;
  int grade = 1, length = 4;  //óʼȼߵijʼ
  int gamespeed = 500;  //óʼǰʱ
  for(i=3;i>=0;i--)
  {
   start=clock();
   while(clock()-start<=1000);
   system("cls");
   if(i>0)
    cout << "\n\n\t\t\t\t뵹ʱ" << i << endl;  //ʱʾ
   else
    Refresh(tcsQipan,grade,gamespeed,length,score);  //ʼʾ
  }
  int timeover=1,otherkey=1;//ʼʱʱͰжϲ
  char direction = 77;  // óʼ£˶
  int x=tcsZuobiao[0][head],y=tcsZuobiao[1][head];//ͷ굽xy
  while(1)//һϷ
  {
   start = clock();
   while((timeover=((starttemp=clock())-start<=gamespeed))&&!kbhit());//м»ʱ䳬Զǰʱֹѭ
   if(direction==72||direction==80||direction==75 ||direction==77)
   directiontemp=direction;//һη򰴼
            //starttemp=gamespeed+start-starttemp;//ͣʱ
   if(timeover)
   {
    #if (DEBUG==1)
    direction = getch();//Դ
             #else
    if((direction =getch())==-32)
     direction = getch();
       #endif
   }
             #if (DEBUG==1)//Դ
       start=clock();
    while(clock()-start<=2000);
    gotoxy(24,4);
    cout << "\tASCII"<<(int)direction<<"    "<             #endif
    if(!(direction==72||direction==80||direction==75 ||direction==77))
    {   
     otherkey=0;//  ǷotherkeyΪ0
    }
    else
    {
     otherkey=1;//  ΪotherkeyΪ1
    }
             if(direction==72 && directiontemp==80)//Է򰴼
    {
        direction=32;
     otherkey=0;
                 //start = clock();
        //while(clock()-start<=starttemp);
    }
    else if(direction==80 && directiontemp==72)
   {
        direction=32;//ðΪǷ
      otherkey=0;//  ΪǷotherkeyΪ0
                // start = clock();
       //while(clock()-start<=starttemp);//ȴʱ
    }
    else if(direction==75 && directiontemp==77)
    {
        direction=32;
     otherkey=0;
                 //start = clock();
        //while(clock()-start<=starttemp);
    }
    else if(direction==77 && directiontemp==75)
    {
        direction=32;
     otherkey=0;
                 //start = clock();
        //while(clock()-start<=starttemp);
    }
    
    
    switch(direction)//жϷ
    {
     case 72: x= tcsZuobiao[0][head]-1; y= tcsZuobiao[1][head];break;      // 
     case 80: x= tcsZuobiao[0][head]+1; y= tcsZuobiao[1][head];break;      // 
     case 75: x= tcsZuobiao[0][head]; y= tcsZuobiao[1][head]-1;break;      // 
     case 77: x= tcsZuobiao[0][head]; y= tcsZuobiao[1][head]+1;break;      // 
     default: break;
    }
   
 
    if(x==0 || x==21 ||y==0 || y==21)      // ͷǽڣϷ
    {  
     gotoxy(22,12);
     cout << "\tϷѽ!" << endl;
     if(score>=(length+(grade-1)*8)*10)//жǷƼ¼
     {
      gotoxy(10,7);
      color(12);
      cout << "ʧ Ү!" << endl;
      fclose(fpini);//رiniļ
     }
     else
     {
      gotoxy(10,7);
      color(12);
      cout << "ϲƼ¼" << endl;
      score=(length+(grade-1)*8)*10;
      writeini(&fpini, &score, argv);//дiniļ߼¼
     }
     gotoxy(23,12);
        cout << "س¿ʼESC˳Ϸ" << endl;//ʾʾ
     break;//˳þϷ
    }
    if(tcsQipan[x][y]!=0&&!(x==x1&&y==y1)&&tcsQipan[x][y]!=3) //   ͷϷ
    {
     gotoxy(22,12);
     cout << "\tϷѽ!" << endl;
     if(score>=(length+(grade-1)*8)*10)//жǷƼ¼
     {
      gotoxy(10,7);
      color(12);
      cout << "ʧ Ү!" << endl;
      fclose(fpini);//رiniļ
     }
     else
     {
      gotoxy(10,7);
      color(12);
      cout << "ϲƼ¼" << endl;
      score=(length+(grade-1)*8)*10;
      writeini(&fpini, &score, argv);//дiniļ߼¼
     }
     gotoxy(23,12);
     cout << "س¿ʼESC˳Ϸ" << endl;//ʾʾ
     break;//˳þϷ
    }
    /*
    Ϸʱĺ㷨ʼ
    */
    if(x==x1 && y==y1) //  Թӣȼ1
    {   
     length ++;
     if(length>=8)//ȴڵ8¼㳤ȣȼ1
     {
      length -= 8;//¼㳤
      grade ++;//ȼ1
      if(gamespeed>50)//ٶΪ50
       gamespeed = 550 - grade * 50; // ıԶǰʱ
     }
     tcsQipan[x][y]= 3;//̰Ӧͷ־Ϊͷ־3
     tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = 4;//̰Ӧԭͷ־Ϊ־4
     head = (head+1)%400;//ֹԽ
     tcsZuobiao[0][head] = x;//ͷx
     tcsZuobiao[1][head] = y;//ͷy
     do//
     {
      x1=rand()%20+1;
      y1=rand()%20+1;
     }
     while(tcsQipan[x1][y1]!=0);//ڿհ״³
     tcsQipan[x1][y1]=5;//̰ӦϹӵı־5
     gotoxy(22,12);
     cout << "\tϷ!" << endl;
     Refresh(tcsQipan,grade,gamespeed,length,score);
    }
    else  //  Թ
    {  
     if(otherkey)
     {
      tcsQipan [tcsZuobiao[0][tail]][tcsZuobiao[1][tail]]=0;
      tail=(tail+1)%400;//ֹԽ
      tcsQipan [tcsZuobiao[0][head]][tcsZuobiao[1][head]]=4;
      head=(head+1)%400;//ֹԽ
      tcsZuobiao[0][head]=x;//ͷx
      tcsZuobiao[1][head]=y;//ͷy
      tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]]=3;
      gotoxy(22,12);
      cout << "\tϷ!" << endl;
      Refresh(tcsQipan,grade,gamespeed,length,score);
     }
     else
     {
      gotoxy(22,12);
      cout << "\tϷͣ!" << endl;
     }
    }
    /*
    Ϸʱĺ㷨
    */
       }
    while(1)
    {
     while(!kbhit());
     if((direction =getch())==13)//سʼһ
      break;
     if(direction ==27)//ESC˳Ϸ
      exit(0);
    }
       system("cls");//Ļ¿ʼ
 }
 return 0;
}

һα༭ʱ Ƽ2017-09-10 07:05:52
网站地图

银河1331官网