Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int matrix[3][3];
- bool playerTurn;
- void playing();
- int checkwinpc();
- int checkwinplayer();
- int computer();
- int tie();
- int checkposition();
- int XO,playerone, playertwo, pcpick,final, playerchoice;
- void playing(int matrix[3][3]){
- int cont, a, b;
- // Limpiara la pantalla
- system("CLS");
- cont=1;
- printf("nnnnttt t³t t³ntt");
- //La t y las n centran mis textos
- for(a=0; a<3; a++){
- if(a!=0){
- printf("t t³t t³ntt"); // Posicionará mis lineas verticales en un orden mas descente
- }
- for(b=0; b<3; b++){
- if ( matrix[a][b]==0){
- if(b!=2){
- printf("t%it³",cont );
- }
- else{
- printf("t%it",cont );
- }
- }
- else{
- if (matrix[a][b]==1){
- if(b!=2){
- printf("tXt³");
- }
- else{
- printf("tXt");
- }
- }
- else{
- if(b!=2){
- printf("tOt³");
- }
- else{
- printf("tOt");
- }
- }
- }
- cont++;
- }
- printf("nttt t³t t³ntt");
- if(a!=2){
- printf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄntt"); // Imprimira mis 2 líneas horizontalez
- }
- }
- }
- int main(){
- srand(time(0));
- int playAgain;
- int yourscore= 0;
- int pcscore= 0;
- int tie= 0;
- int mode =0;
- cout<<"Contra quién deseas jugar?"<<endl;
- cout<<"1-PvPn 2-PvPc" <<endl;
- cin>>mode;
- if (mode=1){
- system("CLS");
- playing();
- int vocal, number, XO, cont,final;
- vocal = 1;
- playing(matrix);
- if (vocal==1)
- printf("nTurno: X");
- else
- printf("nTurno: O");
- int checkposition();
- int checkplayer();
- if(final==1){
- playing(matrix);
- // Llama a mi función con condiciones para selecionar un ganador.
- printf("nnGanador: ");
- if(vocal==2){
- XO=8;
- printf("X");
- getch();
- }
- else{
- XO=8;
- printf("O");
- getch();
- }
- }
- }
- else if (mode=2){
- do{
- system("CLS");
- int turnFirst = rand()% (2 - 1 + 1)+1;
- pcpick=rand()% (9 - 1 + 1)+1;
- playing();
- if (turnFirst==1){
- while (!(cin >>playerone))
- {
- cout << endl;
- cout << "Numbers only" << endl;
- cin.clear(); cin.ignore(10000,'n');
- }
- checkposition();
- system("CLS");
- playing();
- playerTurn = false;
- }
- if (turnFirst==2){
- pcpick;
- pcpick=pcpick;
- checkposition();
- cout<<"Turn pc"<<endl;
- playing();
- }
- if (playerTurn==true){
- cout<<"Set your position to place X"<<endl;
- while (!(cin >> playerchoice)) //error
- {
- cout << "Numbers only." << endl; cin.clear(); cin.ignore(10000,'n');
- }
- checkposition();
- checkwinplayer();
- int tie();
- playerTurn=false;
- }
- if(playerTurn == false) {
- computer();
- system("CLS");
- playing();
- checkwinpc();
- int tie();
- playerTurn = true;
- }
- }
- while (final>2);
- if (final==0);
- cout<<"tien";
- ++tie;
- if (final==1){
- cout<<"You winn";
- ++yourscore;
- }
- if(final==2){
- cout<<"PC winsn";
- ++pcscore;
- }
- cout<<"Total score";
- cout<<"You :"<<yourscore<<"Pc :"<<pcscore<<"Tie :"<<tie<<endl;
- cout<<"Want to play again?n1-Yesn2-No"<<endl;
- while(!(cin>>playAgain)){
- cout << endl;
- cout << "Play again?n1-Yesn2-No" << endl;
- cin.clear(); cin.ignore(10000,'n');
- }
- }
- while(playAgain == 1);
- return 0;
- }
- int checkwinpc(){
- if(XO>3){
- if((matrix[0][0]+matrix[0][1]+matrix[0][2]!=0)&&(matrix[0][0]==matrix[0][1])&&(matrix[0][1]==matrix[0][2])){
- final=2;
- }
- else{
- if((matrix[1][0]+matrix[1][1]+matrix[1][2]!=0)&&(matrix[1][0]==matrix[1][1])&&(matrix[1][1]==matrix[1][2])){
- final=2;
- }
- else{
- if((matrix[2][0]+matrix[2][1]+matrix[2]!=0)&&(matrix[2][0]==matrix[2][1])&&(matrix[2][1]==matrix[2][2])){
- final=2;
- }
- else{
- if((matrix[0][0]+matrix[1][0]+matrix[2][0]!=0)&&(matrix[0][0]==matrix[1][0])&&(matrix[1][0]==matrix[2][0])){
- final=2;
- }
- else{
- if((matrix[0][1]+matrix[1][1]+matrix[2][1]!=0)&&(matrix[0][1]==matrix[1][1])&&(matrix[1][1]==matrix[2][1])){
- final=2;
- }
- else{
- if((matrix[0][2]+matrix[1][2]+matrix[2][2]!=0)&&(matrix[0][2]== matrix[1][2])&&(matrix[1][2]==matrix[2][2])){
- final=2;
- }
- else{
- if((matrix[0][0]+matrix[1][1]+matrix[2][2]!=0)&&(matrix[0][0]==matrix[1][1])&&(matrix[1][1]==matrix[2][2])){
- final=2;
- }
- else{
- if((matrix[2][0]+matrix[1][1]+matrix[0][2]!=0)&&(matrix[2][0]==matrix[1][1])&&(matrix[1][1]==matrix[0][2])){
- final=2;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- int checkwinplayer(){
- if(XO>3){
- if((matrix[0][0]+matrix[0][1]+matrix[0][2]!=0)&&(matrix[0][0]==matrix[0][1])&&(matrix[0][1]==matrix[0][2])){
- final=1;
- }
- else{
- if((matrix[1][0]+matrix[1][1]+matrix[1][2]!=0)&&(matrix[1][0]==matrix[1][1])&&(matrix[1][1]==matrix[1][2])){
- final=1;
- }
- else{
- if((matrix[2][0]+matrix[2][1]+matrix[2]!=0)&&(matrix[2][0]==matrix[2][1])&&(matrix[2][1]==matrix[2][2])){
- final=1;
- }
- else{
- if((matrix[0][0]+matrix[1][0]+matrix[2][0]!=0)&&(matrix[0][0]==matrix[1][0])&&(matrix[1][0]==matrix[2][0])){
- final=1;
- }
- else{
- if((matrix[0][1]+matrix[1][1]+matrix[2][1]!=0)&&(matrix[0][1]==matrix[1][1])&&(matrix[1][1]==matrix[2][1])){
- final=1;
- }
- else{
- if((matrix[0][2]+matrix[1][2]+matrix[2][2]!=0)&&(matrix[0][2]== matrix[1][2])&&(matrix[1][2]==matrix[2][2])){
- final=1;
- }
- else{
- if((matrix[0][0]+matrix[1][1]+matrix[2][2]!=0)&&(matrix[0][0]==matrix[1][1])&&(matrix[1][1]==matrix[2][2])){
- final=1;
- }
- else{
- if((matrix[2][0]+matrix[1][1]+matrix[0][2]!=0)&&(matrix[2][0]==matrix[1][1])&&(matrix[1][1]==matrix[0][2])){
- final=1;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- int tie(){
- for (int a= 0; a<9;a++){
- for (int b=0;b<9;b++){
- for(int num=0;num<9;num++){
- if (matrix[a][b]!=num){
- printf("Empate");
- }
- }
- }
- final= 0;
- }
- }
- int checkposition(){
- int matrix[3][3] = {};
- int vocal, number, XO;
- vocal = 1;
- for(XO=0;XO<9;XO++){
- switch(number){
- case 1 :
- if(matrix[0][0]==0){
- matrix[0][0]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill it'"); // Si digita una casillla previamente ocupada
- XO=XO--;
- getch();
- }
- break;
- case 2 :
- if(matrix[0][1]==0){
- matrix[0][1]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill it '");
- XO=XO--;
- getch();
- }
- break;
- case 3 :
- if(matrix[0][2]==0){
- matrix[0][2]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill it");
- XO=XO--;
- getch();
- }
- break;
- case 4 :
- if(matrix[1][0]==0){
- matrix[1][0]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can´t fill it ");
- XO=XO--;
- getch();
- }
- break;
- case 5 :
- if(matrix[1][1]==0){
- matrix[1][1]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can´t fill this square");
- XO=XO--;
- getch();
- }
- break;
- case 6 :
- if(matrix[1][2]==0){
- matrix[1][2]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill this square");
- XO=XO--;
- getch();
- }
- break;
- case 7 :
- if(matrix[2][0]==0){
- matrix[2][0]= vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill this square'");
- XO=XO--;
- getch();
- }
- break;
- case 8 :
- if(matrix[2][1]==0){
- matrix[2][1]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill it");
- XO=XO--;
- getch();
- }
- break;
- case 9 :
- if(matrix[2][2]==0){
- matrix[2][2]=vocal;
- if(vocal==1){
- vocal=2;
- }
- else{
- vocal=1;
- }
- }
- else{
- printf("We can't fill this square'");
- XO=XO--;
- getch();
- }
- break;
- default:
- printf("This is not a available square");
- XO=XO--;
- getch();
- break;
- // Cuando elige una casilla inexistente
- }
- }
- }
Add Comment
Please, Sign In to add comment