搜档网
当前位置:搜档网 › 纯C语言写的一个小型游戏源代码完整版

纯C语言写的一个小型游戏源代码完整版

纯C语言写的一个小型游戏源代码完整版
纯C语言写的一个小型游戏源代码完整版

纯C语言写的一个小型

游戏源代码

HUA system office room 【HUA16H-TTMS2A-HUAS8Q8-HUAH1688】

/* A simple game*/

/*CopyRight: Guanlin*/ #include

#include

#include

#include

#include

#include

?

struct object_fix

{

char name[20];

char id[5];

char desc[500];

char action[30];

char im[5];

};

struct object_move {

char name[20]; char id[5];

char desc[500];

int loc;

int pwr;

int strg;

char im[5];

};

struct rover

{

char name[20]; char id[5];

char desc[500];

int strg;

int location[2];

char im[5];

};

struct map /* this is the map structure*/

{

char data[20];

char add_data[20];

int amount;

int x; /* this were the successor keeps it's x & y values*/

int y;

};

struct location /*this structure is for the successor lister*/ {

float height;

};

void stats_update(int selected, struct rover *p_rover)

{

switch (selected)

{

case 1:

if(p_rover->pwr < 7)

printf("\n\nYou do not have enough power to perform this action!\n\n"); else

{

(p_rover->pwr) -= 7;

printf("You have destroyed the object!\n\n");

}

break;

case 2:

if(p_rover->pwr < 3)

printf("\n\nYou do not have enough power to perform this action!\n\n");

else if(p_rover->strg > 90)

printf("\n\nYou do not have enough storage space for this object!\n\n");

else

{

(p_rover->pwr) -= 3;

(p_rover->strg) += 10;

printf("You have collected a sample of the object!\n\n");

}

break;

case 3:

p_rover->pwr -= 10; /*Distance around object- value gained from mapper module.

1 square = -1 power*/

printf("You have avoided the object!\n\n");

break;

case 4:

p_rover->pwr -= 2;

printf("You have driven through the obstacle!\n\n"); break;

case 5:

if(p_rover->pwr == 100)

printf("\n\nYou do not need to charge up!\n\n");

else

{

p_rover->pwr = 100;

printf("You have charged up your rover!\n\n");

}

break;

default:

printf("\n\n*****ERROR*****\nInvalid Selection\n\n"); break;

}

}

void action(char object, struct rover *p_rover)

{

int selection;

switch(object)

{

case 1:

printf("\nYou have encountered: A Sandy Rock\n\n");

printf("This object can be:\n1.\tDestroyed\n2.\tCollected\nPlease choose action 1 or 2:\t");

scanf("%d", &selection);

stats_update(selection, p_rover);

break;

case 2:

printf("\nYou have encountered: A Solid Rock\n\n");

1 or 2:\t");

scanf("%d", &selection);

if (selection == 1)

selection = 3;

stats_update(selection, p_rover);

break;

case 3:

printf("\nYou have encountered: A Mountain\n\n");

printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t"); scanf("%d", &selection);

selection = 3;

stats_update(selection, p_rover);

break;

case 4:

printf("\nYou have encountered: Dust\n\n");

action 1 or 2:\t");

scanf("%d", &selection);

if (selection == 1)

selection = 4;

stats_update(selection, p_rover);

break;

case 5:

printf("\nYou have encountered: A Sheer Valley\n\n");

printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t"); scanf("%d", &selection);

selection = 3;

stats_update(selection, p_rover);

break;

case 6:

printf("\nYou have encountered: A Gentle Valley\n\n");

action 1 or 2:\t");

scanf("%d", &selection);

if (selection == 1)

selection = 4;

if (selection == 2)

selection = 3;

stats_update(selection, p_rover);

break;

case 7:

printf("\nYou have encountered: A 'Martian' Tree\n\n");

printf("This object can be:\n1.\tDestroyed\n2.\tCollected\n3.\tAvoided\nPlease choose action 1, 2 or 3:\t");

scanf("%d", &selection);

stats_update(selection, p_rover);

break;

case 8:

printf("\nYou have encountered: Shallow Water\n\n");

printf("This object can be:\n1.\tDriven

through\n2.\tCollected\n3.\tAvoided\nPlease choose action 1, 2 or 3:\t"); scanf("%d", &selection);

if (selection == 1)

selection = 4;

stats_update(selection, p_rover);

break;

case 9:

printf("\nYou have encountered: Deep Water\n\n");

printf("This object can be:\n1.\tAvoided\n2.\tCollected\nPlease choose action 1 or 2:\t");

scanf("%d", &selection);

if (selection == 1)

selection = 3;

stats_update(selection, p_rover);

break;

case 10:

printf("\nYou have encountered: An Aggressive Alien\n\n");

printf("This object can be:\n1.\tDestroyed\nPlease enter 1:\t"); scanf("%d", &selection);

selection = 1;

stats_update(selection, p_rover);

break;

case 11:

printf("\nYou have encountered: A Non-Aggressive Alien\n\n"); printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t"); scanf("%d", &selection);

selection = 3;

stats_update(selection, p_rover);

break;

case 12:

printf("\nYou have encountered: Another Rover\n\n");

printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");

scanf("%d", &selection);

selection = 3;

stats_update(selection, p_rover);

break;

case 13:

printf("\nYou have encountered: A Power Station\n\n");

printf("You can:\n1.\tCharge up\n2.\tAvoid\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);

if (selection == 1)

selection = 5;

if (selection == 2)

selection = 3;

stats_update(selection, p_rover);

break;

default:

printf("\n\n*****ERROR*****\n\n");

break;

}

}

void show_map(struct map *number, struct map *number_2, struct object_fix

*rsny,

struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst, struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre, struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr, struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*the show map function calling number and number_2 from the map structure to see if moveable objects are needed*/

{

struct map f_map[8][8]; /*8 by 8 map*/

int i,j, rx, ry, object; /*this is your x and y value in your map (f_map)*/ system("cls"); /* this is your x and y value in your map (f_map)*/

//srand(time(NULL)); /*calling the time from include to gather random variables*/

for(i=0;i<8;i++) /*for loop to copy all your fixed object lists into f_map so they can be displayed*/

{

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

strcpy(f_map[i][j].data,"");

}

if (number->amount>0) /*this is looking at the add function to see weather or not there are aliens in f_map*/

{

for(i=0;iamount;i++) /*allocating the number of aliens in f_map*/ strcpy(f_map[rand()%8][rand()%8].data, anon->im); /*randomizing their

position*/

}

if(number_2->amount>0) /*repeat of above just for rovers instead*/

{

for(i=0;iamount;i++)

strcpy(f_map[rand()%8][rand()%8].data, rvr->im); }

rx= p_rover->location[0];

ry= p_rover->location[1];

strcpy(f_map[1][0].data, wdp->im);

strcpy(f_map[4][0].data, mnt->im);

strcpy(f_map[5][0].data, mnt->im);

strcpy(f_map[3][1].data, dst->im);

strcpy(f_map[4][1].data, dst->im);

strcpy(f_map[3][2].data, dst->im);

strcpy(f_map[4][2].data, dst->im);

strcpy(f_map[0][3].data, mnt->im);

strcpy(f_map[1][3].data, mnt->im);

strcpy(f_map[4][3].data, dst->im); strcpy(f_map[5][3].data, vgnt->im); strcpy(f_map[3][4].data, vshr->im); strcpy(f_map[4][4].data, dst->im); strcpy(f_map[5][4].data, vgnt->im); strcpy(f_map[2][5].data, wshl->im); strcpy(f_map[3][5].data, wshl->im); strcpy(f_map[4][5].data, wshl->im); strcpy(f_map[1][6].data, pstn->im); strcpy(f_map[2][6].data, wdp->im); strcpy(f_map[3][6].data, wdp->im); strcpy(f_map[4][6].data, wshl->im); strcpy(f_map[7][6].data, mnt->im); strcpy(f_map[0][7].data, mnt->im); strcpy(f_map[1][7].data, wdp->im);

strcpy(f_map[3][7].data, wshl->im);

strcpy(f_map[6][7].data, mnt->im);

strcpy(f_map[rx][ry].data, p_rover->im);

if((rx == 1 && ry == 0) || (rx == 2 && ry == 6) ||(rx == 3 && ry == 6) ||(rx == 1 && ry == 7))

{

object = 9;

action(object, p_rover);

}

else if((rx == 4 && ry == 0) || (rx == 5 && ry == 0) || (rx == 0 && ry == 3) || (rx == 1 && ry == 3) || (rx == 7 && ry == 6) || (rx == 0 && ry == 7) || (rx == 6 && ry == 7))

{

object = 3;

action(object, p_rover);

else if((rx == 3 && ry== 1) || (rx == 4 && ry == 1) || (rx == 3 && ry== 2) || (rx == 4 && ry == 2) || (rx == 4 && ry == 3) || (rx == 4 && ry == 4))

{

object = 4;

action(object, p_rover);

}

else if((rx == 3 && ry == 3) || (rx == 3 && ry == 4))

{

object = 5;

action(object, p_rover);

}

else if((rx == 5 && ry == 3) || (rx == 5 && ry == 4))

{

object = 6;

action(object, p_rover);

纯C语言写的一个小型游戏-源代码

纯C语言写的一个小型游戏-源代码

/* A simple game*/ /*CopyRight: Guanlin*/ #include #include #include #include #include #include struct object_fix { char name[20]; char id[5]; char desc[500]; char action[30]; char im[5]; }; struct object_move { char name[20]; char id[5]; char desc[500]; int loc; int pwr; int strg; char im[5]; }; struct rover { char name[20]; char id[5]; char desc[500]; int pwr; int strg; int location[2]; char im[5]; }; struct map /* this is the map structure*/ { char data[20]; char add_data[20]; int amount; int x; /* this were the successor keeps it's x & y values*/ int y; }; struct location /*this structure is for the successor lister*/ { float height; char obj;

c语言小游戏编程

程序设计实践 大作业 学号:20100302XXXX 姓名:XXX 班级:信息10-3班 实验题目:射击类飞机游戏 页脚内容1

成绩: 一.实验题目: 射击类飞机游戏 二.实验目的: 通过c语言编写一个射击类的打飞机小游戏,可以通过键盘来进行游戏,操作方法是“a”“d”“w”或者“←”“↑”“→”来控制,击中敌机可获得积分,被敌机撞中死亡一次,每次游戏有3次生还机会,游戏结束后可选择是否重新开始游戏…… 三.对游戏的改进: 这个游戏是我对一个小游戏进行的改造升级版,添加了颜色函数、终止函数,选择类函数,使游戏实现了可以终止,不再是分数、死亡数一直增加但是没有结束的情况;增加了颜色函数,使得游戏看起来更加的舒适;增加了终止函数,使游戏在死亡三次后自动结束游戏,并且可以选择是否重新开始游戏;另外增添了设置函数,使得可以对游戏进行设置,改变游戏大小,调整飞机运行速度等等,是游戏更加的人性化…… 四.实验内容 页脚内容2

编写出c语言代码,运行程序,并调试程序,最终实现游戏的功能。本程序主要包含游戏控制函数、设置是否继续游戏函数、输出函数、子弹移动函数、敌机移动函数、设置函数、菜单函数等7个主要函数,包含了不同的功能,对原来的程序作出了很大的改进,用到的主要语句有getche语句、for语句、while语句、printf语句、switch语句等等,添加了颜色函数,实现了诸多功能。可以在页面上显示制作人的主要信息等等…… 【流程图见打印版】 五.源程序: #include 页脚内容3

#include #include #include #define N 35 #define up 72 #define left 75 #define right 77 void run();//游戏控制函数 void yn();//设置是否继续游戏函数 void print(int [][N]);//输出函数 void movebul(int [][N]);//子弹移动函数 void movepla(int [][N]);//敌机移动函数 void setting(void);//设置函数 void menu(void);//菜单函数 int scr[22][N]={0},pl=9,width=24,speed=3,density=30,score=0,death=0;//全局变量:界面、我机初始位、界面宽度、敌机速度、敌机密度、得分、死亡 页脚内容4

C语言游戏源代码最新版

C语言游戏源代码 1、简单的开机密码程序 #include "conio.h" #include "string.h" #include "stdio.h" void error() {window(12,10,68,10); textbackground(15); textcolor(132); clrscr(); cprintf("file or system error! you can't enter the system!!!"); while(1); /*若有错误不能通过程序*/ } void look() {FILE *fauto,*fbak; char *pass="c:\\windows\\password.exe"; /*本程序的位置*/ char a[25],ch; char *au="autoexec.bat",*bname="hecfback.^^^"; /*bname 是autoexec.bat 的备份*/ setdisk(2); /*set currently disk c:*/ chdir("\\"); /*set currently directory \*/ fauto=fopen(au,"r+"); if (fauto==NULL) {fauto=fopen(au,"w+"); if (fauto==NULL) error();} fread(a,23,1,fauto); /*读取autoexec.bat前23各字符*/ a[23]='\0'; if (strcmp(a,pass)==0) /*若读取的和pass指针一样就关闭文件,不然就添加*/ fclose(fauto); else {fbak=fopen(bname,"w+"); if (fbak==NULL) error(); fwrite(pass,23,1,fbak); fputc('\n',fbak); rewind(fauto); while(!feof(fauto)) {ch=fgetc(fauto); fputc(ch,fbak);} rewind(fauto); rewind(fbak); while(!feof(fbak))

C语言编程游戏代码

#include #include #include #include #include #define L 1 #define LX 15 #define L Y 4 static struct BLOCK { int x0,y0,x1,y1,x2,y2,x3,y3; int color,next; intb[]={{0,1,1,1,2,1,3,1,4,1},{1,0,1,3,1,2,1,1,4,0},{1,1,2,2,1,2,2,1,1,2},{0,1,1,1,1,0,2,0,2,4}, {0,0,0,1,1,2,1,1,2,3},{0,0,1,0,1,1,2,1,3,8},{1,0,1,1,2,2,2,1,2,5},{0,2,1,2,1,1,2,1,2,6},{0,1,0,2,1,1,1 ,0,3,9},{0,1,1,1,1,2,2,2,3,10},{1,1,1,2,2,1,2,0,3,7},{ 1,0,1,1,1,2,2,2,7,12},{0,1,1,1,2,1,2,0,7,13},{0 ,0,1,2,1,1,1,0,7,14},{0,1,0,2,1,1,2,1,7,11},{0,2,1,2,1,1,1,0,5,16},{0,1,1,1,2,2,2,1,5,17},{1,0,1,1,1, 2,2,0,5,18},{0,0,0,1,1,11,2,1,5,15},{0,1,1,1,1,0,2,1,6,2,0},{0,1,1,2,1,1,1,0,6,21},{0,1,1,2,1,1,2,1,6 ,22},{1,0,1,1,1,2,2,1,6,19}}; static int d[10]={33000,3000,1600,1200,900,800,600,400,300,200}; int Llevel,Lcurrent,Lnext,Lable,lx,ly,Lsum; unsigned Lpoint; int La[19][10],FLAG,sum; unsigned ldelay; void scrint(),datainit(),dispb(),eraseeb(); void throw(),judge(),delayp(),move(0,note(0,show(); int Ldrop(),Ljudge(),nextb(),routejudge(); } main() { char c; datainit(); Label=nextb(); Label=Ldrop(); while(1){ delayp(); if(Label!=0) { Ljudge(); Lable=nextb(); } ldelay--; if(ldelay==0)

c语言课程设计源代码

c语言课程设计源代码标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N]

学校运动会管理系统问题描述: (1) 初始化输入:N-参赛院系总数,M-男子竞赛项目数,W-女子竞赛项目数; (2) 各项目名次取法有如下几种: 取前5名:第1名得分 7,第2名得分 5,第3名得分3,第4名得分2,第5名得分 1; (3) 由程序提醒用户填写比赛结果,输入各项目获奖运动员的信息。 (4) 所有信息记录完毕后,用户可以查询各个院系或个人的比赛成绩,生成团体总分报表,查看参赛院系信息、获奖运动员、比赛项目信息等。 程序代码: #include<> #include<> #define N 3 #define M 3 #define W 3 char* n_number[3]={"1","院系2","院系3"}; char* m_number[3]={"1","男项2","男项3"};

char* w_number[3]={"女项1","女项2","女项3"}; int size=2; struct student { char num[10]; char name[20]; char xiangmu[20]; int score; char ximing[20]; }stu[100],temp; void input() um,&stu[i].name,&stu[i].xiangmu,&stu[i].score,&stu[i].ximing); iming,n_number[0])==0) iming); iming,n_number[h])==0) for(int s=0;s

C编写的小游戏

C编写的小游戏 集团企业公司编码:(LL3698-KKI1269-TM2483-LUI12689-ITT289-

#i n c l u d e usingnamespacestd; constcharMOUSE='*'; constcharWAY=''; constcharWALL='@'; constcharPASS='.'; constcharIMPASS='X'; classGame{ public: Game(size_tuWidth,size_tuHeight):m_uWidth(uWidth),m_uHeigh t(uHeight),m_pcMaze(newchar[uWidth*uHeight]),m_mouse(0,1){ srand(time(NULL)); char(*pcMaze)[m_uWidth]=reinterpret_cast(m_pcMaze); for(size_ti=0;im_uWidth-5)) pcMaze[i][j]=WAY;

elseif(i==0||i==m_uHeight- 1||j==0||j==m_uWidth-1) pcMaze[i][j]=WALL; else pcMaze[i][j]=rand()%4WAY:WALL; } ~Game(void){ if(m_pcMaze){ delete[]m_pcMaze; m_pcMaze=NULL; } } voidRun(void){ for(Show();!Quit()&&Step();); } private: classMouse{ public: Mouse(size_tx,size_ty):m_x(x),m_y(y){} size_tGetX(void){returnm_x;} size_tGetY(void){returnm_y;} voidStepRight(void){

一个C语言写的简单贪吃蛇源代码

#include #include #include #include #include #include int grade=5,point=0,life=3; void set(),menu(),move_head(),move_body(),move(),init_insect(),left(),upon(),right(),down(),init_grap h(),food_f(),ahead(),crate(); struct bug { int x; int y; struct bug *last; struct bug *next; }; struct fd { int x; int y; int judge; }food={0,0,0}; struct bug *head_f=NULL,*head_l,*p1=NULL,*p2=NULL; void main() { char ch; initgraph(800,600); set(); init_insect(); while(1) { food_f(); Sleep(grade*10); setcolor(BLACK); circle(head_l->x,head_l->y,2); setcolor(WHITE); move_body(); if(kbhit()) { ch=getch(); if(ch==27) { ahead();

set(); } else if(ch==-32) { switch(getch()) { case 72:upon();break; case 80:down();break; case 75:left();break; case 77:right();break; } } else ahead(); } else { ahead(); } if(head_f->x==food.x&&head_f->y==food.y) { Sleep(100); crate(); food.judge=0; point=point+(6-grade)*10; if(food.x<30||food.y<30||food.x>570||food.y>570) life++; menu(); } if(head_f->x<5||head_f->x>595||head_f->y<5||head_f->y>595) { Sleep(1000); life--; food.judge=0; init_graph(); init_insect(); menu(); } for(p1=head_f->next;p1!=NULL;p1=p1->next) { if(head_f->x==p1->x&&head_f->y==p1->y) { Sleep(1000); life--; food.judge=0;

C语言小游戏程序设计

程序设计实验 大作业 学院: 班级: 学号: 指导老师: 姓名: 实验项目名称:猜数字游戏成绩:

一、实验要求 根据所学知识编写一个小游戏--猜数字游戏 二、实验目的 为了加深对编程课程的基本知识的理解和掌握,并且掌握编程和程序调试的技巧通过程序的设计训练和提高学生的基本技能,掌握字符串的表示方法和字符串函数的功能、编程软件操作的基本知识、键盘上特殊键的获取以及图形方式下光标的显示,提高编程兴趣与编程水平,学会如何正确的书写程序设计说明文档,提高解决实际问题的能力,巩固语法规则的理解和掌握,学会通过源程序写出流程图,提高自学以及查阅资料的能力。 三、功能模块分析 1.系统能够随机产生一个1到1000的数字 2.比较输入数字与随机产生数字的大小 3.选择是否继续游戏 四、修改处 1.将输出内容由英文变为汉字 2.改变背景及输出字体的颜色 3将随机产生的数值范围由1-100变为1-1000 四、设计思路 # include # include # include main() { void textbackground(int color); system("color fc"); int a,b; char c; srand(time(NULL)); a=1+(rand()%1000); printf("这有一个数字从1到1000.\n你能猜出它吗?\n输入你猜的数字.\n"); scanf("%d",&b); while(b!=-1) { if(b==a) { printf("恭喜你猜对了!\n你喜欢再玩一遍吗?(y or n)?");

c语言游戏讲解

1: C语言游戏设计 1.1:课程设计目标 C语言编写一款打飞机游戏,掌握函数的使用和编程的整体思路。 1.2:整体设计思路 总体设想:运行游戏时显示游戏的界面,允许用户选择个性化设置,A、D、W分别控制飞机的左右移动和发射子弹,不同的敌机飞行和攻击,并不时伴有奖励。游行运行时播放音效,同时记录飞机的生命和得分,达到一定的分数进入下一关。 需要构建的函数:位图调用模块、界面输出函数、主菜单函数、设置函数、速度选择函数、游戏控制函数、敌机移动函数、子弹移动函数、boss 函数、计时函数。 1.3: 需调用的头文件:include //常规库头文件 include //控制台输入输出流头文件 include //系统函数头文件 include //时间函数头文件 include //windows函数库 include //导入声音头文件 pragma comment(lib,"winmm.lib ")//导入声音头文件库 1.4: 游戏过程模拟:

1.5:显示效果如下图所示:

初始设置界面:游戏界面 2 算法实现 2.1需要了解的知识点: Main函数和menu函数编写比较顺利,在bmp函数中遇到如何显示窗口和调用图片的问题,看了一些例子和网上的资料,逐渐掌握了一下知识点: ○1设备上下文:设备,显示器,打印机,数码相机,扫描仪这些类似的设备, 上下文,就是上面设备的相关信息,比如屏幕分辨率等 ○2 HANDLE 通用句柄,实际上是一个指向指针的指针,在Windows操作系统中, 内存操作器经常移动对象,来满足各种程序的内存需要,为了解决寻找对象问题,内存管理器开辟出一块专门的内存储存空间,把移动后的地址存储在该空间,这样就可以通过该地址间接寻找到对象。 ○3 HDC设备描述句柄,实现对窗口操作区域的GDI(图形设备接口, 负责系统 与绘图程序之间的信息交换,处理所有Windows程序的图形输出)操作,如画线、写文本、绘画制图等。 ○4 BITMAP 用于处理有像素数据定义的图像的对象。

C语言游戏源代码

语言游戏源代码1、简单地开机密码程序 "" "" "" () {()()()()(" ! ' !!!"); (); *若有错误不能通过程序* } () { *,*; *":\\\\"; *本程序地位置* []; *"",*".^^^"; *是地备份*(); * :*("\\"); * \*(,""); () {(,""); () ();}(); *读取前各字符* []'\'; (()) *若读取地和指针一样就关闭文件,不然就添加*(); {(,""); () ()()('\'); (); (()) {()();} (); (); (()){()();}()(); (); * * } } () { *""; [] ; () {()()()(); ; ()()()()(":"); () {[](); (>) {(); ;} *若字符多于个字符就结束本次输入* ([]) ;

([]> []<) *若字符是数字或字母才算数* {('*'); ;} ([]) *删除键* (>) {("\ \"); []'\'; ;} } []'\'; (()) ; {(); ()()()()(" !")();} } } () {(); (); } 2、彩色贪吃蛇 <> <> ; * 游戏速度*, , ; * 游戏分数* [] { , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

C编写的小游戏

C编写的小游戏集团档案编码:[YTTR-YTPT28-YTNTL98-UYTYNN08]

#i n c l u d e usingnamespacestd; constcharMOUSE='*'; constcharWAY=''; constcharWALL='@'; constcharPASS='.'; constcharIMPASS='X'; classGame{ public: Game(size_tuWidth,size_tuHeight):m_uWidth(uWidth),m_uHeight(uHe ight),m_pcMaze(newchar[uWidth*uHeight]),m_mouse(0,1){ srand(time(NULL)); char(*pcMaze)[m_uWidth]=reinterpret_cast(m_p cMaze); for(size_ti=0;im_uWidth-5)) pcMaze[i][j]=WAY; elseif(i==0||i==m_uHeight- 1||j==0||j==m_uWidth-1) pcMaze[i][j]=WALL; else pcMaze[i][j]=rand()%4?WAY:WALL; } ~Game(void){ if(m_pcMaze){ delete[]m_pcMaze; m_pcMaze=NULL; } } voidRun(void){ for(Show();!Quit()&&Step();); } private: classMouse{ public: Mouse(size_tx,size_ty):m_x(x),m_y(y){} size_tGetX(void){returnm_x;} size_tGetY(void){returnm_y;} voidStepRight(void){

纯C语言写的一个小型游戏-源代码

/* A simple game*/ /*CopyRight: Guanlin*/ #include #include #include #include #include #include struct object_fix { char name[20]; char id[5]; char desc[500]; char action[30]; char im[5]; }; struct object_move { char name[20]; char id[5]; char desc[500]; int loc; int pwr; int strg; char im[5]; }; struct rover { char name[20]; char id[5]; char desc[500]; int pwr; int strg; int location[2]; char im[5]; }; struct map /* this is the map structure*/ { char data[20]; char add_data[20]; int amount; int x; /* this were the successor keeps it's x & y values*/ int y; }; struct location /*this structure is for the successor lister*/ { float height; char obj;

C语言实现生命游戏

本世纪70年代,人们曾疯魔一种被称作“生命游戏”的小游戏,这种游戏相当简单。假设有一个像棋盘一样的方格网,每个方格中放置一个生命细胞,生命细胞只有两种状态:“生”或“死”。游戏规则如下: 1. 如果一个细胞周围有3个细胞为生(一个细胞周围共有8个细胞),则该细胞为生,即该细胞若原先为死,则转为生,若原先为生,则保持不变; 2. 如果一个细胞周围有2个细胞为生,则该细胞的生死状态保持不变; 3. 在其它情况下,该细胞为死,即该细胞若原先为生,则转为死,若原先为死,则保持不变。 依此规则进行迭代变化,使细胞生生死死,会得到一些有趣的结果。该游戏之所以被称为“生命游戏”,是因为其简单的游戏规则,反映了自然界中的生存规律:如果一个生命,其周围的同类生命太少的话,会因为得不到帮助而死亡;如果太多,则会因为得不到足够的资源而死亡。 用计算机模拟这个“生命游戏”也相当简单,可以用一个M×N像素的图像来代表M×N个细胞,其中每一个像素,代表一个细胞,像素为黑色表示细胞为生,像素为白色代表细胞为死。 设定图像中每个像素的初始状态后依据上述的游戏规则演绎生命的变化,由于初始状态和迭代次数不同,将会得到令人叹服的优美图案。 下面给出的小程序是用TC2.0编写。演示100×100个生命细胞初始状态全为生时的变代情况,变化时边缘细胞不参与变化。随着迭代次数的不同,在屏幕显示的图案精彩纷呈,像万花筒般引人入胜。 #include main(){ int orgData[100][100],resData[100][100];/*分别记录每次迭代 的初始和结果状态*/ int nCount,nRows,nCols,i,j,times; /*times记录迭代次数*/ int GraphDriver=DETECT,GraphMode; for (i=0;i<100;i++) /*初始化数据,令每一个细胞为生*/ for (j=0;j<100;j++) orgData[i][j]=1; initgraph(&GraphDriver,&GraphMode,′′′′); /*初始化屏幕 显示*/ setcolor(WHITE); rectangle(270,190,370,290); /*作显示边框*/ for (times=1;times<200;times++){ for (nRows=1;nRows<99;nRows++) { for (nCols=1;nCols<99;nCols++){ /*计算每一个细胞周围的活的细胞数*/

使用C语言编写简单小游戏

纯真童趣的《泡泡堂》,还有武林情仇,笑傲江湖的《剑侠情缘on line》.它是e 时代常谈的话题,是交互式娱乐的主力军,是一种高层次的综合艺术,更是一个民族的文化,世界观的全新传播方式 .作为游戏玩家的我们,是不是想设计一个属于自己的游戏呢? 爱玩是人的天性,而C语言是我们计算机专业都要学习的一门基础学科.一般来说,是比较枯燥的.那么,我们能不能通过编一些小游戏来提高它的趣味性呢?这样学习程序设计,就不会是一件艰苦 ,枯燥的事,它变得象电脑游戏一样充满好奇,富有乐趣. 1,总是从Hello,world开始学习编程的第一个程序,一般就是打印一个亲切的词语——"Hell o,world!".让我们来看看这个最简单的C程序: #incolude <> /*把输入输出函数的头文件包含进来*/ int main() { printf("Hello, world!");/*在屏幕上输出字符串"Hello,world!"*/ return 0;/*退出main函数,并返回0*/ } 下面我们发现几个值得改进的地方,1,程序的运行结果一闪而过 .2,每执行这个程序一次都能看见上次运行留下的字符.3,我们还希望屏幕输出一个笑脸来欢迎我们. 让我们来改进一下这个程序吧! 1,在return语句的前面加一句:getch ();,表示按任意键结束.2,在printf语句前用clrscr函数清屏,要使用这个函数和getch函数,需要在程序开头再包含头文件码也有许多非常好玩的字符,比如ASCII码值为2的就是一个笑脸,我们可以用printf("%c", 2)来输出一个笑脸. 现在我们把Hello,world程序改成一个更好看的Hello,world了.下面让我们开始做游戏吧! 2,心动的开始,一个运动中的笑脸大家小时侯喜欢看动画片吗?哈哈,我猜你们都喜欢吧!下面就让我们来做一个小动画吧.在屏幕上显示一个运动的小笑脸,而且当它到达屏幕的边缘时会自动弹回来.先在程序定义一个在屏幕中运动的点的结构: struct move_point { int x, y;/*该点的位置,包括x坐标和y坐标*/ int xv, yv;/*该点在x轴,y轴的速度*/ }; 运动的原理是,先擦去物体先前的轨迹,让物体按其速度移动一段距离,再画出该物体.让我们看到以下代码: gotoxy, ;/*把光标移到指定的坐标*/ printf(" ");/*输出一个空格,把先前的字符擦去*/ 然后我们让物体按其速度运动: += ;/*水平方向按x轴的速度运动*/ += ;/*垂直方向按y轴的速度运动*/ 运动后还要判断物体是否出界,如果出了界,就令物体反弹,即让它下一刻的速度等于现在的速度的相反数.最后打印出这个笑脸: gotoxy, ; printf("%c\b", 2); /*输出ASCII码值为2的"笑脸"字符*/ 怎么样?是不是很有趣呢?不过这个笑脸一直是自己运动,能不能让我们来控制它运动呢?答案是肯定的,让我们继续往下学吧! 3,交互的实现——让我们来控制笑脸运动 这个程序的主要功能是接受按键,如果接收的是方向键,就让笑脸顺着方向移动,如果接收的是ESC键就退出程序,其他按键则忽略处理.接受按键我们用以下两条语句: while (bioskey(1) == 0);/*等待按键*/ key = bioskey(0);/*把接收的按键的键盘码赋给变量key*/ 然后用switch语句来判断按键以及执行相关操作,如下: switch (key) /*对变量key的值进行判断*/ { case UP: /*如果按的是向上键*/ … break; /*让物体向上运动,并退出switch*/

纸牌记忆小游戏C语言源代码

#include #include #include intoutputacard(inta,int b) //输出一张扑克 { if(b==11) { printf("[%c",a); //J printf("%c]",b+63); } else if(b==12) { printf("[%c",a); //Q printf("%c]",b+69); } else if(b==13) { printf("[%c",a); //K printf("%c]",b+62); } else if(b==1) { printf("[%c",a); //A printf("%c]",b+64); } else if(b==88) printf("[%c%c]",a,b); //XX else { printf("[%c",a); //随机输出8张扑克 printf("%d]",b); } } int main() { int puke[8][2]; inti,j,k; srand((unsigned int)time(NULL)); printf("记住下面牌的顺序\n准备好了按<回车>,我会提问你的^-^\n"); for(i=0; i<8; i++) for(j=0; j<2; j++) { if(j==0) puke[i][j]=3+rand()%3; /*红心是003 方块004 梅花005 黑桃

006*/ else puke[i][j]=1+rand()%12; //A……K } for(k=0; k<8; k++) outputacard(puke[k][0],puke[k][1]); //随机输出8张扑克 printf("\n"); int puke2[8][2]; int puke0[2]; intt,rh; for(t=0; t<8; t++) { puke2[t][0]=puke[t][0]; puke2[t][1]=puke[t][1]; } for(t=0; t<8; t++) /*把上面的8张扑克打乱顺序存入另一个数组*/ { rh=rand()%7; if(rh!=t) { puke0[0]=puke2[t][0]; puke0[1]=puke2[t][1]; puke2[t][0]=puke2[rh][0]; puke2[t][1]=puke2[rh][1]; puke2[rh][0]=puke0[0]; puke2[rh][1]=puke0[1]; } } for(k=0; k<8; k++) outputacard(puke2[k][0],puke2[k][1]); /*打乱顺序后重新输出8张扑克*/ printf("\n"); int puke3[8][2],puke4[8][2]; for(i=0; i<8; i++) /*为把上面代表两组扑克的数组puke,puke2复制到另外*/ for(j=0; j<2; j++) /*两个数组puke3、puke4中,以方便后面输出*/ for(j=0; j<2; j++) { puke3[i][j]=88; puke4[i][j]=88; } system("pause"); system("CLS");

c语言编写的小游戏代码

用vc6.0新建一个Win32 Application工程,把附件代码拷贝进去即可。上下左右键控制蛇的方向,空格键用于启动或者停止游戏。 上下左右空格键 #include #include #include #define C_W 516 #define C_H 548 //#define C_W 1024 //#define C_H 1024 #define GO_RIGHT 0x01 #define GO_DOWN 0x02 #define GO_LEFT 0x03 #define GO_UP 0x04 #define SNAKE_NUMBER 30 typedef struct node_struct { unsigned char direction; unsigned char cnt; }s_node,*s_node_handle; s_node s_count[SNAKE_NUMBER ]; typedef struct SNAKE { unsigned char Head_X; unsigned char Head_Y; unsigned char Tail_X; unsigned char Tail_Y; unsigned char h_index; unsigned char t_index;

unsigned char food_state; unsigned char score; unsigned char snake_state; } Snake_Data,*Snake_Data_handle; Snake_Data snk_1; #define MAP_X 64 #define MAP_Y 64 unsigned char game_map[MAP_Y][MAP_X]; LRESULT CALLBACK Win_tetris_Proc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state ) { snk_1.Head_X = 0x01;//head x snk_1.Head_Y = 0x00;//head y snk_1.Tail_X = 0x00;//tail x snk_1.Tail_Y = 0x00;//tail y snk_1.h_index=0; snk_1.t_index=0; snk_1.food_state=0; snk_1.score=0; snk_1.snake_state = 1; s_count[snk_1.h_index].cnt=2; s_count[snk_1.h_index].direction=GO_RIGHT; s_count[snk_1.t_index].cnt=2; s_count[snk_1.t_index].direction=GO_RIGHT; WNDCLASS wndcls; wndcls.cbClsExtra=0;

C语言程序设计(医院信息管理系统)附源代码

C语言程序设计(医院信息管理系统)附源代码

————————————————————————————————作者:————————————————————————————————日期:

专业设计报告 课程名称: C 语言程序设计课题名称:医院信息管理系统 专业班别:12本计算机科学与技术二班 姓名: 学号: 指导教师: 设计日期:2012-5-25

教师评语: 等级 优良中及格差项目 专业设计目的 设计基本要求 算法分析 源程序代码 源程序代码测试 设计总结 成绩评定: 指导教师签名: 日期:2012 年月日

课程设计题目医院信息管理程序 作者姓名: 同组成员: 摘要利用结构体存储每个病人的信息和每种药品的信息,并使用链表存储全部病人的信息;能完成对医院内所有病人信息的注册、查询、删除和修改等操作,同时又能对药房内库存的药品进行查询;可以将链表中的病人信息保存在文件中,并且可以对文件中的病人信息进行读取与显示 1.专业设计目的 1、掌握链表的操作,包括链表节点的创建、释放还有链表的遍历 2、掌握对二进制文件的创建、增添等基本操作。 3、熟悉C语言函数的使用方法,学会模块化处理问题以及多个源文件的处理方式 2.设计基本要求( 1、使用结构体来存储病人的信息,结构体中包括病的id号码、姓名、病历以及消费信息,并用链表将所有病人信息整合。 2、用文件来存储链表的信息以便下次再使用该程序时载入病人信息 3、能够实现病人信息的注册、病人信息的查询、病人消费统计、保存链表信息、载入链表信息、查询库存等几项功能。 4、要求用四个源文件main.c、link.c、find.c、save_load.c 5、系统完成后应实现类似下面所示界面

如何用c语言编写小游戏

如何用c语言编写小游戏 ----------------------------精品word文档值得下载值得拥有---------------------------------------------- 纯真童趣的《泡泡堂》,还有武林情仇, 笑傲江湖的《剑侠情缘on line》.它是e时代常谈的话题,是交互 式娱乐的主力军,是一种 高层次的综合艺术,更是一个民族的文 化,世界观的全新传播方式 .作为游戏玩家的我们,是不是想设计一 个属于自己的游戏呢? 爱玩是人的天性,而C语言是我们计算机 专业都要学习的一门基础 学科.一般来说,是比较枯燥的.那么,我 们能不能通过编一些小 游戏来提高它的趣味性呢?这样学习程 序设计,就不会是一件艰苦 ----------------------------精品word文档值得下载值得拥有---------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------- ----------------------------精品word文档值得下载值得拥有----------------------------------------------

,枯燥的事,它变得象电脑游戏一样充满 好奇,富有乐趣.这正是 我发贴的目的. 1, 总是从Hello,world开始 学习编程的第一个程序,一般就是打印 一个亲切的词语——"Hell o,world!".让我们来看看这个最简单的 C程序: #incolude /*把输入输出函 数的头文件包含进来*/ int main() { printf("Hello, ----------------------------精品word文档值得下载值得拥有---------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------- ----------------------------精品word文档值得下载值得拥有---------------------------------------------- world!");/*在屏幕上输出字符串"Hell o,world!"*/ return 0;/*退出main函数,并返回0*/ } 下面我们发现几个值得改进的地方,1,