#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#include<graphics.h>
#define NULL 0
#define LENID sizeof(struct gameid)
#define LEN sizeof(struct game)
#include <iostream>
#pragma comment(lib,"winmm.lib")
#include <windows.h>
using namespace std;
#define XXX 14 //方框的横轴大小
#define YYY 25 //方框的竖轴大小
int dia_x, dia_y;//存储方块的位置,左上角
int shape, change, nextshape, nextchange;//定义方块的开关与变型
clock_t nowtime;//定义开始时间
int Background[YYY][XXX] = {0};//定义背景并初始化
int Is_Gethit = 0;//接受按键为1, 否则为0;
int score = 0, Allscore = 0;//你的得分
int level,speed;
int timing;//存放时间
char timee[30];
char choose;//记录键值
int choose1;//是否跳出读取键值
int quit;
clock_t over,start;//单位(s)
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);//设置控制台
int program=0;
int a=1;//判断游戏密码是否存在
int pausing;//判断是否跳出暂停
void saveid(struct gameid *headid);
struct gameid *loadid();
struct gameid *shifangid(struct gameid *headid);
struct game *shifang(struct game *head);
void gotoxy(int x,int y);
void savetime(char *p);
void goodmotherpattern();
struct game
{
char name[30];
char score[30];
struct game *next;
};
struct gameid
{
char password[30];
struct gameid *nextid;
};
void kaishi(void)
{
int gdriver, gmode;
int a;
gdriver=VGA;
gmode=VGAHI;
initgraph(&gdriver, &gmode, "");
bar3d(0, 0, 1500, 1500,5, 1);
setbkcolor(WHITE);
for(a=0;a<480;a++)
{
setcolor(BLUE);
setfont(30,0,_T("楷体"));
outtextxy(60,a,_T(" \n"));
outtextxy(30,a-380,_T("一起来玩\n"));
setcolor(BLUE);
setfont(60,0,_T("楷体"));
outtextxy(60,a,_T(" \n"));
outtextxy(150,a-300,_T("俄罗斯方块\n"));
setcolor(GREEN);
setfont(30,0,_T("楷体"));
outtextxy(320,a,_T(" \n"));
outtextxy(320,a-130,_T("ElevenTH 团队 制作\n"));
Sleep(10);
}
}
void Close(void)
{
closegraph();
}
//读取键值
void Getkbhit1()//对上下左右按键的处理
{
choose='0';
if(kbhit())//如果有按键刚进入按键处理
{
switch(getch())
{
case '1':
choose='1';
break;
case '2':
choose='2';
break;
case '3':
choose='3';
break;
case '4':
choose='4';
break;
case '5':
choose='5';
break;
case '6':
choose='6';
break;
default:
choose='0';
break;
}
}
goodmotherpattern();
}
void open()
{
const M=25;
int k;
printf("\n 〓程序加载中>>>> ");
for (k=1;k<=M;k++)
{
printf("■");
Sleep(120);
}
}
//按键说明
void state()
{
gotoxy(55,14);
printf("按键说明: ");
gotoxy(55,16);
printf("p - 暂停 q - 退出 ");
gotoxy(55,18);
printf("w - 变形 a - 左移");
gotoxy(55,20);
printf("s - 下降 d - 右移");
}
//好妈妈倒计时图案
void goodmotherpattern()
{
int h,m,s;
h=(over-((clock()-start)/CLOCKS_PER_SEC))/3600;
m=(over-((clock()-start)/CLOCKS_PER_SEC)-h*3600)/60;
s=(over-((clock()-start)/CLOCKS_PER_SEC)-h*3600-m*60);
gotoxy(55,19);
printf(" 好妈妈助手提示 ");
gotoxy(55,20);
printf("----------------------");
gotoxy(55,21);
printf("| 程序结束倒计时: |");
gotoxy(55,22);
printf("| %2d:%2d:%2d |",h,m,s);
gotoxy(55,23);
printf("----------------------");
}
void goodmotherpattern1()
{
int h,m,s;
h=(over-((clock()-start)/CLOCKS_PER_SEC))/3600;
m=(over-((clock()-start)/CLOCKS_PER_SEC)-h*3600)/60;
s=(over-((clock()-start)/CLOCKS_PER_SEC)-h*3600-m*60);
gotoxy(54,6);
printf(" 好妈妈助手提示 ");
gotoxy(54,7);
printf("----------------------");
gotoxy(54,8);
printf("| 程序结束倒计时: |");
gotoxy(54,9);
printf("| %2d:%2d:%2d |",h,m,s);
gotoxy(54,10);
printf("----------------------");
}
//因时间到而退出的界面
void overfunction()
{
float c;
system("cls");
printf("\n\n\n\n\n");
printf("\t\t好妈妈助手提示您:");
printf("\n\n\n\n");
printf("\t\t\t从程序开始到现在已经过去了%.3f个小时,\n",(float)over/3600);
printf("\n\n");
printf("\t\t\t\t快去休息一下吧!");
printf("\n\n\n\n\n\n\n");
printf("\t\t\t\t\t\t");
Sleep(10000);
}
//转换函数
void transform2()
{
over=0;
int c,d;
for(c=0;timee[c]!='\0';c++);
for(d=0;d<(c);d++)
over+=(timee[d]-48)*(int)pow(10,c-1-d);
}
//排行榜排序函数
struct game *paixu(struct game *head)
{
struct game *p1,*p2;
int i,j;
struct game1
{
char name[30];
char score[30];
};
struct game1 px[200];
struct game1 temp;
if(head==NULL)
{
printf("\t\t\t*** 排行榜为空,无法排序! ***\n");
return(head);
}
p1=head;
for(i=0;i<11,p1!=NULL;i++)
{
strcpy(px[i].name,p1->name);
strcpy(px[i].score,p1->score);
p2=p1;
p1=p1->next;
}
head=shifang(head);
for(j=0;j<10;j++)
{
for(i=j+1;i<11;i++)
{
if(strcmp(px[i].name,px[j].name)>0)
{
temp=px[i];
px[i]=px[j];
px[j]=temp;
}
}
}
p1=(struct game *)malloc(LEN);
p2=p1;
strcpy(p1->name,px[0].name);
strcpy(p1->score,px[0].score);
head=p1;
for(i=1;i<11;i++)
{
p1=(struct game *)malloc(LEN);
strcpy(p1->name,px[i].name);
strcpy(p1->score,px[i].score);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
//(分数)数字转换为字符串函数
char *transform(int scorein)
{
char scorechar[30];
scorechar[0]=scorein/1000+48;
scorechar[1]=scorein/100+48;
scorechar[2]=scorein/10-scorein/100*10+48;
scorechar[3]=scorein/1-scorein/10*10-scorein/100*100+48;
scorechar[4]='\0';
return scorechar;
}
//(最大时常)数字转换为字符串函数
char *transform1(int scorein)
{
int timeint;//记录位数
int timeint1;
char timechar[30];
for(timeint=0;scorein/((int)pow(10,timeint));timeint++);
for(timeint1=0;timeint1<timeint;timeint1++)
{
timechar[timeint1]=scorein/((int)pow(10,timeint-timeint1-1))+48;
scorein-=scorein/((int)pow(10,timeint-timeint1-1))*pow(10,timeint-timeint1-1);
}
timechar[timeint1]='\0';
return timechar;
}
//好妈妈助手
void goodmothersystem()
{
FILE *fp;
int counting;
struct gameid *headid,*p1id;
char password[30],password1[30],password2[30],num[30],timeset[30],timeset1[30];
int m;//检测密码输入是否一致
int goodmother;//检测是否跳出好妈妈系统
if((fp=fopen("password.txt","r"))==NULL)
{
m=0;
system("cls");
printf("\n\n\n\t* * * * 由于首次使用好妈妈助手,请设置好妈妈密码 * * * *");
while(!m)
{
printf("\n\n\n\n\n");
printf("\t\t请 <输入> 好妈妈密码:");
gets(password1);
while(*password1=='\0')
{
printf("\n");
printf("\t\t密码输入不能为空,请重新输入!\n");
printf("\n");
printf("\t\t请 <输入> 好妈妈密码:");
gets(password1);
}
printf("\n\t\t请 <确认> 好妈妈密码:");
gets(password2);
while(*password2=='\0')
{
printf("\n");
printf("\t\t密码输入不能为空,请重新输入!\n");
printf("\n");
printf("\t\t请 <确认> 好妈妈密码:");
gets(password2);
}
if(strcmp(password1,password2)==0)
{
printf("\n\n\n");
printf("\t\t\t密码设置成功!");
printf("\n\n\n\n");
printf("\t\t\t\t\t\t密码保存完毕(按回车键继续)!\n");
m=1;
}
else
{
printf("\n");
printf("\t\t两次密码输入不一致,请重新输入!\n");
m=0;
}
}
headid=(struct gameid *)malloc(LENID);
strcpy(headid->password,password1);
headid->nextid=NULL;
saveid(headid);
free(headid);
}
headid=loadid();
system("cls");
printf("\n\n\n\n\n");
printf("\t\t请输入好妈妈密码:");
gets(password);
counting=0;
while(strcmp(headid->password,password)!=0)
{
printf("\n");
counting+=1;
if(counting==5)
{
shifangid(headid);
exit(0);
}
printf("\t\t好妈妈密码错误(您还有%d次机会),请确认后输入:",5-counting);
gets(password);
}
printf("\n\n\n");
system("cls");
printf("\n\n\n\n\n\n\n");
printf("\t\t\t好妈妈密码验证通过�