1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| WindowJeu initialisationfenetre()
{
/* Déclaration Variable */
WindowJeu pWindow;
int i,j, compteurblanc,compteurnoir,compteurinitblanc,compteurinitnoire;
compteurblanc =0;
compteurnoir =32;
piece pieceBlanche[16];
compteurinitblanc = 0;
piece pieceNoire[16];
compteurinitnoire = 0;
gtk_window_set_title(GTK_WINDOW(pWindow.pWindow),"Jeu");
gtk_window_set_default_size(GTK_WINDOW(pWindow.pWindow),500,500);
g_signal_connect(G_OBJECT(pWindow.pWindow),"destroy",G_CALLBACK(gtk_main_quit),0);
gtk_container_add(GTK_CONTAINER(pWindow.pWindow), GTK_WIDGET(pWindow.pTable));
for(i =0; i<16;i++)
{
pWindow.pLabel[i]=gtk_label_new(NULL);
}
pWindow.pTable=gtk_table_new(9,9,FALSE);
for(i=0; i<32;i++)
{
pWindow.pImage[i] = gtk_image_new_from_file("./blanc.png");
}
for(i=32; i<64;i++)
{
pWindow.pImage[i] = gtk_image_new_from_file("./noir.png");
}
for(i =0 ; i<64; i++)
{
pWindow.pButton[i] = gtk_button_new ();
pWindow.pBox[i] = gtk_hbox_new (FALSE, 2);
gtk_container_add (GTK_CONTAINER (pWindow.pButton[i]), pWindow.pBox[i]);
gtk_box_pack_start (GTK_BOX (pWindow.pBox[i]), pWindow.pImage[i], TRUE, TRUE, 0);
}
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>1</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[0]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>2</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[1]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>3</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[2]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>4</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[3]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>5</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[4]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>6</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[5]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>7</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[6]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>8</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[7]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>8</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[7]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>A</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[8]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>B</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[9]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>C</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[10]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>D</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[11]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>E</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[12]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>F</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[13]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>G</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[14]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
pWindow.sUtf8 = g_locale_to_utf8("<span face=\"Sans\" size=\"16\"><u>H</u></span>",-1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pWindow.pLabel[15]), pWindow.sUtf8);
g_free(pWindow.sUtf8);
for(i=0; i<8;i++)
{
gtk_table_attach(GTK_TABLE(pWindow.pTable), pWindow.pLabel[i],
0, 1, i, i+1,
GTK_EXPAND , GTK_EXPAND,
0, 0);
}
for(i=0; i<8;i++)
{
gtk_table_attach(GTK_TABLE(pWindow.pTable), pWindow.pLabel[i+8],
i+1, i+2, 8, 9,
GTK_EXPAND, GTK_EXPAND,
0, 0);
}
for(i=0; i<8;i++)
{
for(j=0; j<8;j++)
{
if((j+i)%2==0)
{
gtk_table_attach_defaults(GTK_TABLE(pWindow.pTable), pWindow.pButton[compteurblanc],i+1, i+2, j, j+1);
compteurblanc ++;
printf("\n%d",compteurblanc);
if(j<2 && i<8)
{
gtk_image_set_from_file(GTK_IMAGE(pWindow.pImage[compteurblanc-1]), "./pionNb.png");
pieceNoire[compteurinitnoire].positionX = i;
pieceNoire[compteurinitnoire].positionY = j;
printf("Pièce Noire (%d : %d )\n",pieceNoire[compteurinitnoire].positionX,pieceNoire[compteurinitnoire].positionY);
compteurinitnoire++;
}
if(((j>=6) && (j<=8) &&(i<8)))
{
gtk_image_set_from_file(GTK_IMAGE(pWindow.pImage[compteurblanc-1]), "./pionBb.png");
pieceBlanche[compteurinitblanc].positionX = i;
pieceBlanche[compteurinitblanc].positionY = j;
printf("Pièce blanche (%d : %d )\n",pieceBlanche[compteurinitblanc].positionX,pieceBlanche[compteurinitblanc].positionY);
compteurinitblanc++;
}
}
else
{
gtk_table_attach_defaults(GTK_TABLE(pWindow.pTable), pWindow.pButton[compteurnoir],i+1, i+2, j, j+1);
compteurnoir ++;
printf("\n%d",compteurnoir);
if(j<2 && i<8)
{
gtk_image_set_from_file(GTK_IMAGE(pWindow.pImage[compteurnoir-1]), "./pionNn.png");
pieceNoire[compteurinitnoire].positionX = i;
pieceNoire[compteurinitnoire].positionY = j;
printf("Pièce Noire (%d : %d )\n",pieceNoire[compteurinitnoire].positionX,pieceNoire[compteurinitnoire].positionY);
compteurinitnoire++;
}
if(((j>=6) && (j<=8) &&(i<8)))
{
gtk_image_set_from_file(GTK_IMAGE(pWindow.pImage[compteurnoir-1]), "./pionBn.png");
pieceBlanche[compteurinitblanc].positionX = i;
pieceBlanche[compteurinitblanc].positionY = j;
printf("Pièce blanche (%d : %d )\n",pieceBlanche[compteurinitblanc].positionX,pieceBlanche[compteurinitblanc].positionY);
compteurinitblanc++;
}
}
}
printf("\nDone\n");
}
} |
Partager