Don't crash when board size is changed.
[AROS-Contrib.git] / Games / madmatrix / madmatrix.c
blob0ad095540ff68e17a853bd26218d9beb399bee68
1 #include "madmatrix.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <math.h>
8 #include <time.h>
11 #ifdef __AROS__
12 #include <proto/muimaster.h>
13 #endif
15 #include <proto/utility.h>
17 #include <libraries/mui.h>
18 #undef SysBase
19 #undef GfxBase
20 #undef UtilityBase
21 #undef IntuitionBase
23 #include "alloctab.h"
25 #include <clib/alib_protos.h>
27 // Custom class MUI
29 #ifndef MAKE_ID
30 #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
31 #endif
33 #define PAS 0.12
34 #define MADMATRIX_ABS(x) ((x)>0?(x):-(x))
36 #define MADMATRIX_LIGNE(taille,nombre) (int)((nombre-1)/taille)
37 #define MADMATRIX_COLONNE(taille,nombre) (int)((nombre-1)%taille)
38 #define MADMATRIX_NOMBRE(taille,ligne,colonne) ( taille*ligne+colonne+1 )
39 #define MADMATRIX_VOISINS(taille,nb1, nb2) \
40 ((MADMATRIX_ABS(MADMATRIX_LIGNE(taille,nb1)-MADMATRIX_LIGNE(taille,nb2))+\
41 MADMATRIX_ABS(MADMATRIX_COLONNE(taille,nb1)-MADMATRIX_COLONNE(taille,nb2)) ) == 1?1:0)
43 #define MADMATRIX_YOUWIN "You win"
44 #define MADMATRIX_GOODLUCK "Good luck"
46 void Madmatrix_Rotate(struct IClass *cl,Object *obj, int sens, double pas);
47 void Madmatrix_Shake(struct IClass *cl,Object *obj, int nb);
48 void Madmatrix_Init(struct Madmatrix_Data *data);
49 void Madmatrix_Restart(struct IClass *cl,Object *obj);
50 void Madmatrix_Tourne(int **tableau,int ligne, int colonne, int sens );
51 int Madmatrix_Calcul(int **tableau, int taille);
54 IPTR Madmatrix_Dispose(struct IClass *cl,Object *obj,Msg msg);
55 IPTR Madmatrix_New(struct IClass *cl,Object *obj,Msg msg);
56 IPTR Madmatrix_AskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg);
57 IPTR Madmatrix_Draw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg);
58 IPTR Madmatrix_Setup(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg);
59 IPTR Madmatrix_Cleanup(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg);
60 IPTR Madmatrix_HandleInput(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg);
63 extern struct GfxBase *GfxBase;
64 extern struct IntuitionBase *IntuitionBase;
65 extern struct Library *MUIMasterBase;
69 #define _between(a,x,b) ((x)>=(a) && (x)<=(b))
70 #define _isinobject(x,y) (_between(_mleft(obj),(x),_mright (obj)) && _between(_mtop(obj) ,(y),_mbottom(obj)))
72 #define MADMATRIX_MAX(a,b) ((a)<(b)?(b):(a))
74 /// ULONG Madmatrix_New(struct IClass *cl,Object *obj,Msg msg)
75 IPTR Madmatrix_New(struct IClass *cl,Object *obj,Msg msg)
77 struct Madmatrix_Data *data;
78 /* struct TagItem *tags,*tag;*/
80 if (!(obj = (Object *)DoSuperMethodA(cl,obj,msg)))
81 return(0);
83 data = INST_DATA(cl,obj);
85 data->taille = MADMATRIX_TAILLE_MAX;
86 data->ntaille = MADMATRIX_TAILLE_MAX;
87 data->groupe = NULL;
89 data->matrice=(int **)AllocTab(sizeof(int),data->taille,data->taille);
91 Madmatrix_Init(data);
93 if ( data->matrice == NULL )
94 return(FALSE);
96 return((IPTR)obj);
98 ///
100 /// ULONG Madmatrix_Dispose(struct IClass *cl,Object *obj,Msg msg)
101 IPTR Madmatrix_Dispose(struct IClass *cl,Object *obj,Msg msg)
103 struct Madmatrix_Data *data = (struct Madmatrix_Data *)INST_DATA(cl,obj);
105 FreeTab((void **)data->matrice,data->taille);
107 return(DoSuperMethodA(cl,obj,msg));
111 /// ULONG Madmatrix_AskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
112 IPTR Madmatrix_AskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
114 struct Madmatrix_Data *data = INST_DATA(cl,obj);
115 int largeur;
117 data->font_sx = _font(obj)->tf_XSize;
118 data->font_sy = _font(obj)->tf_YSize;
120 /*printf("Ask %p %d %d\n",_font(obj),_font(obj)->tf_XSize,_font(obj)->tf_YSize);*/
122 DoSuperMethodA(cl,obj,(Msg)msg);
124 largeur = (3*data->taille*data->font_sx+1);
127 printf("%p\n",_rp(obj));
129 printf("Largeur1 = %d\n",largeur);
130 largeur = MADMATRIX_MAX(largeur,TextLength(_rp(obj),MADMATRIX_YOUWIN,strlen(MADMATRIX_YOUWIN)));
131 printf("Largeur2 = %d\n",largeur);
132 largeur = MADMATRIX_MAX(largeur,TextLength(_rp(obj),MADMATRIX_GOODLUCK,strlen(MADMATRIX_GOODLUCK)));
133 printf("Largeur3 = %d\n",largeur);
135 largeur = MADMATRIX_MAX(largeur,data->font_sx*strlen(MADMATRIX_YOUWIN));
136 largeur = MADMATRIX_MAX(largeur,data->font_sx*strlen(MADMATRIX_GOODLUCK));
138 msg->MinMaxInfo->MinWidth += largeur;
139 msg->MinMaxInfo->DefWidth += largeur;
140 msg->MinMaxInfo->MaxWidth += largeur;
142 msg->MinMaxInfo->MinHeight += (2*(data->taille+2)*data->font_sy); /**/
143 msg->MinMaxInfo->DefHeight += (2*(data->taille+2)*data->font_sy);
144 msg->MinMaxInfo->MaxHeight += (2*(data->taille+2)*data->font_sy);
147 return(0);
151 /// ULONG Madmatrix_Draw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
152 IPTR Madmatrix_Draw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
154 struct Madmatrix_Data *data = INST_DATA(cl,obj);
155 int ligne,colonne;
156 char temp[1000];
157 int tf_x=_rp(obj)->Font->tf_XSize;
158 int tf_y=_rp(obj)->Font->tf_YSize;
159 int offset_x, offset_y, x,y;
162 /* clear message zone */
164 SetAPen(_rp(obj),0);
165 RectFill(_rp(obj),_mleft(obj),_mtop(obj)+(2*tf_y)*(data->taille)+1,_mright(obj),_mbottom(obj));
167 if ( data->message )
169 SetAPen(_rp(obj),1);
170 x = _mleft(obj)+1;
171 y = _mtop(obj)+(2*tf_y)*(data->taille+1);
173 Move(_rp(obj),x,y);
174 Text(_rp(obj),data->message,strlen(data->message));
176 data->message=NULL;
179 if ( data->box == -1 )
181 data->box=0;
182 SetAPen(_rp(obj),0);
183 Move(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
184 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*(data->colonne+2),_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
185 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*(data->colonne+2),_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2);
186 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2);
187 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
188 return(TRUE);
191 if ( data->box == 1 )
193 data->box=0;
194 SetAPen(_rp(obj),1);
195 Move(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
196 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*(data->colonne+2),_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
197 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*(data->colonne+2),_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2);
198 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2);
199 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
200 return(TRUE);
204 DoSuperMethodA(cl,obj,(Msg)msg);
206 if (data->matrice == NULL)
208 return FALSE;
211 SetAPen(_rp(obj),0);
212 if ( data->mouvement == 0 )
213 RectFill(_rp(obj),_mleft(obj),_mtop(obj),_mright(obj),_mbottom(obj));
214 else
215 RectFill(_rp(obj),
216 _mleft(obj)+(3*tf_x)*data->colonne+1,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2+1,
217 _mleft(obj)+(3*tf_x)*(data->colonne+2)-1,_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2-1
221 SetAPen(_rp(obj),1);
224 offset_x = (3*tf_x)*data->pas;
225 offset_y = (2*tf_y)*data->pas;
227 switch ( data->mouvement )
229 case 1:
231 ligne = data->ligne; colonne = data->colonne;
232 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
233 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
235 Move(_rp(obj),x+offset_x,y); Text(_rp(obj),temp,strlen(temp));
237 colonne++;
238 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
239 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
241 Move(_rp(obj),x,y+offset_y); Text(_rp(obj),temp,strlen(temp));
243 ligne++;
244 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
245 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
247 Move(_rp(obj),x-offset_x,y); Text(_rp(obj),temp,strlen(temp));
249 colonne--;
250 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
251 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
253 Move(_rp(obj),x,y-offset_y); Text(_rp(obj),temp,strlen(temp));
255 break;
257 case -1:
259 ligne = data->ligne; colonne = data->colonne;
260 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
261 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
262 Move(_rp(obj),x,y+offset_y); Text(_rp(obj),temp,strlen(temp));
265 colonne++;
266 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
267 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
269 Move(_rp(obj),x-offset_x,y); Text(_rp(obj),temp,strlen(temp));
271 ligne++;
272 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
273 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
275 Move(_rp(obj),x,y-offset_y); Text(_rp(obj),temp,strlen(temp));
277 colonne--;
278 x = _mleft(obj)+(3*tf_x)*colonne; y = _mtop(obj)+(2*tf_y)*(ligne+1);
279 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
281 Move(_rp(obj),x+offset_x,y); Text(_rp(obj),temp,strlen(temp));
283 break;
285 default :
286 for ( ligne=0;ligne<data->taille; ligne++)
288 for ( colonne=0;colonne<data->taille; colonne++ )
290 x = _mleft(obj)+(3*tf_x)*colonne;
291 y = _mtop(obj)+(2*tf_y)*(ligne+1);
292 sprintf(temp,"%3d",data->matrice[ligne][colonne]);
294 Move(_rp(obj),x,y);
295 Text(_rp(obj),temp,strlen(temp));
299 break;
305 if ( ! data->shaking )
307 Move(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
308 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*(data->colonne+2),_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
309 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*(data->colonne+2),_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2);
310 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+2)+tf_x/2);
311 Draw(_rp(obj),_mleft(obj)+(3*tf_x)*data->colonne,_mtop(obj)+(2*tf_y)*(data->ligne+1)-3*tf_x/2);
315 return(TRUE);
320 /// ULONG Madmatrix_Setup(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg)
321 /* init data & allocate pens */
322 IPTR Madmatrix_Setup(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg)
324 if (!(DoSuperMethodA(cl,obj,(Msg)msg)))
325 return(FALSE);
327 MUI_RequestIDCMP(obj,IDCMP_RAWKEY);
329 srand(time(NULL));
331 return(TRUE);
336 /// ULONG Madmatrix_Set(struct IClass *cl,Object *obj,Msg msg)
337 IPTR Madmatrix_Set(struct IClass *cl,Object *obj,struct opSet *msg)
339 struct Madmatrix_Data *data = INST_DATA(cl,obj);
340 struct TagItem *tags,*tag;
342 for (tags=msg->ops_AttrList;(tag=NextTagItem(&tags));)
345 switch (tag->ti_Tag)
347 case MADMATRIX_TAILLE:
348 data->ntaille=tag->ti_Data;
349 break;
350 case MADMATRIX_GROUPE:
351 data->groupe=(Object *)tag->ti_Data;
352 break;
356 return(DoSuperMethodA(cl,obj,msg));
360 /// ULONG Madmatrix_Get(struct IClass *cl,Object *obj,Msg msg)
361 IPTR Madmatrix_Get(struct IClass *cl,Object *obj,struct opGet *msg)
363 struct Madmatrix_Data *data = INST_DATA(cl,obj);
364 IPTR *store = msg->opg_Storage;
366 switch (msg->opg_AttrID)
368 case MADMATRIX_TAILLE:
369 *store = data->taille;
370 return(TRUE);
373 return(DoSuperMethodA(cl,obj,msg));
377 /// ULONG Madmatrix_HandleInput(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg)
378 IPTR Madmatrix_HandleInput(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg)
380 struct Madmatrix_Data *data = INST_DATA(cl,obj);
382 if (msg->muikey!=MUIKEY_NONE)
384 switch (msg->muikey)
386 case MUIKEY_UP :
387 data->box=-1;
388 MUI_Redraw(obj,MADF_DRAWUPDATE);
389 if ( data->ligne>0 )
390 data->ligne--;
391 data->box=1;
392 MUI_Redraw(obj,MADF_DRAWUPDATE);
393 break;
395 case MUIKEY_DOWN :
396 data->box=-1;
397 MUI_Redraw(obj,MADF_DRAWUPDATE);
398 if ( data->ligne<data->taille-2 )
399 data->ligne++;
400 data->box=1;
401 MUI_Redraw(obj,MADF_DRAWUPDATE);
402 break;
404 case MUIKEY_RIGHT :
405 data->box=-1;
406 MUI_Redraw(obj,MADF_DRAWUPDATE);
407 if ( data->colonne<data->taille-2 )
408 data->colonne++;
409 data->box=1;
410 MUI_Redraw(obj,MADF_DRAWUPDATE);
411 break;
413 case MUIKEY_LEFT :
414 data->box=-1;
415 MUI_Redraw(obj,MADF_DRAWUPDATE);
416 if ( data->colonne>0 )
417 data->colonne--;
418 data->box=1;
419 MUI_Redraw(obj,MADF_DRAWUPDATE);
420 break;
422 case MUIKEY_PRESS :
423 Madmatrix_Rotate(cl,obj, -1,PAS);
424 /*MUI_Redraw(obj,MADF_DRAWUPDATE);*/
425 break;
426 case MUIKEY_TOGGLE :
427 Madmatrix_Rotate(cl,obj, 1, PAS);
428 /*MUI_Redraw(obj,MADF_DRAWUPDATE);*/
429 break;
433 if ( msg->imsg && msg->imsg->Class == IDCMP_RAWKEY )
435 if ( msg->imsg->Code == 24 ) /* 'o' key */
436 Madmatrix_Rotate(cl,obj, -1,PAS);
438 if ( msg->imsg->Code == 25 ) /* 'p' key */
439 Madmatrix_Rotate(cl,obj, 1,PAS);
441 return(DoSuperMethodA(cl,obj,(Msg)msg));
445 /// ULONG Madmatrix_Cleanup(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg)
446 IPTR Madmatrix_Cleanup(struct IClass *cl,Object *obj,struct MUIP_HandleInput *msg)
448 MUI_RejectIDCMP(obj,IDCMP_RAWKEY);
450 return(DoSuperMethodA(cl,obj,(Msg)msg));
454 /// ULONG __attribute__((regparm(3))) Madmatrix_Dispatcher(struct IClass *cl , void *msg,Object *obj )
456 #ifndef __AROS__
457 __asm ULONG Madmatrix_Dispatcher(register __a0 struct IClass *cl, register __a2 Object *obj, register __a1 Msg msg)
458 #else
459 BOOPSI_DISPATCHER(IPTR, Madmatrix_Dispatcher, cl, obj, msg)
460 #endif
462 struct Madmatrix_Data *data;
464 data = INST_DATA(cl,obj);
466 switch (msg->MethodID)
468 case OM_NEW : return(Madmatrix_New(cl,obj,(APTR)msg));
469 case OM_DISPOSE : return(Madmatrix_Dispose(cl,obj,(APTR)msg));
470 case OM_SET : return(Madmatrix_Set(cl,obj,(APTR)msg));
471 case OM_GET : return(Madmatrix_Get(cl,obj,(APTR)msg));
472 case MUIM_AskMinMax : return(Madmatrix_AskMinMax (cl,obj,(struct MUIP_AskMinMax *)msg));
473 case MUIM_Draw : return(Madmatrix_Draw (cl,obj,(struct MUIP_Draw *)msg));
474 case MUIM_HandleInput : return(Madmatrix_HandleInput(cl,obj,(struct MUIP_HandleInput *)msg));
475 case MUIM_Setup : return(Madmatrix_Setup (cl,obj,(struct MUIP_HandleInput *)msg));
476 case MUIM_Cleanup : return(Madmatrix_Cleanup (cl,obj,(struct MUIP_HandleInput *)msg));
477 case MADMATRIX_SHAKE : Madmatrix_Shake(cl,obj,data->taille*data->taille-data->taille+1); return(TRUE);
478 case MADMATRIX_RESTART : Madmatrix_Restart(cl,obj); return(TRUE);
483 return(DoSuperMethodA(cl,obj,(Msg)msg));
485 #ifdef __AROS__
486 BOOPSI_DISPATCHER_END
487 #endif
494 /// void Madmatrix_Rotate(struct IClass *cl,Object *obj, int sens, double pas)
495 /* init data & allocate pens */
496 void Madmatrix_Rotate(struct IClass *cl,Object *obj, int sens, double pas)
498 struct Madmatrix_Data *data = INST_DATA(cl,obj);
500 data->mouvement=sens;
501 for ( data->pas=0; data->pas <= 1; data->pas+=pas )
503 WaitTOF();
504 MUI_Redraw(obj,MADF_DRAWUPDATE);
507 Madmatrix_Tourne(data->matrice, data->ligne, data->colonne, sens);
508 if ( data->shaked )
509 if ( Madmatrix_Calcul(data->matrice,data->taille) == data->taille*data->taille )
510 data->message="You win !";
511 Madmatrix_Tourne(data->matrice, data->ligne, data->colonne, -sens);
513 data->pas=1;
514 MUI_Redraw(obj,MADF_DRAWUPDATE);
515 data->mouvement=0;
517 Madmatrix_Tourne(data->matrice, data->ligne, data->colonne, sens);
521 /// void Madmatrix_Shake(struct IClass *cl,Object *obj, int nb)
522 void Madmatrix_Shake(struct IClass *cl,Object *obj, int nb)
524 struct Madmatrix_Data *data = INST_DATA(cl,obj);
525 int cpt, sens=-1;
527 data->box = -1;
528 MUI_Redraw(obj,MADF_DRAWUPDATE);
530 data->shaking=1;
532 for ( cpt=0; cpt<nb; cpt++ )
534 data->ligne = rand()%(data->taille-1);
535 data->colonne = rand()%(data->taille-1);
536 sens=-sens;
538 Madmatrix_Rotate(cl,obj,sens,3*PAS);
541 data->shaking=0;
542 data->shaked=1;
543 data->ligne=0;
544 data->colonne=0;
546 data->box = 1;
547 data->message=MADMATRIX_GOODLUCK;
548 MUI_Redraw(obj,MADF_DRAWUPDATE);
553 /// void Madmatrix_Init(struct Madmatrix_Data *data)
554 void Madmatrix_Init(struct Madmatrix_Data *data)
556 int ligne, colonne,nb=1;
558 for ( ligne=0; ligne<data->taille; ligne++ )
559 for ( colonne=0; colonne<data->taille; colonne++ )
560 data->matrice[ligne][colonne]=nb++;
562 data->ligne = 0;
563 data->colonne = 0;
565 data->mouvement=0;
566 data->shaking=0;
571 /// void Madmatrix_Restart(struct IClass *cl,Object *obj)
572 void Madmatrix_Restart(struct IClass *cl,Object *obj)
574 struct Madmatrix_Data *data = INST_DATA(cl,obj);
577 if ( data->ntaille > MADMATRIX_TAILLE_MAX )
578 data->ntaille = MADMATRIX_TAILLE_MAX;
580 if ( data->ntaille < 3 )
581 data->ntaille=3;
583 if ( data->taille != data->ntaille )
585 if ( data->groupe )
587 if (DoMethod(data->groupe,MUIM_Group_InitChange))
589 FreeTab((void **)data->matrice,data->taille);
590 data->matrice = NULL;
592 DoMethod(data->groupe,OM_REMMEMBER,obj);
593 data->taille=data->ntaille;
594 DoMethod(data->groupe,OM_ADDMEMBER,obj);
596 DoMethod(data->groupe,MUIM_Group_ExitChange);
599 else
601 FreeTab((void **)data->matrice,data->taille);
602 data->matrice = NULL;
603 data->taille=data->ntaille;
607 data->matrice=(int **)AllocTab(sizeof(int),data->taille,data->taille);
610 Madmatrix_Init(data);
612 data->shaked = 0;
614 MUI_Redraw(obj,MADF_DRAWOBJECT);
619 /// void Madmatrix_Tourne(int **tableau,int ligne, int colonne, int sens )
620 void Madmatrix_Tourne(int **tableau,int ligne, int colonne, int sens )
622 int temp=tableau[ligne ][colonne ];
624 if ( sens>=0 )
626 tableau[ligne ][colonne ] = tableau[ligne+1 ][colonne ];
627 tableau[ligne+1 ][colonne ] = tableau[ligne+1 ][colonne+1 ];
628 tableau[ligne+1 ][colonne+1 ] = tableau[ligne ][colonne+1 ];
629 tableau[ligne ][colonne+1 ] = temp;
631 else
633 tableau[ligne ][colonne ] = tableau[ligne ][colonne+1 ];
634 tableau[ligne ][colonne+1 ] = tableau[ligne+1 ][colonne+1 ];
635 tableau[ligne+1 ][colonne+1 ] = tableau[ligne+1 ][colonne ];
636 tableau[ligne+1 ][colonne ] = temp;
644 /// int Madmatrix_Calcul(int **tableau, int taille)
645 int Madmatrix_Calcul(int **tableau, int taille)
647 int ligne, colonne;
648 int nb=0;
651 for ( ligne=0; ligne<taille; ligne++ )
652 for ( colonne=0; colonne<taille; colonne++ )
654 if ( tableau[ligne][colonne] == MADMATRIX_NOMBRE(taille,ligne,colonne) )
655 nb++;
658 return(nb);