本人大一的课程设计,时间太长,代码可能有些许丢失,欢迎纠错

/*功能:超市寄存管理系统
完成时间:2014年6月12日夜12点
完成地点:12#506宿舍
院系:信息工程学院
班级:网工1301B
作者:
#include<stdio.h>
#include<windows.h>
#include<stdlib.h>//预处理头文件
#include<string.h>
#include<time.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")///导入winmm.lib库,支持对windows 多媒体的编程.
#define CLS system("cls")
#include<conio.h>
/********游戏所需函数变量声明********/
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade = 1, C_Gold = 0, C_Ag = 0, Score = 0, Delay_time = 1000, Max_blank = 9, Distance = 18;
struct Birds
{
 int x, y;
 int condition;
};
Birds *Bird = (Birds*)malloc(sizeof(Birds));
struct Bg
{
 int x, y;
 int l_blank;
 int reward[9];
 Bg *pri;
 Bg *next;
};
Bg *Bg1 = new Bg[sizeof(Bg)];
void Position(int x, int y)
{
 COORD pos = { x - 1, y - 1 };
 HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleCursorPosition(Out, pos);
}
void CreatBird()
{
 Bird->x = 41;
 Bird->y = 10;
 Bird->condition = 0;
}
void CreatBg()
{
 Bg *Bg2 = (Bg*)malloc(sizeof(Bg));
 Bg1->x = 90; Bg1->y = 8;
 Bg2->x = Bg1->x + Distance; Bg2->y = 9;
 Bg1->l_blank = Max_blank - Grade;
 Bg2->l_blank = Max_blank - Grade;
 Bg1->next = Bg2;
 Bg1->pri = Bg2;
 Bg2->next = Bg1;
 Bg2->pri = Bg1;
}
void InsertBg(Bg *p)
{
 int temp;
 Bg *Bgs = (Bg*)malloc(sizeof(Bg));
 Bgs->x = p->pri->x + Distance;
 Bgs->l_blank = Max_blank - Grade;
 srand((int)time(0));
 temp = rand();
 if (temp % 2 == 0)//++
 {
 if ((temp % 4 + p->pri->y + Max_blank - Grade)<21)
 Bgs->y = p->pri->y + temp % 4;
 else
 Bgs->y = p->pri->y;
 }
 else
 {
 if ((p->pri->y - temp % 4)>2)
 Bgs->y = p->pri->y - temp % 4;
 else
 Bgs->y = p->pri->y;
 }
 Bgs->pri = p->pri;
 Bgs->next = p;
 p->pri->next = Bgs;
 p->pri = Bgs;
}
void Check_Bg(Bg *q)
{
 Bg *p = q; int i = 0, temp;
 while (++i <= 5)
 {
 if (p->x>-4)
 p = p->next;
 else
 {
 srand((int)time(0));
 temp = rand();
 if (temp % 2 == 0)//++
 {
 if ((temp % 4 + p->y + Max_blank - Grade)<21)
 p->y = p->y + temp % 4;
 else
 p->y = p->y;
 p->x = p->pri->x + Distance;
 p->l_blank = Max_blank - Grade;
 }
 else
 {
 if ((p->y - temp % 4)>2)
 p->y = p->y - temp % 4;
 else
 p->y = p->y;
 p->x = p->pri->x + Distance;
 p->l_blank = Max_blank - Grade;
 }
 }
 }
}
void Loop_Bg(Bg *q)
{
 Bg *p = q; int i = 0;
 while (++i <= 5)
 {
 p->x = p->x - 1;
 p = p->next;
 if (Bird->x == p->x)
 {
 Score += 1;
 if (Score % 4 == 0 && Grade<4)
 Grade++;
 }
 }
}
void Prt_Bg(Bg *q)
{
 Bg *p = q; int i = 0, k, j;
 while (++i <= 5)
 {
 if (p->x>0 && p->x <= 78)
 {
 for (k = 2; k<p->y; k++)
 {
 Position(p->x + 1, k);
 PR_Box; PR_Box; PR_Blank
 }
 Position(p->x, p->y);
 PR_Box; PR_Box; PR_Box; PR_Blank;
 Position(p->x, p->y + p->l_blank);
 PR_Box; PR_Box; PR_Box; PR_Blank;
 k = k + p->l_blank + 1;
 for (k; k <= 22; k++)
 {
 Position(p->x + 1, k);
 PR_Box; PR_Box; PR_Blank;
 }
 Position(p->x, 23);
 for (k = 1; k<Distance / 3 - 2; k++)
 PR_Land;
 }
 p = p->next;
 if (p->x == 0)
 {
 for (j = 2; j<p->y; j++)
 {
 Position(p->x + 1, j);
 PR_Blank; PR_Blank;
 }
 Position(p->x + 1, p->y);
 PR_Blank; PR_Blank; PR_Blank;
 Position(p->x + 1, p->y + Max_blank - Grade);
 PR_Blank; PR_Blank; PR_Blank;
 j = j + Max_blank - Grade + 1;
 for (j; j <= 22; j++)
 {
 Position(p->x + 1, j);
 PR_Blank; PR_Blank;
 }
 }
 }
}
void PrtBg()
{
 int i;
 Position(1, 1); PR_Bg_TL;
 Position(79, 1); PR_Bg_TR;
 Position(1, 24); PR_Bg_DL;
 Position(79, 24); PR_Bg_DR;
 for (i = 3; i <= 78; i += 2)
 {
 Position(i, 1); PR_Bg_X;
 Position(i, 24); PR_Bg_X;
 }
 /*for(i=2;i<=23;i++)
 { Position(1,i);PR_Bg_Y;printf("%d",i-1);
 Position(79,i);PR_Bg_Y;
 }*/
}
void PrtBird()
{
 Position(Bird->x, Bird->y - 1);游戏代码——————————————————
 PR_Blank;
 Position(Bird->x, Bird->y);
 PR_FBird;
 Position(38, 2);
 printf("Score:%d", Score);
}
int CheckYN(Bg *q)
{
 Bg *p = q; int i = 0;
 while (++i <= 5)
 {
 if (Bird->y>23)
 return 0;
 if (Bird->x == p->x&&Bird->y <= p->y)
 return 0;
 if ((Bird->x == p->x || Bird->x == p->x + 1 || Bird->x == p->x + 2) && Bird->y == p->y)
 return 0;
 if (Bird->x == p->x&&Bird->y>p->y + p->l_blank)
 return 0;
 if ((Bird->x == p->x || Bird->x == p->x + 1 || Bird->x == p->x + 2) && Bird->y == p->y + p->l_blank)
 return 0;
 p = p->next;
 }
 return 1;
}
void Prtfirst()
{
 printf("══════════════════════════════════════\n");
 printf(" ■■ ■■\n");
 printf(" ■■ ■■\n");
 printf(" ■■ ■■ C语言版 快乐小鸟\n");
 printf(" ■■ ■■ 瞎搞人:磊哥\n");
 printf(" ■■ ■■ 瞎搞日期:2014.2\n");
 printf(" ■■ ■■ 耗时:4小时\n");
 printf(" ■■■ ■■ 游戏说明:\n");
 printf(" ■■ 1-按上箭头使鸟起飞\n");
 printf(" ■■ 2-等级越高,难度越大!\n");
 printf(" Ю ■■■\n");
 printf("\n");
 printf(" ■■■ 欢迎各路大神与我探讨C、C++、VB、PHP、C#\n");
 printf(" ■■\n");
 printf(" ■■\n");
 printf(" ■■ ■■■ 【无版权,随意修改】\n");
 printf(" ■■ ■■\n");
 printf(" ■■ Ф ■■\n");
 printf(" ■■ ■■\n");
 printf(" ■■ ■■\n");
 printf(" ■■ ■■\n");
 printf(" ■■ ■■\n");
 printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n");
 system("pause");
 Position(1, 1);
 int i = 0;
 while (i++<40 * 25)
 PR_Blank;
}
struct goods{
int num;
   char passward[6];
char name[10];
}g[50];
void welcome();
void slect();
int cun(struct goods g[50]);
void qu(struct goods g[50]);//各个子函数
void printf();
void out();
void set_color();
void seach(struct goods g[50]);
void game();
//文件
FILE *cun_record;
FILE *qu_record;
int Count=0;
int main(void)
{
system("Title 超市寄存管理系统");//设置标题
    PlaySound (TEXT("C:\\1.mp3"), NULL, SND_ASYNC | SND_NODEFAULT);//播放背景音乐
welcome();
slect();//主函数
out();
return 0;
}
//欢迎界面
void welcome()
{
char s[10]="color 0",str;
int n = 20;
srand((unsigned int) time(NULL));
printf("\n\n\n\n\n");
    printf("                *                                                 *\n");
printf("                *                    ********                     *\n");
printf("                *                ****************                 *\n");
printf("                *               *******************               *\n");
printf("                *     * *   ***************************   * *     *\n");
printf("                *   *  *  **      #     **  #   #      **  *  *   *\n");
    printf("                *  *  *** * ####  ##### ** ## #    ### *  ***  *  *\n");
printf("                *   *  * **  # # # #  # **  # # #    #  ** *  *   *\n");
printf("                *     *****   #   # #   ** ## ###  ###  ** ***    *\n");
printf("                *        **  # # #   #  **  #   #  #    **        *\n");
printf("                *        ** #   #     # ** ###########  **        *\n");
printf("                *        **             **              **        *\n");
printf("                *        *********************************        *\n");
printf("                *   ******************************************    *\n");
printf("                *        ********使用超市物品寄存********         *\n");
printf("                *          *********管      理*********                                                                                              *\n");
printf("                *                 *****系统*****                  *\n");
    printf("                *                     *******                     *\n");
while(n--)
{
Sleep(100);
int num=rand()%9+1;
str=num+'0';
s[7]=str;
s[8] = '\0';
system(s);
}
system("color 04");
}
//功能选择
void slect(){
int choice=5;
while(choice!=0){
printf(" ※ ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");
printf(" ※                     [1],   寄存           [2],提取                           ※\n");
    printf(" ※                                                                              ※\n");
printf(" ※                      [3],打印存取记录             [4],换个颜色                  ※\n");
printf(" ※                                                                              ※\n");
printf(" ※                         [5],查询寄存信息     [0],退出                        ※\n");
printf("                                  [6],玩会儿,游戏?                              \n");
printf(" ******************************************************************************\n");
scanf("%d",&choice);
switch(choice){
case 1:cun(g);break;
case 2:qu(g);break;
case 3:printf();break;
case 4:set_color();break;
case 5:seach(g);break;
case 6:game();break;
case 0:break;
}
system("pause");
CLS;
}
}
//物品存放
int cun(struct goods g[50]){
if(Count>50)
printf("\n亲,不好意思,储物柜已满,请到其他地方存放");
if((cun_record=fopen("H:\\cun.txt","r"))==NULL){
printf("\n亲,您真是太幸运了,您是第一个使用本机器的人类,给你个飞吻吧");
Sleep(2000);
printf("\n                        ◎                   \n");
}
cun_record=fopen("H:\\cun.txt","w");
char s[6];
char name[10];
time_t now;
time(&now);
printf("\n                 请稍后,正在分配储物柜                          \n");
Sleep(2000);
printf("                           亲,您的货柜编号是%d\n",Count);
Sleep(2000);
printf("\n               已经打开储物柜,请将货物放入                         \n");
Sleep(2000);
printf("                亲,请输入货物名称,以便进行统计                    \n");
scanf("%s",name);
printf("\n              亲,请输入六位密码,并牢记密码:                     \n");
scanf("%s",s);
strcpy(g[Count].passward,s);
g[Count].num=Count;
printf("存入时间:%s",ctime(&now));
fprintf(cun_record,"%d\t%s\t%s\n",Count,name,ctime(&now));
   fclose(cun_record);
   Count++;
return 0;

}
//物品提取
void qu(struct goods g[50]){
if((qu_record=fopen("H:\\qu.txt","r"))==NULL){
printf("\n亲,您是今天第一个来取货的人\n");
}
qu_record=fopen("H:\\qu.txt","w");
   time_t now;
time(&now);
int num;
char mima[20];
printf("亲,请输入您的货柜编号\n");
scanf("%d",&num);
if(strcmp(g[num].name,"kong")==0)
printf("货物已被提取\n");
else{
if(num>Count)
printf("亲,对不起,没有寄存此货物\n");
else{
printf("亲,请输入您的密码\n");
scanf("%s",mima);
if(strcmp(g[num].passward,mima)==0){
printf("密码输入正确,货柜正在打开,请稍后。。。。\n");
Sleep(2000);
           fprintf(qu_record,"%d\t%s\t%s\n",num,g[num].name,ctime(&now));
printf("已经打开,请提取\n");
                strcpy(g[num].name,"kong");
}
else{
printf("亲,再好好想一想,您还有一次机会,请再次输入\n");
scanf("%s",mima);
            if(strcmp(g[num].passward,mima)==0){
printf("密码输入正确,货柜正在打开,请稍等。。。。。。\n");
Sleep(2000);
printf("已经打开,请提取\n");
           fprintf(qu_record,"%d\t%s\t%s\n",num,g[num].name,ctime(&now));
strcpy(g[num].name,"kong");
}
else{
printf("对不起,密码输入错误,请好好想一想,系统自动退出\n");
out();
}
}
}
}
   fclose(qu_record);
}
//退出
void out()
{
char s[10]="color 0",str;
int n = 20;
srand((unsigned int) time(NULL));
printf("\n\n\n\n\n");
 printf("*                                                 *\n");
printf("                *                    ********                     *\n");
printf("                *                ****************                 *\n");
printf("                *               *******************               *\n");
    printf("                *                     谢谢                        *\n");
printf("                *        *********************************        *\n");
printf("                *   ******************************************    *\n");
printf("                *        ********使用超市物品寄存********         *\n");
printf("                *          *********管      理*********           *\n");
printf("                *                 *****系统*****                  *\n");
    printf("                *                     *******                     *\n");
while(n--)
{
Sleep(100);
int num=rand()%9+1;
str=num+'0';
s[7]=str;
s[8] = '\0';
system(s);
}


system("color 07");
}
//改变字体颜色
void set_color()
{
int num;
srand((unsigned int)time(NULL));
char cmd[10] = "color 0" , ch;
num=(int)rand()%10;
ch=num+'0';
cmd[7]=ch;
cmd[8] = '\0';
system(cmd);
}
void printf(){
char ch;
if((cun_record=fopen("H:\\cun.txt","r"))==NULL)
printf("不好意思,亲,没有存入记录\n");
if((qu_record=fopen("H:\\qu.txt","r"))==NULL)
printf("不好意思,亲,没有取出记录\n");
printf("\n寄存记录\n");
printf("货柜编号\t货物名\t称取货时间\n");
while(!feof(cun_record)){
ch=fgetc(cun_record);
printf("%c",ch);
}
printf("取货记录\n");
while(!feof(qu_record)){
ch=fgetc(qu_record);
printf("%c",ch);
}
}
//查询
void seach(struct goods g[50]){
int c;
printf("\n亲,输入物品货柜编号\n");
scanf("%d",&c);
if(strcmp(g[c].name,"kong")==0)
printf("货物被提取,请到记录中查询\n");
else
printf("亲,您在%d号货柜存放的是%s\t",c,g[c].name);
}
//游戏
void game(){
CLS;
 int i = 0; 
 Prtfirst();
 PrtBg();
 CreatBg();
 InsertBg(Bg1);
 InsertBg(Bg1);
 InsertBg(Bg1);
 CreatBird();
 while (1)
 {
 if (!CheckYN(Bg1))
 break;
 Check_Bg(Bg1);
 Prt_Bg(Bg1);
 PrtBird();
 Loop_Bg(Bg1);
 Bird->y = Bird->y + 1;
 if (GetAsyncKeyState(VK_UP))
 {
 Position(Bird->x, Bird->y - 1);
 PR_Blank;
 Bird->y = Bird->y - 4;
 }
 while (i++<500);
 { Sleep(100);
 }
 i = 0;
 }
 Position(38, 10);
 printf("You Lost!");
 Position(1, 25);
 system("pause");
}



























































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值