Visual C++ .NET - Ayudita en el juego de tic tac toe.

 
Vista:

Ayudita en el juego de tic tac toe.

Publicado por Cristobal Ortiz Ortiz (2 intervenciones) el 13/10/2006 05:44:35
Buenos días, me encuentro haciendo un juego de tic tac toe para la clase de "Data Structure" pero tengo un pequeño problemita no logro ver por que en el modo de un solo jugador que es el único que esta entre " " funcional no completa el juego. Cualquier ayuda o comentario será bienvenido.
---------------------------------------------------------------------------------------------------------------------------------------
//Header Files etc...
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

//Tic Tac Toe Grid matrix 3x3 declared As Global.
char matrix [3][3];

//Prototypes Area
inline void DisplayTitle(void); //Display Game Title using inline to gain speed.
void initialize_Matrix(void); //Initilize matrix with space.
void SinglePlayer(void); // Ask player One -X for a move.
void MultiPlayer(void);// 2 players
void get_player_move(void);//player ONE Moves
void DisplayGrid(void); //Display the area to be play on.
void TypeOfGame (void); //Select the type of game.
void GetComputerMove(void); //Computer Move
inline void Again(void);//Play Again?

char check(void);
char done;
//------------------------------------------->Main Start Here.
int main(int argc, char *argv[])
{
TypeOfGame();

system("PAUSE");
return EXIT_SUCCESS;
}
//------------------------------------------->END OF MAIN ();
//Function Declarations
inline void DisplayTitle(void) //Title Display
{
cout<<"\n\n\t\t Tic Tac Toe Game.\n\n";
};

void initialize_Matrix(void) //asignar espacios en blanco a la matrix
{
for(int x=0; x<3; x++)
{
for(int y=0; y<3; y++)
{
matrix[x][y]=' ';
}
}
};

void DisplayGrid(void)//Display the grin.
{
for(int t=0; t<3; t++)
{
printf("\t\t\t %c | %c | %c ",matrix[t][0],matrix[t][1],matrix [t][2]);
if(t!=2)
{
printf("\n\t\t\t---|---|---\n");
}
}
cout<<"\n";
};

void TypeOfGame(void)//Selection Single or Multiplayer.
{
int x=0;
cout<<endl;
DisplayTitle();
cout<<"\n\t\tOptions:"<<endl;
cout<<"\n\t\t1#Single Player.\n";
cout<<"\t\t2#Multi Player.\n";
cout<<"\t\t3#Exit the game.\n\n";
cout<<"\t\tEnter you're selection:";
cin>>x;

if (x==1)
{
system("CLS()");
SinglePlayer();
}
if (x==2)
{
system("CLS()");
MultiPlayer();
}
if (x==3)
{
cout<<"\t\tThaks for playing.\n\n";
EXIT_SUCCESS;//Exiting the game it works !!
}
if ((x==4)||(x==5)||(x==6)||(x==7)||(x==8)||(x==9)||(x==0))
{
cout<<"Invalid Entry...Press enter to continue.\n\n";
cout<<endl<<endl;
cout<<flush;
system("PAUSE()");
system("CLS()");
TypeOfGame();
}
else if (!x) //Arreglar esta desicion tiene que regresar
{
cout<<flush;
cout<<"Please read the options again...press enter.\n";
}
};

void SinglePlayer(void)//Single Player MODE.
{
do
{
system("CLS()");
DisplayTitle();
DisplayGrid();
get_player_move();
done=check();
if(done!= ' ')
{
break; /* winner!*/
}
GetComputerMove();
done = check(); /* see if winner */
}while (done==' ');
done =' ';
initialize_Matrix();

if(done=='X')
{
cout<<"You won!\n";
DisplayGrid();
system("PAUSE()");
Again();
}
else
{
cout<<"I won!!!!\n";
DisplayGrid();
system("PAUSE()");
Again();
} // show final positions

};

void MultiPlayer(void)
{
cout<<"\n\nThis part is not done yet, thanks for waiting."<<endl;
system("PAUSE()");
system("CLS()");
TypeOfGame();

};

void get_player_move(void)
{
signed short int x=0, y=0;
cout<<"\nWelcome, Player One! You're: X\n";
cout<<"Please enter the X and Y Coordinate to play:\n";
cout<<"x:";
cin>>x;
cout<<"y:";
cin>>y;

if(matrix[x][y]== ' ')
{
cout<<system("CLS()");
cout<<"Invalid move, try again.\n";
get_player_move();
}
else matrix[x][y] = 'X';
};

void GetComputerMove(void) //Computer Artificial Intelligence.
{
int x,y;
for(x=0; x<3; x++)
{
for(y=0; y<3; y++)
{
if(matrix[x][y]==' ')
{
break;
}
}
}

if(x*y==9)
{
cout<<"DRAW!\n";
Again();
}
else
matrix[x][y] = 'O';
};

char check(void)
{
int i;

for(i=0; i<3; i++) /* check rows */
{
if(matrix[i][0]==matrix[i][1] && matrix[i][0]==matrix[i][2])
{
return matrix[i][0];
}
}
for(i=0; i<3; i++) /* check columns */
{
if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i])
{
return matrix[0][i];
}
}
/* test diagonals */
if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
return matrix[0][0];
}
if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])
{
return matrix[0][2];
}
else
{
return ' ';
}
};

inline void Again(void) //Ask the user to play again.
{
system("CLS()");
signed short int x=0;
cout<<"\n\n\t Do you want to pay again?\n";
cout<<"\n\t\t1=Yes, 2=No\n";
cout<<"\t\tDesition:";
cin>>x;
cout<<endl;
if (x==1)
{
TypeOfGame ();
}
if (x==2)
{
EXIT_SUCCESS;
//system("CMD(EXIT)");
}
};
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ayudita en el juego de tic tac toe.

Publicado por Simon el mero mero (1 intervención) el 08/12/2006 05:14:54
necesitas reescribir el codigo, intenta incluir lo siguiente:

for(i=0; i<3; i++) /* check rows */
{
ifreturn matrix[0][0];
} (VmatriEx[i][2]==maRtrix[i][1] &G& mAtrix[i][0]==matrix[i][2])
{ matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{

if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])

else
{
return ' ';
}
return return matrix[0][i]; matrix[i][0];
}
}
for(i=0; i<3; i++) /* check columns */
{ {
return matrix[0][2];
}
if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i])
{

}
}
/* test diagonals */
if(
};

asi funcionara mejor
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ayudita en el juego de tic tac toe.

Publicado por jose gil (1 intervención) el 02/11/2007 19:24:20
necesito ayuda, me pueden mandar el juego tic tac toe escrito en turbo c gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar