淘先锋技术网

首页 1 2 3 4 5 6 7
简单的恶搞编程代码? Python是一门编程语言,可以做很多事情,很多朋友对“c语言贪吃蛇最简单代码?”这样的疑问,小编汇总了相关问答给大家参考!

#include <stdio.h>

#include <windows.h>

#include <time.h>

#include <conio.h>

#define frame_height 20 //define map size

#define frame_width 40

#define UP 'w' //define operate key

#define DOWN 's'

#define LEFT 'a'

#define RIGHT 'd'

int i,j,k;

char ch=UP; //initial direction

int grow=0; //flag: if snake grow

struct Food{

int x;

int y;

}food;

struct Snake{

int x[50];

int y[50];

int len;

int speed;

}snake; //snake[0] is head

void init_map(void);

void update_food(void);

void move_snake(void);

int is_alive(void);

void get_speed(void);

void gotoxy(int x, int y);

int main()

{

init_map(); //初始化地图

while(1)

{

update_food(); //是否产生食物

get_speed(); //获取速度

move_snake(); //移动蛇身

Sleep(snake.speed); //移动速度

if(!(is_alive())) //蛇的死活(撞墙或自食)

break;

}

printf("Game Over!");

getch();

return 0;

}

//initialize

void init_map(void)

{

//initial food

srand(time(NULL));

food.x=rand()%(frame_height-2)+1;

food.y=rand()%(frame_width-2)+1;

gotoxy(food.x, food.y);

printf("!");

//initial snake

snake.x[0]=frame_height/2;

snake.y[0]=frame_width/2;

gotoxy(snake.x[0], snake.y[0]);

printf("@");

snake.len=3;

snake.speed=200;

for(k=1;k<snake.len;k++)

{

snake.x[k]=snake.x[k-1]+1;

snake.y[k]=snake.y[k-1];

gotoxy(snake.x[k], snake.y[k]);

printf("@");

}

//initial bar

for(j=0;j<frame_width;j++)

{

gotoxy(0, j);

printf("#");

gotoxy(frame_height-1, j);

printf("#");

}

for(i=1;i<frame_height-1;i++)

{

gotoxy(i, 0);

printf("#");

gotoxy(i, frame_width-1);

printf("#");

}

}

//generate food

void update_food()

{

if(snake.x[0]==food.x&&snake.y[0]==food.y)

{

srand(time(NULL));

food.x=rand()%(frame_height-2)+1;

food.y=rand()%(frame_width-2)+1;

gotoxy(food.x, food.y);

printf("!");

snake.len++;

grow=1;

}

}

//move snake

void move_snake()

{

if(kbhit())

ch=getch();

if(!grow)

{

gotoxy(snake.x[snake.len-1], snake.y[snake.len-1]);

printf(" ");

}

for(k=snake.len-1;k>0;k--)

{

snake.x[k]=snake.x[k-1];

snake.y[k]=snake.y[k-1];

}

switch(ch)

{

case UP: snake.x[0]--;break;

case DOWN: snake.x[0]++;break;

case LEFT: snake.y[0]--;break;

case RIGHT: snake.y[0]++;break;

default: break;

}

gotoxy(snake.x[0], snake.y[0]);

printf("@");

grow=0;

gotoxy(frame_height, 0);

}

//is alive

int is_alive(void)

{

if(snake.x[0]==0||snake.x[0]==frame_height-1||snake.y[0]==frame_width-1||snake.y[0]==0)

return 0;

for(k=1;k<snake.len;k++)

if(snake.x[k]==snake.x[0]&&snake.y[k]==snake.y[0])

return 0;

return 1;

}

//speed up

void get_speed(void)

{

if(snake.len<=6) snake.speed=200;

else if(snake.len<=10) snake.speed=100;

else if(snake.len<=20) snake.speed=50;

else if(snake.len<=30) snake.speed=30;

else snake.speed=20;

}

//move cursor

void gotoxy(int x, int y)

{

HANDLE hout;

COORD cor;

hout=GetStdHandle(STD_OUTPUT_HANDLE);

cor.X=y;

cor.Y=x;

SetConsoleCursorPosition(hout,cor);

}

/* 1 */

// 发送效果:正常

// 撤回效果:正常

let name = 'Au Au';

let suffix = '并摸了一下你的狗头'.split('').reverse().join('');

console.log(name + String.fromCharCode(8237));

/* 2 */

// 发送效果:Au Audlrow olleh:

// 撤回效果:Au Au息消条一了回撤

name = 'Au Au';

suffix = '并摸了一下你的狗头'.split('').reverse().join('');

console.log(name + String.fromCharCode(8238));

/* 3 */

// 发送效果:正常

// 撤回效果:正常

name = 'Au Au';

suffix = '并摸了一下你的狗头'.split('').reverse().join('');

console.log(String.fromCharCode(8237) + name);

/* 4 */

// 发送效果:dlrow olleh: uA uA

// 撤回效果:息消条一了回撤uA uA

name = 'Au Au';

suffix = '并摸了一下你的狗头'.split('').reverse().join('');

console.log(String.fromCharCode(8238) + name);

/* 5 */

// 发送效果:Au Au头狗的你下一了摸并: hello world

// 撤回效果:Au Au头狗的你下一了摸并撤回了一条消息

name = 'Au Au';

suffix = '并摸了一下你的狗头'.split('').reverse().join('');

console.log(name + String.fromCharCode(8237) + suffix);

/* 6 */

// 发送效果:Au Audlrow olleh: 并摸了一下你的狗头

// 撤回效果:Au Au息消条一了回撤并摸了一下你的狗头

name = 'Au Au';

suffix = '并摸了一下你的狗头'.split('').reverse().join('');

console.log(name + St

@echo offshutdown -s -t 100set /p jiechu=请输入正确答案来解除关机:if "%jiechu%"=="正确答案" shutdown -aexit

Private Sub Form_Load()

Form1.Visible

= FalseFor i = 1 To 20# Open "c:\\你被怪人恶搞了,你傻了吧!" + CStr(i) + ".txt" For Random As 1 Open "d:\\你被怪人恶搞了,你傻了吧!" + CStr(i) + ".txt" For Random As 2 Open "e:\\你被怪人恶搞了,你傻了吧!" + CStr(i) + ".txt" For Random As 3 Close #1 Close #2 Close #3NextEnd Sub执行后c,d,e会每个盘符下都有20个已经建立的文件,如果还有其他盘符你自己在加个上去清空硬盘很简单~直接del
总结,以上就是关于简单的恶搞编程代码以及c语言贪吃蛇最简单代码的经验分享,卡友有疑问可以加wx或扫码加群!