?? user.c
字號(hào):
/*界面功能函數(shù)模塊*/
#include "MAGIC.h"
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <conio.h>
#include <io.h>
#include <time.h>
#include <bios.h>
#include <math.h>
#include <string.h>
char *BMP0[13]={"card\\1.bmp","card\\2.bmp","card\\3.bmp","card\\4.bmp","card\\5.bmp",
"card\\6.bmp","card\\7.bmp","card\\8.bmp","card\\9.bmp","card\\10.bmp",
"card\\11.bmp","card\\12.bmp","card\\13.bmp"};
char *BMP1[13]={"card\\14.bmp","card\\15.bmp","card\\16.bmp","card\\17.bmp","card\\18.bmp",
"card\\19.bmp","card\\20.bmp","card\\21.bmp","card\\22.bmp","card\\23.bmp",
"card\\24.bmp","card\\25.bmp","card\\26.bmp"};
char *BMP2[13]={"card\\27.bmp","card\\28.bmp","card\\29.bmp","card\\30.bmp","card\\31.bmp",
"card\\32.bmp","card\\33.bmp","card\\34.bmp","card\\35.bmp","card\\36.bmp",
"card\\37.bmp","card\\38.bmp","card\\39.bmp"};
char *BMP3[13]={"card\\40.bmp","card\\41.bmp","card\\42.bmp","card\\43.bmp","card\\44.bmp",
"card\\45.bmp","card\\46.bmp","card\\47.bmp","card\\48.bmp","card\\49.bmp",
"card\\50.bmp","card\\51.bmp","card\\52.bmp"};
char *ntostr(int n,char Str[])
{
int i=0,temp=n;
do
{
i++;
temp=temp/10;
}while(temp);
Str[i]='\0';
while(i--)
{
Str[i]=n%10+48;
n=n/10;
}
return Str;
}
void NewQues(int *a,int *b,int *c,int *d) /*出題函數(shù)*/
{
char out[3]="00";
srand(time(NULL));
*a=rand()%13+1;
*b=rand()%13+1;
*c=rand()%13+1;
*d=rand()%13+1;
DrawBMP(120,50,BMP0[*a-1]);
DrawBMP(220,50,BMP1[*b-1]);
DrawBMP(320,50,BMP2[*c-1]);
DrawBMP(420,50,BMP3[*d-1]);
setcolor(WHITE);
rectangle(120,165,490,200);
setfillstyle(1,BLUE);
bar(121,166,489,199);
bar(311,301,633,439);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setcolor(WHITE);
outtextxy(315,310," Make sure you have used the number");
outtextxy(315,325,"ABOVE, and the symbols of the formula");
outtextxy(315,340,"are NOT ILLEGAL. Some Questions may");
outtextxy(315,355,"have more than one answer, but you");
outtextxy(315,370,"just input ONE. For the Questions has");
outtextxy(315,385,"no answer, please input \'0\' instead.");
setcolor(LIGHTGREEN);
outtextxy(315,420,"Press ESC to quit the game. HAVE FUN!");
setfillstyle(1,BLUE);
bar(6,441,633,456);
setcolor(YELLOW);
outtextxy(155,445,"Use \'+ - * / \' and \'( )\' to calculate 24!");
setcolor(LIGHTGREEN);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(145,175,ntostr(*a,out));
outtextxy(245,175,ntostr(*b,out));
outtextxy(345,175,ntostr(*c,out));
outtextxy(445,175,ntostr(*d,out));
}
int Justify(int a,int b,int c,int d,char Form[]) /*輸入驗(yàn)證是否為題目數(shù)字*/
{
int i=0,j,temp=0,flag=0,key=0,count=0;
int Just[4];
Just[0]=a;
Just[1]=b;
Just[2]=c;
Just[3]=d;
do
{
if(Form[i]>='0'&&Form[i]<='9')
{
temp=temp*10+(Form[i]-48);
flag=1;
}
else if(flag)
{
flag=0;
for(j=0;j<4;j++)
{
if(temp==Just[j])
{
Just[j]=-1;
key++;
break;
}
}
count++;
temp=0;
}
}while(Form[i++]!='\0');
if(key==4&&count==4) return 1;
else return 0;
}
void Welcome(void) /*歡迎界面*/
{
setfillstyle(2,LIGHTBLUE);
bar(20,80,619,120);
setcolor(DARKGRAY);
settextstyle(0,HORIZ_DIR,6);
outtextxy(120,80,"Magic 24");
setcolor(WHITE);
outtextxy(115,77,"Magic 24");
setcolor(LIGHTGRAY);
settextstyle(0,HORIZ_DIR,1);
outtextxy(90,450,"Version: Beta 1.1 Copyright (C) 2007 by snow_by@tom.com");
DrawBMP(200,150,"card\\120.bmp");
do
{
FlashText();
}while(getch()!=13);
}
void Quit(void)
{
void *buf;
int size;
char ch;
size=imagesize(155,190,465,270);
buf=malloc(size);
getimage(155,190,465,270,buf);
setfillstyle(1,RED);
bar(155,190,465,270);
setlinestyle(0,0,1);
setcolor(YELLOW);
rectangle(160,193,460,267);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(168,230,"Are You Sure to Quit the Game?(Y/N)");
Flash(448,230,YELLOW,RED,1);
ch=getch();
if(ch=='y'||ch=='Y')
{
closegraph();
exit(0);
}
putimage(155,190,buf,COPY_PUT);
free(buf);
}
void Showup(void)
{
void *buf1,*buf2,*buf3,*buf4,*buf5;
unsigned size;
char ch;
int gdriver=VGA,gmode=VGAHI;
int i=0;
int a,b,c,d;
char *Ans[100];
size=imagesize(0,0,639,100);
buf1=malloc(size);
getimage(0,0,639,100,buf1);
size=imagesize(0,101,639,201);
buf2=malloc(size);
getimage(0,101,639,201,buf2);
size=imagesize(0,202,639,302);
buf3=malloc(size);
getimage(0,202,639,302,buf3);
size=imagesize(0,303,639,403);
buf4=malloc(size);
getimage(0,303,639,403,buf4);
size=imagesize(0,404,639,479);
buf5=malloc(size);
getimage(0,404,639,479,buf5);
closegraph();
printf("Please Input 4 Numbers:\n");
scanf("%d%d%d%d",&a,&b,&c,&d);
fflush(stdin);
Magic(a,b,c,d,Ans);
printf("\n");
while(Ans[i]!=NULL&&i<100)
{
printf("%s\n",Ans[i]);
i++;
}
printf("\n\nMagic24 Version: Beta 1.1 Copyright (C) 2007 by snow_by@tom.com\n");
printf("\nPress any key to return...");
getch();
initgraph(&gdriver,&gmode,"c:\\tc");
putimage(0,0,buf1,COPY_PUT);
putimage(0,101,buf2,COPY_PUT);
putimage(0,202,buf3,COPY_PUT);
putimage(0,303,buf4,COPY_PUT);
putimage(0,404,buf5,COPY_PUT);
free(buf1);
free(buf2);
free(buf3);
free(buf4);
free(buf5);
}
void DrawBK(void) /*畫背景*/
{
setfillstyle(1,BLUE);
bar(0,0,639,479);
setcolor(WHITE);
setlinestyle(0,1,NORM_WIDTH);
line(5,10,634,10);
line(5,12,634,12);
line(5,457,634,457);
line(5,10,5,457);
line(634,10,634,457);
line(5,300,634,300);
line(5,230,634,230);
line(5,440,634,440);
line(310,300,310,440);
setfillstyle(1,LIGHTGRAY);
bar(5,460,634,475);
setcolor(WHITE);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(90,465,"Version: Beta 1.1 Copyright (C) 2007 by snow_by@tom.com");
setfillstyle(1,BLUE);
bar(270,10,349,20);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(270,8," Question ");
setfillstyle(1,BLUE);
bar(255,220,359,240);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setcolor(WHITE);
outtextxy(260,226,"Answer Sheet");
setcolor(LIGHTGREEN);
outtextxy(50,265,"Your Anwser is:");
setcolor(CYAN);
outtextxy(70,320,"Question Num:");
outtextxy(70,350,"Right Count:");
outtextxy(70,380,"Wrong Count:");
outtextxy(70,410,"Tatal Score:");
}
void FlashText(void) /*歡迎界面中的閃爍文字*/
{
int timer;
settextstyle(0,HORIZ_DIR,2);
while(bioskey(1)==0)
{
setcolor(BLUE);
outtextxy(100,400,"Press ENTER to continue...");
setcolor(LIGHTBLUE);
outtextxy(96,398,"Press ENTER to continue...");
timer=clock();
while(((clock()-timer)<5));
setcolor(BLACK);
outtextxy(100,400,"Press ENTER to continue...");
outtextxy(96,398,"Press ENTER to continue...");
timer=clock();
while(((clock()-timer)<5));
}
}
void Flash(int x,int y,int color,int bkcolor,int size) /*輸入時(shí)的閃爍光標(biāo)*/
{
int timer;
settextstyle(DEFAULT_FONT,HORIZ_DIR,size);
while(bioskey(1)==0)
{
setcolor(color);
outtextxy(x,y,"_");
timer=clock();
while(((clock()-timer)<5)&&(bioskey(1)==0));
setcolor(bkcolor);
outtextxy(x,y,"_");
timer=clock();
while(((clock()-timer)<5)&&(bioskey(1)==0));
}
}
void GetText(int x,int y,char *Str) /*取得用戶輸入*/
{
int i=0;
char ch;
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
setcolor(WHITE);
Flash(x,y,WHITE,BLUE,2);
while((ch=getch())!=13)
{
if(ch==8)
{
if(i!=0)
{
x-=20;
setcolor(BLUE);
outtextxy(x,y,Str+i-1);
setcolor(WHITE);
Str[--i]='\0';
}
}
else if(((ch>='0'&&ch<='9')||ch=='('||ch==')'||ch=='+'||ch=='-'||ch=='*'||ch=='/')&&i<18)
{
Str[i]=ch;
Str[++i]='\0';
setcolor(WHITE);
outtextxy(x,y,Str+i-1);
x+=20;
}
else if(ch==27) Quit();
else if((ch=='|')&&(bioskey(2)&1)&&(bioskey(2)&2)) Showup();
Flash(x,y,WHITE,BLUE,2);
}
return;
}
int DrawBMP(int x,int y,char filename[]) /*繪圖函數(shù)*/
{
int i,j=0;
int width,height;
int bytenum;
unsigned char byte;
FILE *fp;
fp=fopen(filename,"rb");
if(fp==NULL)
{
return 0;
}
fseek(fp,18,SEEK_SET);
fread(&width,4,1,fp);
fread(&height,4,1,fp);
fseek(fp,118,SEEK_SET);
for(i=y+height-1;i>=y;i--)
{
bytenum=0;
for(j=x;j<width+x;j++)
{
fread(&byte,1,1,fp);
bytenum++;
putpixel(j,i,SetColor(byte>>4));
putpixel(++j,i,SetColor(byte&0x0f));
}
while(bytenum%4)
{
fseek(fp,1,SEEK_CUR);
bytenum++;
}
}
fclose(fp);
return 1;
}
int SetColor(int color) /*顏色值轉(zhuǎn)換*/
{
switch(color)
{
case 0:
return 0;
case 1:
return 4;
case 2:
return 2;
case 3:
return 6;
case 4:
return 1;
case 5:
return 5;
case 6:
return 3;
case 7:
return 8;
case 8:
return 7;
case 9:
return 12;
case 10:
return 10;
case 11:
return 14;
case 12:
return 9;
case 13:
return 13;
case 14:
return 11;
case 15:
return 15;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -