当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

c语言小游戏代码

更新:02-11 整理:39baobao.com
字体:

[c语言中 beep是个什么函数]是发声函数,运行后通过主板喇叭唱出旋律,可以试试下面: TC 试: #include<dos.h> #include<conio.h> #include<stdlib.h> /* this founction plays sound until hit any key */ v...+阅读

最基础的贪吃蛇的代码#include#include//基本型态定义。支援型态定义函数。使用者界面函数 图形装置界面函数。#include//用户通过按键盘产生的对应操作 (控制台) #include#include//日期和时间头文件 #define LEN 30#define WID 25int Snake[LEN][WID] = {0}; //数组的元素代表蛇的各个部位 char Sna_Hea_Dir = 'a';//记录蛇头的移动方向int Sna_Hea_X, Sna_Hea_Y;//记录蛇头的位置int Snake_Len = 3;//记录蛇的长度clock_t Now_Time;//记录当前时间,以便自动移动int Wait_Time ;//记录自动移动的时间间隔int Eat_Apple = 1;//吃到苹果表示为1int Level ;int All_Score = -1;int Apple_Num = -1;HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //获取标准输出的句柄//句柄 :标志应用程序中的不同对象和同类对象中的不同的实例 方便操控,void gotoxy(int x, int y)//设置光标位置 { COORD pos = {x,y}; //定义一个字符在控制台屏幕上的坐标POS SetConsoleCursorPosition(hConsole, pos); //定位光标位置的函数}void Hide_Cursor()//隐藏光标 固定函数 { CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(hConsole, &cursor_info); }void SetColor(int color)//设置颜色 { SetConsoleTextAttribute(hConsole, color);//是API设置字体颜色和背景色的函数 格式:SetConsoleTextAttribute(句柄,颜色); }void Print_Snake()//打印蛇头和蛇的脖子和蛇尾 { int iy, ix, color; for(iy = 0; iy

C语言里还有 srand()函数等。//头文件:stdlib.h if(color == 14) color -= rand() % 13 + 1; //变色 SetColor(color); gotoxy(ix*2, iy); printf("■"); } if(Snake[ix][iy] == Snake_Len) { gotoxy(ix*2, iy); SetColor(0xe); printf("≈"); } } }void Clear_Snake()//擦除贪吃蛇 { int iy, ix; for(iy = 0; iynul"); exit(0); }void Move_Snake()//让蛇动起来 { int ix, iy; for(ix = 0; ix0) { if(Snake[ix][iy] != Snake_Len) Snake[ix][iy] += 1; else Snake[ix][iy] = 0; } }Snake[Sna_Hea_X][Sna_Hea_Y] = 1;//处理蛇头 }void Get_Input()//控制蛇的移动方向 { if(kbhit()) { switch(getch()) { case 87: Sna_Hea_Dir = 'w'; break; case 83: Sna_Hea_Dir = 's'; break; case 65: Sna_Hea_Dir = 'a'; break; case 68: Sna_Hea_Dir = 'd'; break; default: break; } } if(clock() - Now_Time >= Wait_Time)//蛇到时间自动行走 { Clear_Snake(); Move_Snake(); Print_Snake(); Now_Time = clock(); } }void Init()//初始化 { system("title 贪吃毛毛蛇"); system("mode con: cols=80 lines=25"); Hide_Cursor(); gotoxy(61, 4); printf("You Score:"); gotoxy(61, 6); printf("You Level:"); gotoxy(61, 8); printf("The Lenght:"); gotoxy(61, 10); printf("The Speed:"); gotoxy(61, 12); printf("Apple Num:"); int i; for(i = 0; i50) ...

本文地址:https://www.39baobao.com/show/29_39580.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

谁会用c语言编一个音乐播放器 。。#include #include #include #include #include void main() { void set(int *set1,int *set2,char *f,char *n,int *t,int rate,int num); void music(int *set1,int *set2...

求一个单片机c语言音乐程序#include#define uchar unsigned char #define uint unsigned int sbit BEEP=P3^2; // 生日快乐歌的音符频率表,不同频率由不同的延时来决定 uchar code SONG_TONE[]={212,212...

跪求一个单片机生日快乐歌C语言程序#include <reg52.h> #define uint unsigned int #define uchar unsigned char sbit BEEP=P1^2;//接喇叭或蜂鸣器的接口 uint h,i; uint hz; uchar jiep; bit flag; uint code...

求c语言编写蜂咛器唱歌 7个音阶的从低到高的十六进制代码#include<windows.h> #define N 14 enum FREQUENCY{ Fc=131, Fd=147, Fe=165, Ff=175, Fg=196, Fa=220, Fb=247, Fc1=262, Fd1=294, Fe1=330, Ff1=349, Fg1=392, Fa1=440, F...

C语言问题之进制回文数我就只写回文数判定的函数,你自己调用就行了,其他的感觉你会 #include <stdlib.h> #include <string.h> int fun(int n) {int i,j; char s[30]; itoa(n,s,10); for(i=0,j=strl...

C语言程序题函数判断回文数# include //添加头文件 int main(void)//主函数 { int val; int m; int sum = 0;//定义三个整型变量,分别是val m sum,其中sum赋初值位0 printf("请输入您需要判断的数字:"); scanf(...

C语言:查找回文素数找出大于整数m且最靠近m的回文素数函数#include <stdio.h> #include <math.h> int IsPalin(int n){ char a[20]={},i=0,j; while(n > 0){ a[i] = n % 10; n = n / 10; i++; } i--; for(j=0;j<(i+1)/2;j++) if(a[j...

视频语言怎样转换首先你要找到这个电影的字幕文件 然后使用Subtitle Workshop、SUBmax、StrEdit等编辑软件编辑字幕 比如在电影播放到20分30秒的时候,男主角说“hello” 你就在字幕编辑中找到...

英雄联盟各种语言什么意思ID:你的游戏角色名字 楼主/房主/LZ:创建游戏房间的人 FB:1血,也是DOTA类游戏的魅力之一,FB的全称是firstblood,指第一个杀死的英雄,不光有击杀英雄的奖励,还会额外的奖励的100元(杀...