c++辅导讲解、C++程序辅导、辅导C/C++程序
- 首页 >> C/C++编程#include <stdio.h>
#include <stdlib.h>
#include <libsx.h>
#include <string.h>
#include <time.h>
#include "data.h"
#include "callbacks.h"
int a=12,b=-1,m=0;
Widget w[1];
char nomsDeColor[][12]={"green","green","yellow","yellow","orange1","orange1","red","red","blue","blue","pink","pink"};
int c[12]={0,1,2,3,4,5,6,7,8,9,10,11};
char *pa[12];
/ oid init_display(int argc, char *argv[]){}
int yon(int i){
if(i==c[0])return 0;
if(i==c[1])return 0;
if(i==c[2])return 0;
if(i==c[3])return 0;
if(i==c[4])return 0;
if(i==c[5])return 0;
if(i==c[6])return 0;
if(i==c[7])return 0;
if(i==c[8])return 0;
if(i==c[9])return 0;
if(i==c[10])return 0;
if(i==c[11])return 0;
else
return 1;}
void change(){
pa[0]=nomsDeColor[0];
pa[1]=nomsDeColor[1];
pa[2]=nomsDeColor[2];
pa[3]=nomsDeColor[3];
pa[4]=nomsDeColor[4];
pa[5]=nomsDeColor[5];
pa[6]=nomsDeColor[6];
pa[7]=nomsDeColor[7];
pa[8]=nomsDeColor[8];
pa[9]=nomsDeColor[9];
pa[10]=nomsDeColor[10];
pa[11]=nomsDeColor[11];
char *x,*y;
int i,j,k;
srand(time(NULL) | 0x01);
for(i=0;i<=10;i++)
{j=rand()%11+0;
k=rand()%11+0;
x=pa[j];
y=pa[k];
pa[k]=x;
pa[j]=y;
}
}
void Redisplay(Widget w, int width, int height, void *data){
DrawFilledBox(10,10,100,200);
DrawFilledBox(120,10,100,200);
DrawFilledBox(230,10,100,200);
DrawFilledBox(340,10,100,200);
DrawFilledBox(450,10,100,200);
DrawFilledBox(560,10,100,200);
DrawFilledBox(10,220,100,200);
DrawFilledBox(120,220,100,200);
DrawFilledBox(230,220,100,200);
DrawFilledBox(340,220,100,200);
DrawFilledBox(450,220,100,200);
DrawFilledBox(560,220,100,200);
}
void func(Widget w,int which_button, int x, int y, void *data){
int i;
if(x>=10&&x<=110&&y>=10&&y<=210)i=0;
if(x>=120&&x<=220&&y>=10&&y<=210)i=1;
if(x>=230&&x<=330&&y>=10&&y<=210)i=2;
if(x>=340&&x<=440&&y>=10&&y<=210)i=3;
if(x>=450&&x<=550&&y>=10&&y<=210)i=4;
if(x>=560&&x<=660&&y>=10&&y<=210)i=5;
if(x>=10&&x<=110&&y>=220&&y<=420)i=6;
if(x>=120&&x<=220&&y>=220&&y<=420)i=7;
if(x>=230&&x<=330&&y>=220&&y<=420)i=8;
if(x>=340&&x<=440&&y>=220&&y<=420)i=9;
if(x>=450&&x<=550&&y>=220&&y<=420)i=10;
if(x>=560&&x<=660&&y>=220&&y<=420)i=11;
if(yon(i)==0)
{
if(m==0)
{a=i;
m++;
SetFgColor(w,GetNamedColor(pa[i]));
DrawFilledBox((a<=5)?(a*110+10):((a-6)*110+10),(a)<=(5)?(10):(220),100,200);}
else
{ b=i;
if(a==b)b=-1;
else
{ SetFgColor(w,GetNamedColor(pa[i]));
DrawFilledBox((b<=5)?(b*110+10):((b-6)*110+10),(b)<=(5)?(10):(220),100,200);
if(strcmp(pa[a],pa[b])!=0){
SetFgColor(w, GetNamedColor("black"));
sleep(1);
DrawFilledBox((a<=5)?(a*110+10):((a-6)*110+10),(a)<=(5)?(10):(220),100,200);
DrawFilledBox((b<=5)?(b*110+10):((b-6)*110+10),(b)<=(5)?(10):(220),100,200);
m=0;
a=12;
b=-1;}
else
{c[a]=12;
c[b]=12;
a=12;
b=-1;
m=0;
}}}}
}
int main(int argc,char **argv){
if (OpenDisplay(argc, argv) == 0) {
fprintf(stderr,"Can't open display\n");
return EXIT_FAILURE;
}
change();
w[0]=MakeDrawArea(670,430,Redisplay,NULL);
SetButtonDownCB(w[0],func);
ShowDisplay();
GetStandardColors();
// init_display(argc, argv);
MainLoop();
return EXIT_SUCCESS;
}