資源簡(jiǎn)介
24點(diǎn)游戲.cpp
代碼片段和文件信息
#include?
#include?
#include?
#include?
using?namespace?std;
double?Operate(char?ch?double?a?double?b);
char?Precede(char?achar?b);
int?CaluExpress(char?*int?[]);
static?double?fabs(double);
int?fun1(int);
float?fun2(float?afloat?bint?n);
char?fun3(int);
char?fun4(int); ??
void?PrintExpress(int);
int?putr(int?*int);
void?ClearSpace(char?*);
void?GameResult();
void?PrintHelp();
void?RandomTest();
void?gotoxy(int?int);
void?PrintMenu(int);
void?clr(int?int);
void?PrintEnd(int);
void?file(int);
static?int?location;
static?int?times;
int?ans[4];
time_t?now;
struct?sort
{
char?na[5][30];
double?sc[5];
int?la;
}so;
void?file(int?n)
{???
????int?len;
if(n==0)
{????
FILE?*file=fopen(“rank.txt““wb“);
sort?te=so;
for(int?t2=0;t2<5;t2++)
{???
len=strlen(te.na[t2]);
for(int?t3=0;t3 te.na[t2][t3]--;
}
fwrite((char*)&tesizeof(te)1file);
fclose(file);
}
else?
{?????
FILE?*file=fopen(“rank.txt““rb“);
if(file==0)?return?;
fread((char*)&sosizeof(so)1file);
for(int?p=0;p<5;p++)
{??
len=strlen(so.na[p]);
for(int?j=0;j ????????????????so.na[p][j]++; ?
}
fclose(file);
}
}
void?gotoxy(int?nX?int?nY)//參見函數(shù)SetConsoleCursorPosition()
{
HANDLE?device;//定義一個(gè)句柄?
????device=GetStdHandle(STD_OUTPUT_HANDLE);???//獲得輸出設(shè)備的句柄
????COORD?position;?//定義結(jié)構(gòu)體變量?
????position.X=nX;????
????position.Y=nY;?
????SetConsoleCursorPosition(deviceposition);??//定位?
}?
void?PrintMenu(int?n)
{??
int?i;
switch(n)
{
case?1:
printf(“\n\t\t\t^-^歡迎進(jìn)入速算24游戲^-^\n\n“);
printf(“以下是游戲選項(xiàng):“);
printf(“??1.開始游戲??\t2.查看游戲規(guī)則及其排行????3.退出游戲。\n“);
printf(“請(qǐng)輸入游戲選項(xiàng):??“);
return?;
????case?2:
printf(“\n您只能輸入數(shù)字1,2?或?3。\n“);
PrintEnd(1);
return;
case?3:
clr(07);
printf(“請(qǐng)用加減乘除和括號(hào)將下面四個(gè)基數(shù)組成一串算式,使它的值為24。\n“);
printf(“您也可以直接選擇:?\n\n1.返回\t????2.退出\t3.產(chǎn)生一個(gè)答案\t????4.檢驗(yàn)一組基數(shù)\n“);
gotoxy(013);
printf(“敲“回車”鍵開始輸入并計(jì)時(shí)....“);
PrintEnd(0);
clr(013);
printf(“這組基數(shù)為:“);
for(i=0;i<4;i++)
printf(“%d???“ans[i]);
gotoxy(4414);
printf(“系統(tǒng)已開始計(jì)時(shí)“);
gotoxy(016);
printf(“開始輸入:“);
return?;
case?4:
clr(016);
printf(“其中一種算法:“);
putr(ans1);
PrintEnd(1);
return;
case?5:
printf(“并且您進(jìn)入了排行榜,請(qǐng)留下您的痕跡:“);?
return?;
case?6:
int?val[4];
clr(013);
printf(“請(qǐng)輸入要檢測(cè)的四個(gè)基數(shù):?“);
for(i=0;i<4;i++)
scanf(“%d“&val[i]);
for(i=0;i<4;i++)
if(val[i]>13||val[i]<1)
break;
fflush(stdin);
if(i<4)
printf(“\n數(shù)據(jù)范圍有誤!\n“);
if(i<4)
{?
PrintEnd(1);?
return?;
}
clr(2413);
for(i=0;i<4;i++)
printf(“%d?“val[i]);
gotoxy(015);
if(putr(val0)==0&&i==4)
printf(“此基數(shù)是無效的,不能算成24.\n“);
else?
printf(“此基數(shù)組是有效的,其中一種算法:“);
putr(val1);
PrintEnd(1);
return;
case?7:
gotoxy(1016);
printf(“??????????????????????????????????????????“);
printf(“\n\n計(jì)算錯(cuò)誤請(qǐng)重新輸入!“);
return;
評(píng)論
共有 條評(píng)論