纯C语言写的一个小型游戏 源代码
/* A sim ple gam e*/
/*CopyRight: Guanlin*/
#include
#include
#include
#include
#include
#include
struct object_fix
{
char nam e[20];
char id[5];
char desc[500];
char action[30];
char im[5];
};
struct object_m ove
{
char nam e[20];
char id[5];
char desc[500];
int loc;
int pwr;
int strg;
char im[5];
};
struct rover
{
char nam e[20];
char id[5];
char desc[500];
int pwr;
int strg;
int location[2];
char im[5];
};
struct m ap /* this is the m ap structure*/
{
char data[20];
char add_data[20];
int am ount;
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;
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 sam ple 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");
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 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");
printf("This object can be:\n1.\tDriven through\n2.\tCollected\nPlease choose 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");
printf("This object can be:\n1.\tDriven through\n2.\tAvoided\nPlease choose 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 m ap *number, struct m ap *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *m nt, struct object_fix *dst,
struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *m tre,
struct object_fix *wshl, struct object_fix *wdp, struct object_m ove *aagr,
struct object_m ove *anon, struct object_m ove *rvr, struct object_m ove *pstn, struct rover *p_rover) /*the show m ap function calling number and number_2 from the m ap structure to see if m oveable objects are needed*/
{
struct m ap f_m ap[8][8]; /*8 by 8 m ap*/
int i,j, rx, ry, object; /*this is your x and y value in your m ap (f_map)*/
system("cls"); /* this is your x and y value in your map (f_map)*/
//srand(tim e(NULL)); /*calling the tim e 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_m ap[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;i
strcpy(f_m ap[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;i
strcpy(f_m ap[rand()%8][rand()%8].data, rvr->im);
}
rx= p_rover->location[0];
ry= p_rover->location[1];
strcpy(f_m ap[1][0].data, wdp->im);
strcpy(f_m ap[4][0].data, m nt->im);
strcpy(f_m ap[5][0].data, m nt->im);
strcpy(f_m ap[3][1].data, dst->im);
strcpy(f_m ap[4][1].data, dst->im);
strcpy(f_m ap[3][2].data, dst->im);
strcpy(f_m ap[4][2].data, dst->im);
strcpy(f_m ap[0][3].data, m nt->im);
strcpy(f_m ap[1][3].data, m nt->im);
strcpy(f_m ap[3][3].data, vshr->im);
strcpy(f_m ap[4][3].data, dst->im);
strcpy(f_m ap[5][3].data, vgnt->im);
strcpy(f_m ap[3][4].data, vshr->im);
strcpy(f_m ap[4][4].data, dst->im);
strcpy(f_m ap[5][4].data, vgnt->im);
strcpy(f_m ap[2][5].data, wshl->im);
strcpy(f_m ap[3][5].data, wshl->im);
strcpy(f_m ap[4][5].data, wshl->im);
strcpy(f_m ap[1][6].data, pstn->im);
strcpy(f_m ap[2][6].data, wdp->im);
strcpy(f_m ap[3][6].data, wdp->im);
strcpy(f_m ap[4][6].data, wshl->im);
strcpy(f_m ap[7][6].data, m nt->im);
strcpy(f_m ap[0][7].data, m nt->im);
strcpy(f_m ap[1][7].data, wdp->im);
strcpy(f_m ap[2][7].data, wshl->im);
strcpy(f_m ap[3][7].data, wshl->im);
strcpy(f_m ap[6][7].data, m nt->im);
strcpy(f_m ap[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);
}
else if((rx == 2 && ry == 5) || (rx == 3 && ry == 5 ) || (rx == 4 && ry == 5) || (rx
== 4 && ry == 6) ||(rx == 2 && ry == 7) || (rx == 3 && ry == 7))
{
object = 8;
action(object, p_rover);
}
else if(rx == 1 && ry == 6)
{
object = 13;
action(object, p_rover);
}
i=0; /*re-allocate i to 0 so m ap is printed from start*/
for(i=0;i<8;i++) /*8 by 8 map*/
{
printf("+----+----+----+----+----+----+----+----+\n");
for(j=0;j<8;j++) /*8 by 8 map*/
{
if(strlen(f_map[i][j].data)!=0) /*if function to print nothing but 4 spaces if there in nothing allocated in [i][j]*/
printf("|%4s",f_map[i][j].data);
else
printf("| "); /*end of coloumn visible m ap*/
}
printf("|\n"); /*end of last coloum n visible map*/
}
printf("+----+----+----+----+----+----+----+----+\n"); /*bottom of m ap*/
printf("\n");
printf("\270");
printf("Group B\n");
}
void add_obj(struct m ap *number, struct m ap *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *m nt, struct object_fix *dst,
struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *m tre,
struct object_fix *wshl, struct object_fix *wdp, struct object_m ove *aagr,
struct object_m ove *anon, struct object_m ove *rvr, struct object_m ove *pstn, struct rover *p_rover) /* add m ovable object function, *number=aliens, *number_2=rovers*/ {
int object, t, f;
char alien;
char rover;
printf("This is the add m ovable object function\n");
printf("how m any aliens would you like?\n");
scanf("%d",&t); /*user input of am ount of aliens*/
number->amount=t; /*saving the number in structure m ap-am ount*/
printf("how m any rovers would you like?\n");
scanf("%d",&f); /*user input of am ount of rovers*/
number_2->amount=f; /*saving the number in structure m ap-am ount*/
show_map(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, m tre, wshl,
wdp, aagr, anon, rvr, pstn, p_rover); /*go to show m ap function with the num ber of aliens and number of rovers*/
}
void successor() /*this functions askes the user for the location and then were they want to go from there, printing out that location*/
{
struct m ap location;
int m enu;
int ncol,nrow; /*we can change the n value depends how large the m ap you need.*/
ncol=8;
nrow=8;
printf("This is the successor function\n");
printf("Enter the \nx=\ty=\n");
scanf("%d%d",&location.x,&location.y); /*saving location in map location x and y*/ printf("Enter operator choice\n");
printf("1=left\n");
printf("2=right\n");
printf("3=upwards\n");
printf("4=down\n");
printf("5=quit\n");
scanf("%d",&m enu);
switch(m enu) /*m enu switch to show the position above, underneith, and next to the rover*/
{
case 1:location.x=location.x-1;
printf("The position is [%d,%d]\n",location.x,location.y);
break;
case 2:location.x=location.x+1;
printf("The position is [%d,%d]\n",location.x,location.y);
break;
case 3:location.y=location.y-1;
printf("The position is [%d,%d]\n",location.x,location.y);
break;
case 4:location.y=location.y+1;
printf("The position is [%d,%d]\n",location.x,location.y);
break;
printf("*****back to program*****\n"); /* Quits the program and prints out the message */
break;
default:
printf("*****Please enter an integer from 1-5*****\n"); /* A default option if the user enters an incorrect value */
break;
}
printf("\n");
}
void help(struct m ap *number, struct m ap *number_2, struct object_fix *rsny,
struct object_fix *rsld, struct object_fix *m nt, struct object_fix *dst,
struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *m tre,
struct object_fix *wshl, struct object_fix *wdp, struct object_m ove *aagr,
struct object_m ove *anon, struct object_m ove *rvr, struct object_m ove *pstn, struct rover *p_rover) /*help function*/
{
int i;
char m ov_obj;
printf("++T his is the help function++\n");
printf("| 1-successor |\n");
printf("| 2-add m ovable obj |\n");
printf("| 3-rem ove moveabla obj |\n\n");
printf("\t* * *\n");
printf("\t Index: \n\n");
printf("\t Sandy Rock: *\n");
printf("\t Solid Rock: o\n");
printf("\t Water:\262\262\262\262 \n");
printf("\t Shallow water: \260\260\260\260\n");
printf("\t Mountain: ^^^^\n");
printf("\t Dust: ....\n");
printf("\t* sher valley: VVVV *\n");
printf("\t shallow valey: vvvv\n");
printf("\t power station: \025\n");
printf("\t alien: *_*\n");
printf("\t other rovers: #\n");
printf("\t* * *\n");
scanf("%d",&i);
switch(i) /*switch m enu to go to the successor function, or the add/remove function*/ {
case 1:
successor();
break;
case 2:
add_obj(number, number_2, rsny, rsld, mnt, dst, vshr,
vgnt, m tre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);
case 3:
add_obj(number, number_2, rsny, rsld, mnt, dst, vshr,
vgnt, m tre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);
break;
default:
printf("choose a number from the list\n");
}
}
void direction(int input, struct m ap *number, struct m ap *number_2, struct object_fix *rsny,
struct object_fix *rsld, struct object_fix *m nt, struct object_fix *dst,
struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *m tre,
struct object_fix *wshl, struct object_fix *wdp, struct object_m ove *aagr,
struct object_m ove *anon, struct object_m ove *rvr, struct object_m ove *pstn, struct rover *p_rover)
{
switch(input)
{
case 119: /*w = up*/
if(p_rover->location[0] > 0)
{
p_rover->location[0]--;
p_rover->pwr--;
}else p_rover->location[0]=7;
break;
case 115: /*s = down*/
if(p_rover->location[0] < 7)
{
p_rover->location[0]++;
p_rover->pwr--;
}else p_rover->location[0]=0;
break;
case 97: /*a = left*/
if(p_rover->location[1] > 0)
{
p_rover->location[1]--;
p_rover->pwr--;
}else p_rover->location[1]=7;
break;
case 100: /*d = right*/
if(p_rover->location[1] < 7)
{
p_rover->location[1]++;
p_rover->pwr--;
}else p_rover->location[1]=0;
break;
default:
printf("Invalid operator!\n\n");
}
}
int control(int input)
{
input = _getch();
return input;
}
void main(void)
{
int m enu;
int quit = 0;
int input = 0;
struct object_fix rsny, rsld, mnt, dst, vshr, vgnt, m tre, wshl, wdp;
struct object_m ove aagr, anon, rvr, pstn;
struct rover p_rover;
struct m ap number, number_2;
number.amount = 0; /* setting the initial amount of aliens as 0*/
number_2.amount = 0;
strcpy(rsny.nam e,"Sandy Rock");
strcpy(rsny.id,"RSNY");
strcpy(rsny.desc,"A rock m ade of softer m aterial that can be destroyed or collected"); strcpy(rsny.im,"*");
strcpy(https://www.360docs.net/doc/c34929289.html,,"Solid Rock");
strcpy(rsld.id,"RSLD");
strcpy(rsld.desc,"A rock made of hard m aterial that cannot be destroyed, but can be collected or avoided");
strcpy(rsld.im,"O");
strcpy(mnt.nam e,"Mountain");
strcpy(mnt.id,"MNT");
strcpy(mnt.desc,"A large obstacle m ade of different m aterials that can only be avoided"); strcpy(mnt.im,"^^^^");
strcpy(dst.nam e,"Dust");
strcpy(dst.id,"DST");
strcpy(dst.desc,"Small particles of sand, rock, etc. that m ay reduce visibility or slow down the vehicle, can be driven through but has extra power consumption");
strcpy(dst.im,"....");
strcpy(vshr.nam e,"Sheer Valley");
strcpy(vshr.id,"VSHR");
strcpy(vshr.desc,"A depression in the land with sheer sides, it cannot be driven through and must be avoided");
strcpy(vshr.im,"VVVV");
strcpy(vgnt.nam e,"Gentle Valley");
strcpy(vgnt.id,"VGNT");
strcpy(vgnt.desc,"A depression in the land with gentle sides, it can be driven through with extra power consumption or can be avoided");
strcpy(vgnt.im,"vvvv");
strcpy(m https://www.360docs.net/doc/c34929289.html,,"'Martian' Tree");
strcpy(m tre.id,"MT RE");
strcpy(m tre.desc,"A woody plant native to Mars, it m ay have the sam e characteristics as an 'Earth' tree");
strcpy(m tre.im,"\330");
strcpy(wshl.nam e,"Shallow Water");
strcpy(wshl.id,"WSHL");
strcpy(wshl.desc,"A shallow body of water that can be driven through, can be in the form of a sm all puddle or a large lake");
strcpy(wshl.im,"\260\260\260\260");
strcpy(wdp.nam e,"Deeper Water");
strcpy(wdp.id,"WDP");
strcpy(wdp.desc,"A deeper body of water that cannot be driven through, commonly in the form of a large lake or river");
strcpy(wdp.im,"\262\262\262\262");
strcpy(aagr.nam e,"Aggressive Alien");
strcpy(aagr.id,"AAGR");
strcpy(aagr.desc,"An alien creature that will move upon its own accord, m ay becom e aggressive on contact");
strcpy(aagr.im,"*_*");
strcpy(anon.nam e,"Non-Aggressive Alien");
strcpy(anon.id,"ANON");
strcpy(anon.desc,"An alien creature that will move upon its own accord, will not becom e aggressive on contact");
strcpy(anon.im,"*_*");
strcpy(https://www.360docs.net/doc/c34929289.html,,"Rover");
strcpy(rvr.id,"RVR");
strcpy(rvr.desc,"A Mars Rover vehicle to transport around the m ap, it can destroy, collect or avoid objects. It has a power and object storage");
strcpy(rvr.im,"#");
strcpy(pstn.nam e,"Power Station");
strcpy(pstn.id,"PSTN");
strcpy(pstn.desc,"A m ovable power station that will restore power to the Mars Rovers"); strcpy(pstn.im,"\025");
strcpy(p_rover.nam e,"User Mars Rover");
strcpy(p_rover.id,"URVR");
strcpy(p_rover.desc,"A Mars vehicle that is controlled by the user. Explores the m ap collecting, destroying and avoiding objects");
strcpy(p_rover.im,"<^^>");
p_rover.pwr = 100;
p_rover.strg = 0;
p_rover.location[0] = 7;
p_rover.location[1] = 0;
/****************************************************/
printf("*******************************START***************************** ***\n\n");
do{ /* Object will be gained from mapper */
printf("+++++++++++++++++++++++++++++++MENU++++++++++++++++ +++++++++++++++++\n");
printf("Please choose one of the following option:\n");
printf("1 - Start\n");
printf("2 - Controls\n");
printf("3 - Show Map\n");
printf("4 - Help Menu\n");
printf("5 - Quit\n\n");
printf("--------------->");
scanf("%d", &menu);
switch (m enu)
{
case 1:
show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,
&vgnt, &m t re, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);
while (quit != 1 )
{
input = control(input);
if (input == 27)
quit = 1;
else
{
if(p_rover.pwr>0)
{
direction(input, &number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,
&vgnt, &m t re, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);
show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,
&vgnt, &m t re, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);
printf("Rover stats: \nPower: %d%% \nStorage: %d%%\n", p_rover.pwr, p_rover.strg); }
else
{
printf("*******************END GAME********************\n\n"); // ends game when charge = 0.
break;
}
}
}
break;
case 2:
quit = 0;
printf("\n");
printf("* * *\n");
printf(" Controls \n"); // m enu for the keys used on the keyboard to move the rover in different directions.
printf(" Up : W \n");
printf(" Down : S \n");
printf("* Left : A * \n");
printf("* Right : D * \n");
printf(" choose : Enter \n");
printf("* * *\n");
break;
case 3:
quit = 0;
show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,
&vgnt, &m t re, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover); break;
case 4:
quit = 0;
help(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,
&vgnt, &m t re, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover); break;
case 5:
printf("*********************END***********************\n"); break;
}
}while(menu!=5);
printf("\n -----Please press any key to exit gam e-----\n");
getch();
}
纯C语言写的一个小型游戏-源代码
纯C语言写的一个小型游戏-源代码
/* A simple game*/ /*CopyRight: Guanlin*/ #include
c语言小游戏编程
程序设计实践 大作业 学号:20100302XXXX 姓名:XXX 班级:信息10-3班 实验题目:射击类飞机游戏 页脚内容1
成绩: 一.实验题目: 射击类飞机游戏 二.实验目的: 通过c语言编写一个射击类的打飞机小游戏,可以通过键盘来进行游戏,操作方法是“a”“d”“w”或者“←”“↑”“→”来控制,击中敌机可获得积分,被敌机撞中死亡一次,每次游戏有3次生还机会,游戏结束后可选择是否重新开始游戏…… 三.对游戏的改进: 这个游戏是我对一个小游戏进行的改造升级版,添加了颜色函数、终止函数,选择类函数,使游戏实现了可以终止,不再是分数、死亡数一直增加但是没有结束的情况;增加了颜色函数,使得游戏看起来更加的舒适;增加了终止函数,使游戏在死亡三次后自动结束游戏,并且可以选择是否重新开始游戏;另外增添了设置函数,使得可以对游戏进行设置,改变游戏大小,调整飞机运行速度等等,是游戏更加的人性化…… 四.实验内容 页脚内容2
编写出c语言代码,运行程序,并调试程序,最终实现游戏的功能。本程序主要包含游戏控制函数、设置是否继续游戏函数、输出函数、子弹移动函数、敌机移动函数、设置函数、菜单函数等7个主要函数,包含了不同的功能,对原来的程序作出了很大的改进,用到的主要语句有getche语句、for语句、while语句、printf语句、switch语句等等,添加了颜色函数,实现了诸多功能。可以在页面上显示制作人的主要信息等等…… 【流程图见打印版】 五.源程序: #include
#include
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
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编写的小游戏 集团企业公司编码:(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 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){ #include 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; 程序设计实验 大作业 学院: 班级: 学号: 指导老师: 姓名: 实验项目名称:猜数字游戏成绩: 一、实验要求 根据所学知识编写一个小游戏--猜数字游戏 二、实验目的 为了加深对编程课程的基本知识的理解和掌握,并且掌握编程和程序调试的技巧通过程序的设计训练和提高学生的基本技能,掌握字符串的表示方法和字符串函数的功能、编程软件操作的基本知识、键盘上特殊键的获取以及图形方式下光标的显示,提高编程兴趣与编程水平,学会如何正确的书写程序设计说明文档,提高解决实际问题的能力,巩固语法规则的理解和掌握,学会通过源程序写出流程图,提高自学以及查阅资料的能力。 三、功能模块分析 1.系统能够随机产生一个1到1000的数字 2.比较输入数字与随机产生数字的大小 3.选择是否继续游戏 四、修改处 1.将输出内容由英文变为汉字 2.改变背景及输出字体的颜色 3将随机产生的数值范围由1-100变为1-1000 四、设计思路 # include 1: C语言游戏设计 1.1:课程设计目标 C语言编写一款打飞机游戏,掌握函数的使用和编程的整体思路。 1.2:整体设计思路 总体设想:运行游戏时显示游戏的界面,允许用户选择个性化设置,A、D、W分别控制飞机的左右移动和发射子弹,不同的敌机飞行和攻击,并不时伴有奖励。游行运行时播放音效,同时记录飞机的生命和得分,达到一定的分数进入下一关。 需要构建的函数:位图调用模块、界面输出函数、主菜单函数、设置函数、速度选择函数、游戏控制函数、敌机移动函数、子弹移动函数、boss 函数、计时函数。 1.3: 需调用的头文件:include 1.5:显示效果如下图所示: 初始设置界面:游戏界面 2 算法实现 2.1需要了解的知识点: Main函数和menu函数编写比较顺利,在bmp函数中遇到如何显示窗口和调用图片的问题,看了一些例子和网上的资料,逐渐掌握了一下知识点: ○1设备上下文:设备,显示器,打印机,数码相机,扫描仪这些类似的设备, 上下文,就是上面设备的相关信息,比如屏幕分辨率等 ○2 HANDLE 通用句柄,实际上是一个指向指针的指针,在Windows操作系统中, 内存操作器经常移动对象,来满足各种程序的内存需要,为了解决寻找对象问题,内存管理器开辟出一块专门的内存储存空间,把移动后的地址存储在该空间,这样就可以通过该地址间接寻找到对象。 ○3 HDC设备描述句柄,实现对窗口操作区域的GDI(图形设备接口, 负责系统 与绘图程序之间的信息交换,处理所有Windows程序的图形输出)操作,如画线、写文本、绘画制图等。 ○4 BITMAP 用于处理有像素数据定义的图像的对象。 语言游戏源代码1、简单地开机密码程序 "" "" "" () {()()()()(" ! ' !!!"); (); *若有错误不能通过程序* } () { *,*; *":\\\\"; *本程序地位置* []; *"",*".^^^"; *是地备份*(); * :*("\\"); * \*(,""); () {(,""); () ();}(); *读取前各字符* []'\'; (()) *若读取地和指针一样就关闭文件,不然就添加*(); {(,""); () ()()('\'); (); (()) {()();} (); (); (()){()();}()(); (); * * } } () { *""; [] ; () {()()()(); ; ()()()()(":"); () {[](); (>) {(); ;} *若字符多于个字符就结束本次输入* ([]) ; ([]> []<) *若字符是数字或字母才算数* {('*'); ;} ([]) *删除键* (>) {("\ \"); []'\'; ;} } []'\'; (()) ; {(); ()()()()(" !")();} } } () {(); (); } 2、彩色贪吃蛇 <> <> ; * 游戏速度*, , ; * 游戏分数* [] { , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 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 /* A simple game*/ /*CopyRight: Guanlin*/ #include 本世纪70年代,人们曾疯魔一种被称作“生命游戏”的小游戏,这种游戏相当简单。假设有一个像棋盘一样的方格网,每个方格中放置一个生命细胞,生命细胞只有两种状态:“生”或“死”。游戏规则如下: 1. 如果一个细胞周围有3个细胞为生(一个细胞周围共有8个细胞),则该细胞为生,即该细胞若原先为死,则转为生,若原先为生,则保持不变; 2. 如果一个细胞周围有2个细胞为生,则该细胞的生死状态保持不变; 3. 在其它情况下,该细胞为死,即该细胞若原先为生,则转为死,若原先为死,则保持不变。 依此规则进行迭代变化,使细胞生生死死,会得到一些有趣的结果。该游戏之所以被称为“生命游戏”,是因为其简单的游戏规则,反映了自然界中的生存规律:如果一个生命,其周围的同类生命太少的话,会因为得不到帮助而死亡;如果太多,则会因为得不到足够的资源而死亡。 用计算机模拟这个“生命游戏”也相当简单,可以用一个M×N像素的图像来代表M×N个细胞,其中每一个像素,代表一个细胞,像素为黑色表示细胞为生,像素为白色代表细胞为死。 设定图像中每个像素的初始状态后依据上述的游戏规则演绎生命的变化,由于初始状态和迭代次数不同,将会得到令人叹服的优美图案。 下面给出的小程序是用TC2.0编写。演示100×100个生命细胞初始状态全为生时的变代情况,变化时边缘细胞不参与变化。随着迭代次数的不同,在屏幕显示的图案精彩纷呈,像万花筒般引人入胜。 #include 纯真童趣的《泡泡堂》,还有武林情仇,笑傲江湖的《剑侠情缘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*/ #include 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"); 用vc6.0新建一个Win32 Application工程,把附件代码拷贝进去即可。上下左右键控制蛇的方向,空格键用于启动或者停止游戏。 上下左右空格键 #include 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 语言程序设计课题名称:医院信息管理系统 专业班别: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语言编写小游戏 ----------------------------精品word文档值得下载值得拥有---------------------------------------------- 纯真童趣的《泡泡堂》,还有武林情仇, 笑傲江湖的《剑侠情缘on line》.它是e时代常谈的话题,是交互 式娱乐的主力军,是一种 高层次的综合艺术,更是一个民族的文 化,世界观的全新传播方式 .作为游戏玩家的我们,是不是想设计一 个属于自己的游戏呢? 爱玩是人的天性,而C语言是我们计算机 专业都要学习的一门基础 学科.一般来说,是比较枯燥的.那么,我 们能不能通过编一些小 游戏来提高它的趣味性呢?这样学习程 序设计,就不会是一件艰苦 ----------------------------精品word文档值得下载值得拥有---------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------- ----------------------------精品word文档值得下载值得拥有---------------------------------------------- ,枯燥的事,它变得象电脑游戏一样充满 好奇,富有乐趣.这正是 我发贴的目的. 1, 总是从Hello,world开始 学习编程的第一个程序,一般就是打印 一个亲切的词语——"Hell o,world!".让我们来看看这个最简单的 C程序: #incolude C编写的小游戏
一个C语言写的简单贪吃蛇源代码
C语言小游戏程序设计
c语言游戏讲解
C语言游戏源代码
C编写的小游戏
纯C语言写的一个小型游戏-源代码
C语言实现生命游戏
使用C语言编写简单小游戏
纸牌记忆小游戏C语言源代码
c语言编写的小游戏代码
C语言程序设计(医院信息管理系统)附源代码
如何用c语言编写小游戏