1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tic-Tac-Toe Game in C

Discussion in 'C' started by pradeep, Dec 12, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Tic-Tac-Toe Game in C.

    Code:
    /*
    **    Tic-Tac-Toe game in C
    **    @author: Tanaz Kerawala
    **    @author: Pradeep
    **    @date: 11/12/06
    */
    
    #include<conio.h>
    #include<dos.h>
    #include<stdio.h>
    
    /*
    **    Creates the playing box
    */
    void box()
    {
        clrscr();
        textcolor(78);
        gotoxy(25,9);
        cprintf("  TIC    TAC    TOE ");
        textcolor(10);
        gotoxy(25,10);
        cprintf("ÉÍÍÍÍÍÍËÍÍÍÍÍÍËÍÍÍÍÍÍ»");
        gotoxy(25,11);
        cprintf("º      º      º      º");
        gotoxy(25,12);
        cprintf("º      º      º      º");
        gotoxy(25,13);
        cprintf("ÌÍÍÍÍÍÍÎÍÍÍÍÍÍÎÍÍÍÍÍ͹");
        gotoxy(25,14);
        cprintf("º      º      º      º");
        gotoxy(25,15);
        cprintf("º      º      º      º");
        gotoxy(25,16);
        cprintf("ÌÍÍÍÍÍÍÎÍÍÍÍÍÍÎÍÍÍÍÍ͹");
        gotoxy(25,17);
        cprintf("º      º      º      º");
        gotoxy(25,18);
        cprintf("º      º      º      º");
        gotoxy(25,19);
        cprintf("ÈÍÍÍÍÍÍÊÍÍÍÍÍÍÊÍÍÍÍÍͼ");
        gotoxy(28,12);
    }
    
    /*
    **    Handles the cursor and keys
    */
    void cursor()
    {
        char ch=' ';
        int x=28;
        int y=12;
        int a[2];
        char t[3][3];
        char z='o';
        char s;
        int j,k;
        gotoxy(25,3);
        printf("turn of player 'x'");
        gotoxy(x,y);
        for(j=0;j<3;j++)
        {
            for(k=0;k<3;k++)
            {
                t[j][k]=' ';
            }
        }
        while(ch!='q')
        {
            ch=getch();
            if(ch==0)
            {
                ch=getch();
            }
            gotoxy(x,y);
            a[0]=x;
            a[1]=y;
            switch(ch)
            {
                case'H':
                    if(y>12)
                    {
                        y=y-3;
                    }
                    gotoxy(a[0],a[1]-3);
                    break;
                case'P':
                    if(y<18)
                    {
                        y=y+3;
                    }
                    gotoxy(a[0],a[1]+3);
                    break;
                case'K':
                    if(x>28)
                    {
                        x=x-7;
                    }
                    gotoxy(a[0]-7,a[1]);
                    break;
                case'M':
                    if(x<42)
                    {
                        x=x+7;
                    }
                    gotoxy(a[0]+7,a[1]);
                    break;
                case'x':
                    if(z!='x')
                    {
                    z=ch;
                    if(a[0]==28&&a[1]==12)
                    {
                        if(t[0][0]==' ')
                        {
                            printf("x");
                            t[0][0]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[0][0]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                        ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==28&&a[1]==15)
                    {
                        if(t[1][0]==' ')
                        {
                            printf("x");
                            t[1][0]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[0][1]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                        ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==28&&a[1]==18)
                    {
                        if(t[2][0]==' ')
                        {
                            printf("x");
                            t[2][0]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[0][2]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                        ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==35&&a[1]==12)
                    {
                        if(t[0][1]==' ')
                        {
                            printf("x");
                            t[0][1]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[1][0]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                      ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==35&&a[1]==15)
                    {
                        if(t[1][1]==' ')
                        {
                            printf("x");
                            t[1][1]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[1][1]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                         ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==35&&a[1]==18)
                    {
                        if(t[2][1]==' ')
                        {
                            printf("x");
                            t[2][1]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[1][2]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                 ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==42&&a[1]==12)
                    {
                        if(t[0][2]==' ')
                        {
                            printf("x");
                            t[0][2]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[2][0]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                        ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==42&&a[1]==15)
                    {
                        if(t[1][2]==' ')
                        {
                            printf("x");
                            t[1][2]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[2][1]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                 ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==42&&a[1]==18)
                    {
                        if(t[2][2]==' ')
                        {
                            printf("x");
                            t[2][2]='x';
                            gotoxy(25,3);
                            printf("turn of player 'o'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[2][2]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'x'                         ");
                            z='o';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    if(t[0][0]=='x')
                    {
                        if(t[0][1]=='x')
                        {
                            if(t[0][2]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[0][0]=='x')
                    {
                        if(t[1][0]=='x')
                        {
                            if(t[2][0]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[0][0]=='x')
                    {
                        if(t[1][1]=='x')
                        {
                            if(t[2][2]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[0][2]=='x')
                    {
                        if(t[1][2]=='x')
                        {
                            if(t[2][2]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][2]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[2][0]=='x')
                    {
                        if(t[2][1]=='x')
                        {
                            if(t[2][2]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf(" %c  is  the  winner",t[2][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[0][2]=='x')
                    {
                        if(t[1][1]=='x')
                        {
                            if(t[2][0]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][2]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[0][1]=='x')
                    {
                        if(t[1][1]=='x')
                        {
                            if(t[2][1]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][1]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    if(t[1][0]=='x')
                    {
                        if(t[1][1]=='x')
                        {
                            if(t[1][2]=='x')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[1][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    box();
                                    z='o';
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                }
                                else
                                {
                                    ch='q';
                                }
                            }
                        }
                    }
                    }
                    else
                    {
                        gotoxy(25,3);
                        printf("this move is not allowed turn of player 'o'");
                        sound(500);
                        delay(1000);
                        nosound();
                        getch();
                        gotoxy(25,3);
                        printf("                                            ");
                        z='x';
                        gotoxy(25,3);
                        printf("turn of player 'o'");
                        gotoxy(a[0],a[1]);
                    }
                    if(t[0][0]!=' ')
                    {
                        if(t[0][1]!=' ')
                        {
                            if(t[0][2]!=' ')
                            {
                                if(t[1][0]!=' ')
                                {
                                    if(t[1][1]!=' ')
                                    {
                                        if(t[1][2]!=' ')
                                        {
                                            if(t[2][0]!=' ')
                                            {
                                                if(t[2][1]!=' ')
                                                {
                                                    if(t[2][2]!=' ')
                                                    {
                                                        sound(1000);
                                                        delay(1500);
                                                        nosound();
                                                        gotoxy(25,3);
                                                        printf("game over");
                                                        gotoxy(25,4);
                                                        printf("to start new game click G");
                                                        gotoxy(25,5);
                                                        printf("or click Q to exit");
                                                        scanf("%c",&s);
                                                        if(s!='q')
                                                        {
                                                            for(j=0;j<3;j++)
                                                            {
                                                                for(k=0;k<3;k++)
                                                                {
                                                                    t[j][k]=' ';
                                                                }
                                                            }
                                                            box();
                                                            z='o';
                                                            gotoxy(25,3);
                                                            printf("turn of player 'x'");
                                                        }
                                                        else
                                                        {
                                                            ch='q';
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                break;
                case 'o':
                    if(z!='o')
                    {
                    z=ch;
                    if(a[0]==28&&a[1]==12)
                    {
                        if(t[0][0]==' ')
                        {
                            printf("o");
                            t[0][0]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[0][0]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                         ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==35&&a[1]==12)
                    {
                        if(t[0][1]==' ')
                        {
                            printf("o");
                            t[0][1]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[0][1]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                 ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==42&&a[1]==12)
                    {
                        if(t[0][2]==' ')
                        {
                            printf("o");
                            t[0][2]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[0][2]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                        ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==28&&a[1]==15)
                    {
                        if(t[1][0]==' ')
                        {
                            printf("o");
                            t[1][0]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[1][0]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                          ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==35&&a[1]==15)
                    {
                        if(t[1][1]==' ')
                        {
                            printf("o");
                            t[1][1]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[1][1]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                       ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==42&&a[1]==15)
                    {
                        if(t[1][2]==' ')
                        {
                            printf("o");
                            t[1][2]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[1][2]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                         ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==28&&a[1]==18)
                    {
                        if(t[2][0]==' ')
                        {
                            printf("o");
                            t[2][0]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[2][0]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                         ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==35&&a[1]==18)
                    {
                        if(t[2][1]==' ')
                        {
                            printf("o");
                            t[2][1]='o';
                            gotoxy(25,3);
                            printf("trun of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[2][1]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                 ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    else if(a[0]==42&&a[1]==18)
                    {
                        if(t[2][2]==' ')
    
                        {
                            printf("o");
                            t[2][2]='o';
                            gotoxy(25,3);
                            printf("turn of player 'x'");
                            gotoxy(a[0],a[1]);
                        }
                        else
                        {
                            gotoxy(25,3);
                            printf("this move is not allowed at t[2][2]");
                            sound(700);
                            delay(1000);
                            nosound();
                            getch();
                            gotoxy(25,3);
                            printf("turn of player 'o'                        ");
                            z='x';
                            gotoxy(a[0],a[1]);
                        }
                    }
                    if(t[0][0]=='o')
                    {
                        if(t[0][1]=='o')
                        {
                            if(t[0][2]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[0][0]=='o')
                    {
                        if(t[1][0]=='o')
                        {
                            if(t[2][0]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[0][0]=='o')
                    {
                        if(t[1][1]=='o')
                        {
                            if(t[2][2]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[0][2]=='o')
                    {
                        if(t[1][2]=='o')
                        {
                            if(t[2][2]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][2]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[2][0]=='o')
                    {
                        if(t[2][1]=='o')
                        {
                            if(t[2][2]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[2][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[0][2]=='o')
                    {
                        if(t[1][1]=='o')
                        {
                            if(t[2][0]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][2]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[0][1]=='o')
                    {
                        if(t[1][1]=='o')
                        {
                            if(t[2][1]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[0][1]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    if(t[1][0]=='o')
                    {
                        if(t[1][1]=='o')
                        {
                            if(t[1][2]=='o')
                            {
                                sound(1000);
                                delay(1500);
                                nosound();
                                gotoxy(25,3);
                                printf("  %c  is  the  winner",t[1][0]);
                                gotoxy(25,4);
                                printf("press any key to start new game");
                                gotoxy(25,5);
                                printf("or click Q to exit");
                                scanf("%c",&s);
                                if(s!='q')
                                {
                                    for(j=0;j<3;j++)
                                    {
                                        for(k=0;k<3;k++)
                                        {
                                            t[j][k]=' ';
                                        }
                                    }
                                    z='o';
                                    box();
                                    gotoxy(25,3);
                                    printf("turn of player 'x'");
                                    gotoxy(x,y);
                                 }
                                 else
                                 {
                                    ch='q';
                                 }
                            }
                        }
                    }
                    }
                    else
                    {
                        gotoxy(25,3);
                        printf("this move is not allowed turn of player 'x'");
                        sound(500);
                        delay(1000);
                        nosound();
                        getch();
                        gotoxy(25,3);
                        printf("                                            ");
                        z='o';
                        gotoxy(25,3);
                        printf("turn of player 'x'");
                        gotoxy(a[0],a[1]);
                    }
                    if(t[0][0]!=' ')
                    {
                        if(t[0][1]!=' ')
                        {
                            if(t[0][2]!=' ')
                            {
                                if(t[1][0]!=' ')
                                {
                                    if(t[1][1]!=' ')
                                    {
                                        if(t[1][2]!=' ')
                                        {
                                            if(t[2][0]!=' ')
                                            {
                                                if(t[2][1]!=' ')
                                                {
                                                    if(t[2][2]!=' ')
                                                    {
                                                        sound(1000);
                                                        delay(1500);
                                                        nosound();
                                                        gotoxy(25,3);
                                                        printf("game over");
                                                        gotoxy(25,4);
                                                        printf("press any key to start new game");
                                                        gotoxy(25,5);
                                                        printf("or click Q to exit");
                                                        scanf("%c",&s);
                                                        if(s!='q')
                                                        {
                                                            for(j=0;j<3;j++)
                                                            {
                                                                for(k=0;k<3;k++)
                                                                {
                                                                    t[j][k]=' ';
                                                                }
                                                            }
                                                            z='o';
                                                            box();
                                                            gotoxy(25,3);
                                                            printf("turn of player 'x'");
                                                            gotoxy(x,y);
                                                        }
                                                        else
                                                        {
                                                            ch='q';
    
                                                        }
    
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
    
                    break;
                case 't':
                    gotoxy(3,3);
                    for(j=0;j<3;j++)
                    {
                        for(k=0;k<3;k++)
                        {
                            printf("t[%d][%d]=%c\n",j,k,t[j][k]);
                        }
                    }
                    break;
                default:
                    if(ch!='q')
                    {
                        gotoxy(25,3);
                        printf("press proper keys");
                        gotoxy(a[0],a[1]);
                        sound(700);
                        delay(1000);
                        nosound();
                        getch();
                    }
                    else
                    {
                        gotoxy(25,3);
                        printf("press any key to quit");
                        sound(1000);
                        delay(1000);
                        nosound();
                        getch();
                    }
                    break;
            }
        }
    }
    
    void main()
    {
        clrscr();
        box();
        cursor();
    }
     
  2. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    Still living in DOS era?
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
  4. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    Great keep it up.
    Thanks for share
     

Share This Page