Jeux de mémoire, sans pointeurs!

Contenu du snippet

J'ai débuté ce projet il y a 4 mois, et je viens de le terminer! Il ne contient pas de pointeurs, mais un systeme de structures....

Source / Exemple :


/* memo v.1.2     06-02-16/17/18/20 jouable
todo:
-menus et options!

  • /
#include <iostream> #include <conio.h> // getch() #include <algorithm> // random_shuffle() using namespace std; //1,2,3,4,5,6,11,12,13,14,15,16,17 char poss_char[17] ={1,2,3,4,5,6,112,113,1,2,3,4,5,6,112,113}; // double copy int flag_cart[16] ={0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}; // the showit or not part. int pp[17] ={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; // poss_positions..mixed up bool end =false; bool sound =false; struct Grid{ char coox; // a,b,c,d char cooy; // 1,2,3,4 int value; // une de poss_char[] bool flag; // On l'affiche ou pas } g[16]; // 16 copies of the structure. Donc... a1=112 class Game{ private: char x1, x2, y1, y2; // get_coord(), user's guess. int temp_1, temp_2; // search_values()/valid_values() int mempos; // search_values()/valid_values() public: void mix_positions(){ // mix position array before attributing. random_shuffle(pp, pp+16); } void attrib_coord(){ // 16 attributions 'structs'...coordonnées seulement. char tmp_cart[5] ={'a','b','c','d'}; int count1_4 =0; char rowcount ='1'; for(int z=0; z!=16; z++){ g[z].coox =tmp_cart[count1_4]; // ++ quand rowcount==5 g[z].cooy =rowcount; g[z].flag =false; // par défaut ++rowcount; if (rowcount=='5') {rowcount ='1'; ++count1_4;} } } void attrib_values(){ // attribution des valeurs. for (int zz=0; zz!=16 ;zz++){ g[pp[zz]].value =poss_char[zz]; if (flag_cart[zz]==1) g[pp[zz]].flag =true; else g[pp[zz]].flag =false; } } char chk1(int x){ // tri pour grille pleine. return (char)g[x].value; } char chk2(int x){ // tri pour moitié de grille. if (g[x].flag==false) return (char)g[x].value; else return 0; } void show_full_grid(){ cout <<"4 "<<chk1(3)<<chk1(7)<<chk1(11)<<chk1(15)<<endl; cout <<"3 "<<chk1(2)<<chk1(6)<<chk1(10)<<chk1(14)<<endl; cout <<"2 "<<chk1(1)<<chk1(5)<<chk1(9)<<chk1(13)<<endl; cout <<"1 "<<chk1(0)<<chk1(4)<<chk1(8)<<chk1(12)<<endl; cout <<" abcd" <<endl; cout <<endl; } void show_half_grid(){ cout <<"4 "<<chk2(3)<<chk2(7)<<chk2(11)<<chk2(15)<<endl; cout <<"3 "<<chk2(2)<<chk2(6)<<chk2(10)<<chk2(14)<<endl; cout <<"2 "<<chk2(1)<<chk2(5)<<chk2(9)<<chk2(13)<<endl; cout <<"1 "<<chk2(0)<<chk2(4)<<chk2(8)<<chk2(12)<<endl; cout <<" abcd" <<endl; cout <<endl; } void valid_values(int a, int b){ // moment décisif! if (a==b) { cout <<"Bonnes"; getch(); g[mempos].flag =false; } else { cout <<"Mauvaises"; getch(); } } void search_values(char n1, char n2, char n3, char n4){ for (int z=0; z!=16; z++){ // "Moteur" de recherche. if (g[z].coox==n1 && g[z].cooy==n2) temp_1 =g[z].value; if (g[z].coox==n3 && g[z].cooy==n4) {temp_2 =g[z].value; mempos =z;} } } void get_coord(){ // une meilleure facon??? cout <<"Coords= "; x1 =getch(); cout <<x1; y1 =getch(); cout <<y1; cout <<", "; x2 =getch(); cout <<x2; y2 =getch(); cout <<y2; search_values(x1, y1, x2, y2); valid_values(temp_1, temp_2); } void chkend(){ int flagcount =0; for(int z =0; z!=16; z++){ if (g[z].flag ==true) ++flagcount; } if (flagcount ==0) { cout <<endl <<"BRAVO!" <<endl; getch(); system("CLS"); end =true; } } }; class Runnage{ public: void runme(){ Game try_1; try_1.attrib_coord(); while(true){ system("CLS"); try_1.mix_positions(); try_1.attrib_values(); try_1.show_full_grid(); cout <<"Appuyer sur une touche lorsque vous êtes prêt(e)..."; getch(); while(!end){ system("CLS"); try_1.show_half_grid(); try_1.get_coord(); try_1.chkend(); } } } }; int main(){ Runnage test; test.runme(); }

Conclusion :


Rem: J'ai WinXP et Dev-c++(4.9.9.2) a++

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.