基于c语言的游戏毕业论文
keyishangwangcha
还是靠自己写吧!
机顶盒上游戏开发可以么,也是用C语言写的目 录第一章 绪论 机顶盒的产生背景 机顶盒的发展及其现状 游戏模块设计的必要性 模块设计需要解决的问题 3第二章 系统开发环境及相关技术介绍 XX-XX硬件平台 XX操作系统 内核 任务机制 消息队列 信号量 C语言的特点 7第三章 开发流程 功能需求分析 可行性分析 模块设计 编码 测试 11第四章 系统设计 游戏模块接口设计 游戏的初始化 游戏的按键读取和转化 游戏的暂停、恢复和退出 游戏算法设计 推箱子游戏设计 俄罗斯方块游戏设计 黑白棋游戏设计 14结 论 16谢 辞 17参 考 文 献 18附录 推箱子游戏源程序 19
我这儿倒是有,不知道需要什么样子的?
c语言编程小游戏毕业论文
我是来做任务的~
#include <>#include <>#include <>int main(){ char name[100]; int usr_select; int system_select; int num; int usrwin=0,syswin=0,nowin=0; printf("please in put you name:\n"); scanf("%s",name); printf("please input how many games do you want to play:\n"); scanf("%d",&num); while (num == 0 || (num %2) == 0) { printf("the num must be singular,please input a right number again:\n"); scanf("%d",&num); } int temp = 1; for (temp;temp<=num; temp++) { printf("%d: input you chocice:(0:shi tou 1:jian zi 2:bu)",temp); scanf("%d",&usr_select); while( usr_select <0 || usr_select >2 ) { printf("your choice is error,please input again(0:shi tou 1: jian zi 2:bu)\n"); scanf("%d",&usr_select); } srand(time(0)); system_select= rand()%3; if(usr_select - system_select == -1 || usr_select-system_select == 2) { usrwin++; printf("you win!\n"); } else if(usr_select == system_select) { nowin++; printf("no one win\n"); temp--; } else { syswin++; printf("system win\n"); } } if(usrwin > syswin) printf("%s is winner!\n",name); else printf("system is winner!\n");}
#include ""#include ""#include ""char *words[3]={"石头","剪刀","布"};//本程序用S代表石头,C代表剪刀,P代表布//本程序假设用户所有的输入,都是遵循电脑的提示进行的正确输入,不考虑输入错误的处理void main(){ char name[81];//玩家姓名 int mode;//代表赛制 char input;//代表你出的东东 int you,computer;//代表你和电脑出的东东 int win,lose,deuce; srand( (unsigned)time( NULL ) ); //初始化随机数种子 printf("欢迎参加猜挙比赛,请输入您的名字:"); gets(name); printf("欢迎您,%s\n",name); printf("本次猜挙比赛,您想采取哪种赛制?(1.三局两胜\t2.五局三胜):"); scanf("%d",&mode);//此处不考虑用户输入1,2以外数字或非数字字符的情况 getchar();//过滤回车 if(mode==1) printf("您选择了三局两胜制\n"); else if(mode==2) printf("您选择了五局三胜制\n"); printf("比赛开始!!!\n"); win=lose=deuce=0; while(1) { printf("请出拳{石头:(S/s),剪刀(C/c),布(P/p)}:"); input=getchar(); //此处不考虑用户输入了其他字符的情况 getchar();//过滤回车 if(input=='S' || input=='s') you=0; else if(input=='C' || input=='c') you=1; else you=2; computer=rand()%3; printf("你出了%s,电脑出了%s\n",words[you],words[computer]); if(you-computer==-1 || you-computer==2) { win++; printf("你赢了\n"); } else if(you-computer==1 || you-computer==-2) { lose++; printf("你输了\n"); } else { deuce++; printf("平手\n"); } if((mode==1 && (win==2 || lose==2)) || (mode==2 && (win==3 || lose==3))) { if(win>lose) { printf("恭喜%s获得了最终胜利!\n",name); } else { printf("唉,你输了,下次再努力吧\n"); } break; } else { printf("目前你赢了%d局,输了%d局,平了%d次\n",win,lose,deuce); } }}
static void Main(string[] args)
{
string i = null;
do
{
("请输入一个整数(范围为1~100)\n如果要退出,请输入0!否则输入1!");
i = ();
if (().Equals("0"))
{
return;
}
} while (!().Equals("1"));
start:
Random ra = new Random();
int rndInt = (1, 100);
int input = 0;
do
{
("输入你猜的数值:");
i = ();
if (!(i, out input))
{
continue;
}
if (input > rndInt)
{
("猜大了\n\n");
}
else if (input < rndInt)
{
("猜小了\n\n");
}
} while (input != rndInt);
("恭喜你,猜对了!\n\n");
do
{
("若继续猜测输入Y,若退出则输入N!\n请输入:");
i = ();
if (().Equals("n", ))
{
return;
}
if (().Equals("y", ))
{
goto start;
}
} while (!().Equals("1"));
}
基于c语言的贪吃蛇毕业论文
#include <>#include <>#include <>#include <> /*引用的库函数*/#define LEFT 0x4b00#define RIGHT 0x4d00#define DOWN 0x5000#define UP 0x4800#define ESC 0x011b/*宏定义键名*/#define N 200int 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();/*随机数发生器*/;/*1表示需要出现新食物,0表示已经存在食物*/;/*活着*/;/*方向往右*/[0]=320;[0]=240;/*蛇头*/[1]=330;[1]=240; /*蛇的第二节位置*/;/*节数*/PrScore();/*输出得分*/while(1)/*可以重复玩游戏,压ESC键结束*/{while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/{if()/*需要出现新食物*/{()%360+70;()%250+60;while(!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/;while(!=0);;/*画面上有食物了*/}if()/*画面上有食物了就要显示*/{setcolor(GREEN);rectangle();}for(i=;i>0;i--)/*蛇的每个环节往前移动*/{[i]=[i-1];[i]=[i-1];}/*1,2,3,4表示右,左,上,下四个方向,通过这个控制来移动蛇头*/switch(){case 1: [0]+=10;break;case 2: [0]-=10;break;case 3: [0]-=10;break;case 4: [0]+=10;break;}for(i=3;i<;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/{if([i]==[0]&&[i]==[0]){GameOver();/*显示失败*/; /*蛇死*/break;}}/*如果蛇头碰到墙壁,蛇头从对面墙出来*/if([0]<50){[0]=450;/*如果蛇头越过左边界,则从右边界进入*/[0]=[0];/*纵坐标不变*/for(i=;i>0;i--){[i]=[i-1];[i]=[i-1]; /*蛇的其他节数向前推进*/}{setfillstyle(SOLID_FILL,0); /*设置填充模式和颜色,0表示黑色*/bar(50,55,455,315);/*bar是表示填充的范围的函数*/}}elseif([0]>450){[0]=50;/*如果蛇头越过右边界,则蛇头从左边界进入*/[0]=[0];/*纵坐标不变*/for(i=;i>0;i--){[i]=[i-1];[i]=[i-1]; /*蛇的其他节数向前推进*/}{setfillstyle(SOLID_FILL,0); /*设置填充模式和颜色,0表示黑色*/bar(50,55,455,315);/*bar是表示填充的范围的函数*/}}elseif([0]<60){[0]=320;/*如果蛇头越过上边界,则从下边界进入*/[0]=[0];/*横坐标不变*/for(i=;i>0;i--){[i]=[i-1];[i]=[i-1]; /*蛇的其他节数向前推进*/}{setfillstyle(SOLID_FILL,0); /*设置填充模式和颜色,0表示黑色*/bar(50,55,455,315);/*bar是表示填充的范围的函数*/}}elseif([0]>320){[0]=60;/*如果蛇头越过下边界,则从上边界进入*/[0]=[0];/*横坐标不变*/for(i=;i>0;i--){[i]=[i-1];[i]=[i-1]; /*蛇的其他节数向前推进*/}{setfillstyle(SOLID_FILL,0); /*设置填充模式和颜色,0表示黑色*/bar(50,55,455,315);/*bar是表示填充的范围的函数*/}}if()/*如果蛇死就跳出内循环,重新开始*/break;if([0]==[0]==)/*吃到食物以后*/{setcolor(0);/*把画面上的食物东西去掉*/rectangle(); /*用当前线型和颜色画一矩形*/[]=-20;[]=-20;/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/;/*蛇的身体长一节*/;/*画面上需要出现新的食物*/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);/*bar是表示填充的范围的函数*/}PrScore();/*输出新得分*/ } setcolor(4);/*画出蛇*/ for(i=0;i<;i++) rectangle([i],[i],[i]+10, [i]-10); delay(gamespeed); /*控制游戏速度*/setcolor(0);rectangle([],[], []+10,[]-10); } /*endwhile(!kbhit)*/ /*用黑色去除蛇的的最后一节*/ if()/*如果蛇死就跳出循环*/ break; key=bioskey(0);/*接收按键*/ if(key==ESC)/*按ESC键退出*/ break; else if(key==UP&&!=4) /*判断是否往相反的方向移动*/ ; else if(key==RIGHT&&!=2) ; else if(key==LEFT&&!=1) ; else if(key==DOWN&&!=3) ; }/*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(); }
代码示例如下:
使用了4个自定义函数来实现
#include <>
#include <>
#include <>
#include <>
#define High 20 // 游戏画面尺寸
#define Width 30
// 全局变量
int moveDirection; // 小蛇移动位置,上下左右分别用1,2,3,4表示
int food_x,food_y; // 食物的位置
int canvas[High][Width] = {0}; // 二维数组存储游戏画布中对应的元素
// 0为空格0,-1为边框#,-2为食物F,1为蛇头@,大于1的正数为蛇身*
void gotoxy(int x,int y) //光标移动到(x,y)位置
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
= x;
= y;
SetConsoleCursorPosition(handle,pos);
}
// 移动小蛇
// 第一步扫描数组canvas所有元素,找到正数元素都+1
// 找到最大元素(即蛇尾巴),把其变为0
// 找到=2的元素(即蛇头),再根据输出的上下左右方向,把对应的另一个像素值设为1(新蛇头)
void moveSnakeByDirection()
{
int i,j;
for (i=1;i
for (j=1;j
if (canvas[i][j]>0)
canvas[i][j]++;
int oldTail_i,oldTail_j,oldHead_i,oldHead_j;
int max = 0;
for (i=1;i
for (j=1;j
if (canvas[i][j]>0)
{
if (max