go语言贪吃蛇,go语言 python
c语言设计的贪吃蛇 帮我解释一下。。。
这个是代码
创新互联专注于蚌山网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供蚌山营销型网站建设,蚌山网站制作、蚌山网页设计、蚌山网站官网定制、微信平台小程序开发服务,打造蚌山网络公司原创品牌,更为您提供蚌山网站排名全网营销落地服务。
#include"time.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#define ESC 033
#define UP 0110
#define DOWN 0120
#define LEFT 0113
#define RIGHT 0115
#define X1 15
#define X2 40
#define Y1 2
#define Y2 20
#define N 15
/*************************************************************/
void food(int *b)
{
*b=random(X2-X1+1)+X1; b++; /*产生食物*/
*b=random(Y2-Y1+1)+Y1;
}
/*************************************************************/
void init(int (*a)[2],int *b)
{
int i,j;
food(b);
a[0][0]=random(X2-X1-5)+X1+3; /*随机生成一3断长的snack */
a[0][1]=random(Y2-Y1-5)+Y1+3;
switch(random(4))
{case 0:i=-1; j=0; break;
case 1:i=1; j=0; break;
case 2:i=0; j=-1; break;
case 3:i=0; j=1; break;}
a[1][0]=a[0][0]+i;
a[1][1]=a[0][1]+j;
a[2][0]=2*a[1][0]-a[0][0];
a[2][1]=2*a[1][1]-a[0][1];
window(1,1,80,25);
textbackground(BLACK);
clrscr();
window(X1,Y1,X2,Y2);
textbackground(BLUE);
clrscr();
window(1,1,80,25);
textbackground(YELLOW);
textcolor(YELLOW);
for(i=0;i3;i++)
{gotoxy(a[i][0],a[i][1]);
cprintf("%c",'%');}
gotoxy(b[0],b[1]);
cprintf("%c",'*');
}
/*************************************************************/
void putout(int a[][2],int n,int b[],int step)
{
textbackground(YELLOW);
gotoxy(a[0][0],a[0][1]);
cprintf("%c",'%');
gotoxy(b[0],b[1]);
cprintf("%c",'#');
textbackground(BLUE);
gotoxy(a[n][0],a[n][1]);
cprintf("%c",' '); /*清除蛇的尾部*/
gotoxy(X1,Y2+2);
cprintf("Length:%2d Delay:%3dms",n,step);
}
/*************************************************************/
void direction(int a[][2],int n)
{
char ch;
int i,across,down;
across=a[0][0]-a[1][0];
down=a[0][1]-a[1][1];
if(kbhit())
{ch=getch();
while(ch==0)
ch=getch();
if(ch==LEFT) {if(across!=1) {down=0; across=-1;}}
else if(ch==RIGHT) {if(across!=-1) {down=0; across=1; }}
else if(ch==UP) {if(down!=1) {down=-1; across=0; }}
else if(ch==DOWN) {if(down!=-1) {down=1; across=0; }}
else if(ch==ESC) exit(1);
}
for(i=n;i0;i--)
{a[i][0]=a[i-1][0];
a[i][1]=a[i-1][1];
}
a[0][0]+=across;
a[0][1]+=down;
}
/*************************************************************/
int die(int a[][2],int n)
{int i;
if(a[0][0]X2||a[0][0]X1||a[0][1]Y2||a[0][1]Y1) return 1;
for(i=4;i=n;i++)
{if(a[0][0]==a[i][0]a[0][1]==a[i][1])
return 1;
}
return 0;
}
/*************************************************************/
int meet(int a[][2],int b[])
{
if(a[0][0]==b[0]a[0][1]==b[1]) return 1;
return 0;
}
/*************************************************************/
void delay2(int step)
{float t;
static clock_t start=0;
clock_t end;
do{end=clock();
t=(end-start)/CLK_TCK;
}
while(t*1000step);
start=clock();
}
/*************************************************************/
void ifdie()
{
char ch;
gotoxy(X1,Y2+2);
printf("You die. Do you want to go on?(Y/N)");
ch=getch();
if(ch!='y') exit(1);
}
/*************************************************************/
void ifwin()
{
char ch;
gotoxy(X1,Y2+2);
puts("You win. Do you want to continue?(Y/N)");
ch=getch();
if(ch=='y') return;
exit(1);
}
/**************************************************************/
int main()
{
int a[N][2],b[2];
int n,step;
REPLAY:
for(step=300;1;step*=.9)
{randomize();
init(a,b);
for(n=3;nN;n++)
{do{putout(a,n,b,step);
delay2(step);
direction(a,n);
if(die(a,n))
{putout(a,n,b,step);
ifdie();
goto REPLAY;
}
}
while(!meet(a,b));
food(b);
}
ifwin();
}
return 0;
}
汇编语言贪吃蛇
;*****************************************************************
;程序名 : 贪吃蛇
;程序作者: Softgsy
;编程时间: 2008-04-19
;修改时间: 2008-04-23;04-25;04-26
;*****************************************************************
;___________________________________________________文档__________
;函数功能:
;Protect和Recover : 保护和恢复寄存器现场
;Display : 显示蛇头的'*'和用' '覆盖旧蛇尾的'*'
;Curser : 将光标置于方框外
;Move : 移动蛇,并判断蛇长是否已经满15,并置al:ffh
;nextstep : 蛇移动一步
;judge : 判断蛇的前方是什么(al作接口):
; 00h:食物 0fh:正常 f0h:障碍
;food : 置食物
;_________________________________________________________________
include macro_snake.inc
;*********************************************数据段定义**********
Data segment
snake dw 0101h,0102h,0103h,13 dup(0000h)
graph db 9 dup('#'),0dh,0ah,'#*** #',0dh,0ah
db 11 dup('#',7 dup(' '),'#',0dh,0ah)
db 9 dup('#'),0dh,0ah,'$'
win db 'You Win!',0dh,0ah,'$'
lose db 'What a pity!',0dh,0ah,'$'
direction dw 0064h
speed1 equ 1000h
speed2 equ 0100h
Data ends
;*********************************************堆栈段定义**********
Stack segment stack
dw 0ffh dup(?)
Stack ends
;*********************************************附加段定义**********
Extra segment
snake_food dw 0b06h,0703h,0c01h,0204h,0606h,0a02h,0405h,0905h
dw 0101h,0c04h,0502h,0207h,0c07h,0604h,0c02h,0304h
Extra ends
;*********************************************代码段定义**********
Code segment
assume cs:Code,ds:Data,ss:Stack,es:Extra
;*********************************************主程序定义**********
start:
mov ax,Data
mov ds,ax
mov ax,Stack
mov ss,ax
mov ax,Extra
mov es,ax
mov dx,offset graph
mov ah,09h
int 21h
mov bx,0000h ;蛇尾位置及bh页号
mov si,0002h ;蛇头位置
mov di,offset snake_food
call food
xor ax,ax
outloop:
cmp al,0ffh
jz gamewin
cmp al,0f0h
jz gamelose
call nextstep
jmp outloop
gamewin:
mov dx,offset win
mov ah,09h
int 21h
jmp gameover
gamelose:
mov dx,offset lose
mov ah,09h
int 21h
gameover:
mov ax,4c00h
int 21h
;*********************************************子程序定义**********
;_____________________________________________向前走一步__________
nextstep proc near
input:
get_direction direction,speed1,speed2
mov ax,direction
cmp al,'a'
jz m_l
cmp al,'A'
jz m_l
cmp ah,4bh
jz m_l
cmp al,'d'
jz m_r
cmp al,'D'
jz m_r
cmp ah,4dh
jz m_r
cmp al,'w'
jz m_u
cmp al,'W'
jz m_u
cmp ah,48h
jz m_u
cmp al,'s'
jz m_d
cmp al,'S'
jz m_d
cmp ah,50h
jz m_d
jmp input
m_l:
Move sub,0001h
jmp ret_
m_r:
Move add,0001h
jmp ret_
m_u:
Move sub,0100h
jmp ret_
m_d:
Move add,0100h
jmp ret_
ret_: ret
nextstep endp
;_____________________________________________判断下一步__________
judge proc near ;00h:食物,0fh:正常,f0h:障碍
push cx
mov ah,02h
int 10h
mov ah,08h
int 10h
mov ch,al
mov al,00h
cmp ch,'o'
jz outjudge
mov al,0fh
cmp ch,' '
jz outjudge
mov al,0f0h
outjudge:
pop cx
ret
judge endp
;_____________________________________________置食物函数__________
food proc near
Protect
inc si
and si,000fh
mov cx,bx
getfood:
add di,0002h
cmp di,20h
jb go_on
xor di,di
go_on:
mov bx,cx ;保证每次检查都从尾开始
lp:
shl bx,1
mov dx,es:[di]
cmp dx,snake[bx]
jz getfood
shr bx,1
inc bx
and bx,000fh
cmp bx,si
jnz lp
mov dx,es:[di]
mov ah,02h
int 10h
mov al,'o'
mov ah,0eh
int 10h
Curser
Recover
ret
food endp
;*********************************************子程序结束**********
Code ends
end start
贪吃蛇用英语怎么说_贪吃蛇的单词词组
贪吃蛇游戏是经典手机游戏,既简单又耐玩,它的英文也是如此地好学哦。以下是我给大家带来贪吃蛇英语说法,以供参阅。
贪吃蛇英语说法
1.snake
2.Gluttonous Snake
贪吃蛇的相关 短语
快乐的贪吃蛇 Happy Snake
金属贪吃蛇 Metal Snake Pro
愤怒贪吃蛇 Angry Snake
可可贪吃蛇 Coco Monster
暗影贪吃蛇 Shadow Snake
贪吃蛇对决 Snake Showdown
贪吃蛇的英语例句
1. The use of LabVIEW graphical development language procedures Snake game.
利用图形化语言LabVIEW开发的贪吃蛇游戏程序.
2. OpenGL write Snake small games to run on Linux.
OpenGL写的贪吃蛇小游戏在Linux下运行.
3. Is a small game procedures, Snake game, provides a complete procedure to run.
是一个小游戏程序, 贪吃蛇游戏, 提供了完整了程序,能够运行.
4. This is my first game Snake, do a bit rough, want some help for beginners.
这是我的第一个游戏贪吃蛇, 做的比较粗糙, 希望对于初学者有所帮助了.
5. A game program is very small, very simple screen mobile phone game Snake flash version.
一款游戏程序很小巧, 画面很简单的贪吃蛇手机游戏闪光版.
6. Snake upgraded version than the version before the increase of double battle mode!
贪吃蛇升级版比之前的版本增加了双人对战模式!
7. Old wine in new bottles, this tour is to hand the improved version of the Snake.
旧瓶装新酒, 这款手游是贪吃蛇的改进版.
蛇的英语例句
1. The slow-worm is in fact not a snake but a legless lizard.
蛇蜥其实不是蛇,而是无脚的蜥蜴。
2. He felt as if a serpent had spat venom into his eyes.
他感觉就像有一条蛇朝自己的双眼里喷射了毒液。
3. He'd like to go on safari to photograph snakes and tigers.
他想进行一次观兽旅行,拍摄一些蛇类和老虎的照片。
4. I haven'tthe faintest idea how to care for a snake.
我对养蛇一无所知。
5. Snakes are carnivorous.
蛇是食肉动物。
6. Most people seem to be petrified of snakes.
好像很多人都怕蛇。
7. The snake coiled up, ready to strike.
那条蛇盘绕起来准备攻击。
8. a snake's poison glands
蛇的毒腺
9. I'm petrified of snakes.
我特别怕蛇。
10. The snake slithered away as we approached.
我们一走近,蛇就爬走了。
11. a snake sloughing its skin
正在蜕皮的蛇
12. a snake coiled up in the grass
一条蛇盘在草丛里
13. The snake can squirt poison from a distance of a metre.
这种蛇能把毒液喷射到一米处远。
14. The snake slowly uncoiled.
蛇慢慢地展开了盘着的身体。
15. The snake was curled up in the long grass.
贪吃蛇c语言代码
#define N 200
#include graphics.h
#include stdlib.h
#include dos.h
#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();
}
/*开始画面,左上角坐标为(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;i0;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;isnake.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.xsnake.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;isnake.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==UPsnake.direction!=4)
/*判断是否往相反的方向移动*/
snake.direction=3;
else
if(key==RIGHTsnake.direction!=2)
snake.direction=1;
else
if(key==LEFTsnake.direction!=1)
snake.direction=2;
else
if(key==DOWNsnake.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();
}
分享名称:go语言贪吃蛇,go语言 python
网站链接:http://scyanting.com/article/hsipsg.html