- UID
- 259606
- 在线时间
- 0 小时
- 最后登录
- 2013-9-6
- 注册时间
- 2012-10-26
- 宅魂
- 46 点
- 贡献
- 30 点
- 宅币
- 268 枚
- 宅の石(入宅度)
- 0 块
- 元气(技能点)
- 6 点
- 活跃
- 0 ℃
- 听众
- 4
- 收听
- 0
该用户从未签到
New Game
- 积分
- 781
|
发表于 2012-12-8 14:49:47
|
显示全部楼层
本帖最后由 林林牛雜_ 于 2012-12-8 16:09 编辑
写个人形贪吃蛇C程序可不可以→ →
虽然不是很像人形→ →
找不到什么奇葩的形状了所以
【其实像肉山大魔王啊2333333333333
OTL
不可以鄙视工♂科男的浪漫!!!!!!!!!!!!!
话说我是学电子的因此。。。
我会焊电路板(?
据说要附上微博
@林林牛雜_
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
struct Node
{
int x;
int y;
struct Node *pre;
struct Node *next;
};
struct Food
{
int x;
int y;
char c;
};
void main()
{
int a[15][15]={0};
int i,j,t,flag=0;
char c='d',c1='d';
struct Food food={5,8,'A'};;
int gameover=0;
struct Node *head,*p,*rear,*pt;
head=(struct Node *)malloc(sizeof(struct Node));
head->x=5;
head->y=8;
head->pre=NULL;
head->next=NULL;
rear=head;
srand((unsigned)time(NULL));
while(1)
{
if(food.x==head->x && food.y==head->y)
{
p=(struct Node *)malloc(sizeof(struct Node));
pt=head;
while(pt->next!=NULL)
pt=pt->next ;
p->pre= pt;
pt->next = p;
p->next=NULL;
rear=p;
food.x=rand()%15;
food.y=rand()%15;
food.c=65+rand()%26;
flag=1;
t=0;
while(flag==1)
{
if(t>5)
break;
flag=0;
pt=head;
while(pt!=NULL)
{
if(food.x==pt->x && food.y==pt->y)
{
flag=1;
food.x=rand()%15;
food.y=rand()%15;
break;
}
pt=pt->next;
}
t++;
}
if(t>5)
{
if(c=='d')
{
food.x=head->x+1;
food.y=head->y;
if(food.x>=15)
food.x-=15;
}
else if(c=='a')
{
food.x=head->x-1;
food.y=head->y;
if(food.x<0)
food.x+=15;
}
else if(c=='w')
{
food.x=head->x;
food.y=head->y+1;
if(food.y>=15)
food.y-=15;
}
else if(c=='s')
{
food.x=head->x;
food.y=head->y-1;
if(food.y<0)
food.y+=15;
}
}
}
if(kbhit())
{
c1=getch();
if(c1==27)
break;
if(c!='d' && c1=='a')
c=c1;
else if(c!='a' && c1=='d')
c=c1;
else if(c!='w' && c1=='s')
c=c1;
else if(c!='s' && c1=='w')
c=c1;
}
pt=rear;
while(pt!=head )
{
pt->x=pt->pre->x;
pt->y=pt->pre->y;
pt=pt->pre;
}
if(c=='d')
{
head->y+=1;
if(head->y>=15)
head->y-=15;
}
else if(c=='a')
{
head->y-=1;
if(head->y<0)
head->y+=15;
}
else if(c=='w')
{
head->x-=1;
if(head->x<0)
head->x+=15;
}
else if(c=='s')
{
head->x+=1;
if(head->x>=15)
head->x-=15;
}
pt=head->next;
while(pt!=NULL)
{
if(head->x==pt->x && head->y==pt->y)
{
gameover=1;
break;
}
pt=pt->next ;
}
if(gameover==1)
break;
system("cls");
printf(" ───────────────\n");
for(i=0;i<15;i++)
{
printf("│");
for(j=0;j<15;j++)
{
flag=0;
pt=head;
while(pt!=NULL)
{
if(i==pt->x && j==pt->y)
{
if(pt==head)
printf("○");
else
printf("人");
flag=1;
break;
}
pt=pt->next;
}
if(flag==0)
{
if(i==food.x && j==food.y)
{
putchar(food.c);
putchar(food.c);
continue;
}
printf(" ");
}
}
printf("│");
putchar('\n');
}
printf(" ───────────────\n");
_sleep(200);
}
if(gameover==1)
puts("game over!\n");
getch();
} |
-
是不是要撸个图上来
评分
-
查看全部评分
|