bueno pues no tengo mucho que empeze a usar el turbo c++ y quisiera saber si ay alguna funcion para hacer mas corto el juego del gato contra la computadora
tambien soy nuevo en el foro y esto es lo que yevo
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int g;
char r[100];
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | "<<endl;
cout<<" | | | | "<<endl;
cin>>r[0];
if(r[0]=='1' || r[0]=='2' || r[0]=='3' || r[0]=='4' || r[0]=='5' || r[0]=='6' || r[0]=='7' || r[0]=='8' || r[0]==9)
{//ciclo del gato
if(r[0]=='1')
{//if del 1-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[1];
if(r[1]=='2')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | O"<<endl;
cout<<" | | | | "<<endl;
cin>>r[2];
if(r[2]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | | O "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | O "<<endl;
cout<<" | | | | "<<endl;
cout<<"gane ^^ "<<endl;
}
if(r[2]=='5')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | O "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | O "<<endl;
cout<<" | | | | "<<endl;
cout<<"gane "<<endl;
}
if(r[2]=='7')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | O"<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[2]=='8')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | O "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[2]=='6')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[3];
if(r[3]=='5')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[3]=='8')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[3]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | X | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
}
}
if(r[1]=='3')
{//if del 1-3
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[2];
if(r[2]=='8')
{//if del 1-3-7
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | X | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[3];
if(r[3]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
}
if(r[3]=='7')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 O | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
if(r[4]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | O | O "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | X | O "<<endl;
cout<<" | | | | "<<endl;
}
}
if(r[3]=='6')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 O | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
}
if(r[4]=='7')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
if(r[4]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
if(r[4]=='8')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 O | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
}
}
}
}
if(r[2]=='6')
{//if del 1-3-7
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[3];
if(r[3]=='5')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[3]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" Gane "<<endl;
}
if(r[3]=='8')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
}
}
if(r[2]=='7')
{//if del 1-3-7
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[3];
if(r[3]=='4')
{//1-3-7-4
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | | O "<<endl;
cout<<" | | | | "<<endl;
cout<<"Felicidades ganaste "<<endl;
}//1-3-7-4
if(r[3]=='8')
{//1-3-7-8
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 O | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<"empate "<<endl;
}//1-3-7-8
if(r[3]=='6')
{//1-3-7-6
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 O | O | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | | O "<<endl;
cout<<" | | | | "<<endl;
cout<<"empate "<<endl;
}//1-3-7-6
}//if del 1-3-7
if(r[2]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[4];
if(r[4]=='5')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | X | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[4]=='8')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | O | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
}
if(r[4]=='6')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<"gane "<<endl;
}
}//if 1-3-4
if(r[2]=='5')
{//if del 1-3-7
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[4];
if(r[4]=='6')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[4]=='4')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | X | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | O | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" gane "<<endl;
}
if(r[4]=='8')
{
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | O | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | O "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | X | O "<<endl;
cout<<" | | | | "<<endl;
cout<<" empate "<<endl;
}
}
}//if del 1-3
if(r[1]=='4')
{//if del 1-4
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 X | | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | O "<<endl;
cout<<" | | | | "<<endl;
cin>>r[1];
}//if del 1-4
} //if del 1-1
if(r[0]=='2')
{ //if del 2-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | X | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | "<<endl;
cout<<" | | | | "<<endl;
} //if del 2-1
if(r[0]=='3')
{//if del 3-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | | X "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | O "<<endl;
cout<<" | | | | "<<endl;
} //if del 3-1
if(r[0]=='4')
{//if del 4-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 X | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | "<<endl;
cout<<" | | | | "<<endl;
}//if del 4-1
if(r[0]=='5')
{//if del 5-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | X | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | "<<endl;
cout<<" | | | | "<<endl;
}//if del 5-1
if(r[0]=='6')
{//if del 6-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | X "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 O | | "<<endl;
cout<<" | | | | "<<endl;
}//if del 6-1
if(r[0]=='7')
{//if del 7-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 | | O "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 X | | "<<endl;
cout<<" | | | | "<<endl;
}//if del 7-1
if(r[0]=='8')
{//if del 8-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 O | | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | X | "<<endl;
cout<<" | | | | "<<endl;
}//if del 8-1
if (r[0]=='9')
{//if del 9-1
clrscr();cout<<" teclas juego "<<endl;cout<<" "<<endl;
cout<<" | | | | "<<endl;
cout<<" 1 | 2 | 3 O | | "<<endl;
cout<<"___|___|___ ___|___|___"<<endl;
cout<<" | | | | "<<endl;
cout<<" 4 | 5 | 6 | | "<<endl;
cout<<"___|___|___ ___|___|___ "<<endl;
cout<<" | | | | "<<endl;
cout<<" 7 | 8 | 9 | | X "<<endl;
cout<<" | | | | "<<endl;
}//if del 9-1
}//ciclo del gato
else
{
cout<<"porfavor vuelva a iniciar "<<endl;
}
getch();
}
eso es lo que yevo y si siguo asi me saldra muy largo asi que por eso pido su ayuda
Pon el code en geshi ;)
PD se ve muy feo
Primero, debido a algunos errores típicos vistos en el código, te diría que leas este hilo: Lo que no hay que hacer en C/C++ (http://foro.elhacker.net/programacion_cc/lo_que_no_hay_que_hacer_en_cc_nivel_basico-t277729.0.html)
En cuanto a la idea del algoritmo, te recomendaría que empieces con un buen libro de C/C++ para interiorizarte respecto de las herramientas que tienes disponibles en el lenguaje, ya que visto el acercamiento que intentas utilizar, esta claro que no estas aprovechando el potencial de C. Tenes un hilo en las chinchetas con varios para descarga.
Como ultima instancia, podes encontrar varios códigos tanto en Google como en el foro para que puedas analizarlos. Tic tac toe, ta te ti etc. son los nombres por los cuales podrás encontrarlos.
Saludos
Aqui tengo un code mas pequeño por si te interesa ;D
#include <stdio.h>
int main ()
{
int jugador(1),error,empate(0),ganar(0);
char c1('1'),c2('2'),c3('3'),c4('4'),c5('5'),c6('6'),c7('7'),c8('8'),c9('9'),tiro,marca,respuesta('y');
do{ //Crea El Ciclo
error=1;
printf("\n %c | %c | %c\n",c1,c2,c3); //Imprime el Tablero
printf("---+---+---\n");
printf("\n %c | %c | %c\n",c4,c5,c6);
printf("---+---+---\n");
printf("\n %c | %c | %c\n\n",c7,c8,c9);
if(jugador==1) //Establece la marca del jugador
{marca='X';}
else
{marca='O';}
printf("En que Casilla Deseas Tirar Jugador %d:\n",jugador);
fflush(stdin);
scanf("%c",&tiro);
if (tiro=='1' && c1=='1') {c1=marca;} //Checa las Condiciones para poder tirar
else if (tiro=='2' && c2=='2') {c2=marca;}
else if (tiro=='3' && c3=='3') {c3=marca;}
else if (tiro=='4' && c4=='4') {c4=marca;}
else if (tiro=='5' && c5=='5') {c5=marca;}
else if (tiro=='6' && c6=='6') {c6=marca;}
else if (tiro=='7' && c7=='7') {c7=marca;}
else if (tiro=='8' && c8=='8') {c8=marca;}
else if (tiro=='9' && c9=='9') {c9=marca;}
else {printf("Error! Movimiento No Valido\n"); error=2;}
//Checa Si alguien gano
if(c1=='X'||c1=='O')
{
if(c2==c1&&c3==c1)
{ganar=1;}
if(c4==c1&&c7==c1)
{ganar=1;}
}
if(c5=='X'||c5=='O')
{
if (c1 == c5 && c9 == c5)
{ganar=1;}
if (c2 == c5 && c8 == c5)
{ganar=1;}
if (c4 == c5 && c6 == c5)
{ganar=1;}
if (c3 == c5 && c7 == c5)
{ganar=1;}
}
if(c9=='X'||c9=='O')
{
if (c6 == c9 && c3 == c9)
{ganar=1;}
if (c7 == c9 && c8 == c9)
{ganar=1;}
}
if (c1 != '1' && c2 != '2' && c3 != '3' &&
c4 != '4' && c5 != '5' && c6 != '6' &&
c7 != '7' && c8 != '8' && c9 != '9')
{empate=1;}
if (ganar==1||empate==1)
{
if (ganar==1)
{
printf("Jugador: %d Gana!\n\n",jugador);
printf("\n %c | %c | %c\n",c1,c2,c3);
printf("---+---+---\n");
printf("\n %c | %c | %c\n",c4,c5,c6);
printf("---+---+---\n");
printf("\n %c | %c | %c\n\n",c7,c8,c9);
}
if (empate==1)
{
printf("Shit Nadie Gano!\n",jugador);
printf("\n %c | %c | %c\n",c1,c2,c3);
printf("---+---+---\n");
printf("\n %c | %c | %c\n",c4,c5,c6);
printf("---+---+---\n");
printf("\n %c | %c | %c\n\n",c7,c8,c9);
}
printf("Deseas Jugar de Nuevo: Y/N ?\n");
fflush(stdin);
scanf("%c",&respuesta);
if (respuesta=='y'||respuesta=='Y')
{
empate=0;
jugador=2;
ganar=0;
c1='1';
c2='2';
c3='3';
c4='4';
c5='5';
c6='6';
c7='7';
c8='8';
c9='9';
}
}
if(error==1) //Si Hay un error jugador no cambia
{
if (jugador==1)
{jugador=2;}
else
{jugador=1;}
}
}while(respuesta=='y'||respuesta=='Y');
}