Título: Ayuda con codigo de juego del gato C++ Publicado por: carlangasds en 6 Noviembre 2014, 04:04 am No se porque me marca que ganaste si las operaciones no se prestan para eso.
Citar #include <iostream> #include <stdio.h> #include <windows.h> #include <conio.h> using namespace std; int i,c,v=3,h=14,h2=24,v2=8,v3=14,h3=7,o,s,g1,g2,u; int ganador; int px1=1,px2=2,px3=3,px4=4,px5=5,px6=6,px7=7,px8=8,px9=9; int po1=1,po2=2,po3=3,po4=4,po5=4,po6=6,po7=7,po8=9,po9=9; int gx1,gx2,gx3,gx4,gx5; int go1,go2,go3,go4; void gotoxy(int x,int y) { HANDLE hcon; hcon = GetStdHandle(STD_OUTPUT_HANDLE); COORD dwPos; dwPos.X = x; dwPos.Y= y; SetConsoleCursorPosition(hcon,dwPos); } void pintar_equis() { if (o==1) { gotoxy (9,4); cout << "x x"; gotoxy (9,5); cout << " x "; gotoxy (9,6); cout << "x x"; } if (o==2) { gotoxy (18,4); cout << "x x"; gotoxy (18,5); cout << " x "; gotoxy (18,6); cout << "x x"; } if (o==3) { gotoxy (27,4); cout << "x x"; gotoxy (27,5); cout << " x "; gotoxy (27,6); cout << "x x"; } if (o==4) { gotoxy (9,10); cout << "x x"; gotoxy (9,11); cout << " x "; gotoxy (9,12); cout << "x x"; } if (o==5) { gotoxy (18,10); cout << "x x"; gotoxy (18,11); cout << " x "; gotoxy (18,12); cout << "x x"; } if (o==6) { gotoxy (27,10); cout << "x x"; gotoxy (27,11); cout << " x "; gotoxy (27,12); cout << "x x"; } if (o==7) { gotoxy (9,16); cout << "x x"; gotoxy (9,17); cout << " x "; gotoxy (9,18); cout << "x x"; } if (o==8) { gotoxy (18,16); cout << "x x"; gotoxy (18,17); cout << " x "; gotoxy (18,18); cout << "x x"; } if (o==9) { gotoxy (27,16); cout << "x x"; gotoxy (27,17); cout << " x "; gotoxy (27,18); cout << "x x"; } } void pintar_circulo() { if (o==1) { gotoxy (9,4); cout << " x "; gotoxy (9,5); cout << "x x"; gotoxy (9,6); cout << " x "; } if (o==2) { gotoxy (18,4); cout << " x "; gotoxy (18,5); cout << "x x"; gotoxy (18,6); cout << " x "; } if (o==3) { gotoxy (27,4); cout << " x "; gotoxy (27,5); cout << "x x"; gotoxy (27,6); cout << " x "; } if (o==4) { gotoxy (9,10); cout << " x "; gotoxy (9,11); cout << "x x"; gotoxy (9,12); cout << " x "; } if (o==5) { gotoxy (18,10); cout << " x "; gotoxy (18,11); cout << "x x"; gotoxy (18,12); cout << " x "; } if (o==6) { gotoxy (27,10); cout << " x "; gotoxy (27,11); cout << "x x"; gotoxy (27,12); cout << " x "; } if (o==7) { gotoxy (9,16); cout << " x "; gotoxy (9,17); cout << "x x"; gotoxy (9,18); cout << " x "; } if (o==8) { gotoxy (18,16); cout << " x "; gotoxy (18,17); cout << "x x"; gotoxy (18,18); cout << " x "; } if (o==9) { gotoxy (27,16); cout << " x "; gotoxy (27,17); cout << "x x"; gotoxy (27,18); cout << " x "; } } void pintar_tablero() { for (i=0;i<=16;i++) { gotoxy (h,v+i); cout << "| \n"; } for (c=0;c<=16;c++) { gotoxy (h2,v+c); cout << "| \n"; } for (i=0;i<=24;i++) { gotoxy (h3+i,v2); cout << "- \n"; } for (c=0;c<=24;c++) { gotoxy (h3+c,v3); cout << "- \n"; } } void ganarx() { if ((px1+px2+px3)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px4+px5+px6)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px7+px8+px9)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px1+px4+px7)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px2+px5+px8)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px3+px6+px9)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px1+px5+px9)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((px3+px5+px7)==(gx1+gx2+gx3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } } void ganaro() { if ((po1+po2+po3)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po4+po5+po6)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po7+po8+po9)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po1+po4+po7)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po2+po5+po8)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po3+po6+po9)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po1+po5+po9)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } if ((po3+po5+po7)==(go1+go2+go3)) { gotoxy (0,26); cout << "ĦĦHaz Ganado!!"; i=9; getch(); } } void jugar() { for (i=1;i<=9;i++) { if((i==1)||(i==3)||(i==5)||(i==7)||(i==9)) { gotoxy (0,24); cout << "'Turno de X' Selecciona la casilla: "; cin >> o; pintar_equis(); if (i==1) { gx1=o; } if (i==3) { gx2=o; } if (i==5) { gx3=o; ganarx(); } if (i==7) { gx4=o; ganarx(); } if (i==9) { gx5=o; ganarx(); } } if((i==2)||(i==4)||(i==6)||(i==8)) { gotoxy (0,24); cout << "'Turno de O' Selecciona la casilla: "; cin >> o; pintar_circulo(); if (i==2) { go1=o; } if (i==4) { go2=o; } if (i==6) { go3=o; ganaro(); } if (i==8) { go4=o; ganaro(); } } } } int main(int argc, char** argv) { pintar_tablero(); jugar(); return 0; } |