Jump to content

[C++] Tic Toe Game (X si 0)


Cdorsu
 Share

Recommended Posts

Este pentru samp ?

off: stii ce e tic toe? adica X si 0...nu tot ce e pe forumul asta e pt sa:mp...

 

on: gj..dar poti pune si codul sursa sa fim suguri ca e facut de tine? si nu copiat?

Link to comment
Share on other sites

on: gj..dar poti pune si codul sursa sa fim suguri ca e facut de tine? si nu copiat?

#include <windows.h>
#include <stdio.h>
typedef char string [256];
int p=1,i,j,mutare,m,variabila;
string nume1, nume2, verificare,tabel[]={"Tic Toe Game (1P)","Tic Toe Game (2P)","Updates","Exit"};
char v[9]={'1','2','3','4','5','6','7','8','9'};
int tabel1()
{
    int pointer=0,p=1;
    inc:
    v[0]='1';v[1]='2';v[2]='3';v[3]='4';v[4]='5';v[5]='6';v[6]='7';v[7]='8';v[8]='9';m=0;
    printf("Care este numele primului jucator?");
    scanf("%s",nume1);
    sus:
    while(true)
    {
        SUUUUS:
        system("CLS");
        if(pointer==0)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[0]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\n",v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==1)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|",v[0]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[1]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\n",v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==2)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|",v[0],v[1]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[2]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\n",v[3],v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==3)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n",v[0],v[1],v[2]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[3]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c|%c\n-+-+-\n%c|%c|%c\n",v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==4)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|",v[0],v[1],v[2],v[3]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[4]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c\n-+-+-\n%c|%c|%c\n",v[5],v[6],v[7],v[8]);
        }
        else if(pointer==5)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|",v[0],v[1],v[2],v[3],v[4]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[5]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("\n-+-+-\n%c|%c|%c\n",v[6],v[7],v[8]);
        }
        else if(pointer==6)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n",v[0],v[1],v[2],v[3],v[4],v[5]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[6]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c|%c\n",v[7],v[8]);
        }
        else if(pointer==7)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|",v[0],v[1],v[2],v[3],v[4],v[5],v[6]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[7]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c\n",v[8]);
        }
        else if(pointer==8)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c\n",v[8]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
        }
        else if(pointer>8)
            pointer=8;
        else if(pointer<0)
            pointer=0;
        if(p%2==0)
        {
                if(m>=1)
                printf("\nAcum joaca %s.\nS-a facut un total de %d mutari.\n",nume1,m);
                else printf("\nAcum joaca %s\nS-a facut un total de %d mutari.\n!ATENTIE, TREBUIE SA AVETI CEL PUTIN O MUTARE FACUTA PENTRU A SE VALIDA.",nume1,m);
        }
        else printf("\nAcum joaca calculatorul.\nS-a facut un total de %d mutari.",m);
        if(p%2!=0 && m!=0)
        {
            total:
            variabila=rand()%9;
            switch(variabila)
            {
                case 0: {
                    if(v[0]=='1')
                    {
                        v[0]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[0]!='1') goto total;
                } break;
                case 1: {
                    if(v[1]=='2')
                    {
                        v[1]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[1]!='2') goto total;
                } break;
                case 2: {
                    if(v[2]=='3')
                    {
                        v[2]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[2]!='3') goto total;
                } break;
                case 3: {
                    if(v[3]=='4')
                    {
                        v[3]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[3]!='4') goto total;
                } break;
                case 4: {
                    if(v[4]=='5')
                    {
                        v[4]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[4]!='5') goto total;
                } break;
                case 5: {
                    if(v[5]=='6')
                    {
                        v[5]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[5]!='6') goto total;
                } break;
                case 6: {
                    if(v[6]=='7')
                    {
                        v[6]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[6]!='7') goto total;
                } break;
                case 7: {
                    if(v[7]=='8')
                    {
                        v[7]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[7]!='8') goto total;
                } break;
                case 8: {
                    if(v[8]=='9')
                    {
                        v[8]='O';
                        p+=1; Sleep(500);
                        goto SUUUUS;
                    }
                    if(v[8]!='9') goto total;
                } break;
            }
        }
        while(true)
        {
            if(GetAsyncKeyState(VK_UP)!=0)
            {
                pointer-=3;
                if(pointer<0)
                    pointer=0;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_DOWN)!=0)
            {
                pointer+=3;
                if(pointer>8)
                    pointer=8;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_RIGHT)!=0)
            {
                pointer+=1;
                if(pointer>8)
                    pointer=8;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_LEFT)!=0)
            {
                pointer-=1;
                if(pointer<0)
                    pointer=0;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_RETURN)!=0)
            {
                switch(pointer)
                {
                    case 0: {
                        if(p%2==0 && v[0]=='1' && m>0)
                            v[0]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 1: {
                        if(p%2==0 && v[1]=='2')
                            v[1]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 2: {
                        if(p%2==0 && v[2]=='3')
                            v[2]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 3: {
                        if(p%2==0 && v[3]=='4')
                            v[3]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 4: {
                        if(p%2==0 && v[4]=='5')
                            v[4]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 5: {
                        if(p%2==0 && v[5]=='6')
                            v[5]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 6: {
                        if(p%2==0 && v[6]=='7')
                            v[6]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 7: {
                        if(p%2==0 && v[7]=='8')
                            v[7]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 8: {
                        if(p%2==0 && v[8]=='9')
                            v[8]='X';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    default: {
                        printf("Casuta pe care ai ales-o nu este corecta.");
                        goto sus;
                    } break;
                }
            }
        if((v[0]=='X' && v[1]==v[0] && v[1]==v[2])or
        (v[3]=='X' && v[4]==v[5] && v[5]==v[3])or
        (v[6]=='X' && v[7]==v[8] && v[8]==v[6])or
        (v[0]=='X' && v[4]==v[8] && v[8]==v[0])or
        (v[2]=='X' && v[4]==v[6] && v[6]==v[2])or
        (v[0]=='X' && v[3]==v[6] && v[7]==v[0])or
        (v[1]=='X' && v[4]==v[7] && v[7]==v[1])or
        (v[2]=='X' && v[5]==v[8] && v[8]==v[2])or
        (v[0]=='X' && v[0]==v[3] && v[3]==v[6]))
        {
            system("CLS");
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\nJucatorul %s a castigat. Felicitari!",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],nume1);
            Sleep(5000);
            goto afara;
        }
        else if((v[0]=='O' && v[1]==v[0] && v[1]==v[2])or
                (v[3]=='O' && v[4]==v[5] && v[5]==v[3])or
                (v[6]=='O' && v[7]==v[8] && v[8]==v[6])or
                (v[0]=='O' && v[4]==v[8] && v[8]==v[0])or
                (v[2]=='O' && v[4]==v[6] && v[6]==v[2])or
                (v[0]=='O' && v[3]==v[6] && v[7]==v[0])or
                (v[1]=='O' && v[4]==v[7] && v[7]==v[1])or
                (v[2]=='O' && v[5]==v[8] && v[8]==v[2])or
                (v[0]=='O' && v[0]==v[3] && v[3]==v[6]))
        {
            system("CLS");
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\nAi pierdut!",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
            Sleep(5000);
            goto afara;
        }
        else if(v[0]!='1' && v[1]!='2' && v[2]!='3' &&
                v[3]!='4' && v[4]!='5' && v[5]!='6' &&
                v[6]!='7' && v[7]!='8' && v[8]!='9')
        {
            system("CLS");
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\nNimeni nu a castigat.",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
            Sleep(5000);
            goto afara;
        }
        }
        Sleep(250);
    }
    afara:
    printf("Doriti sa mai jucati o data? Da/Nu");
    scanf("%s",verificare);
    if((verificare[0]=='D' or verificare[0]=='d') && (verificare[1]=='A' or verificare[1]=='a'))
        goto inc;
    else if((verificare[0]=='N' or verificare[0]=='n') && (verificare[1]=='u' or verificare[1]=='U'))
    {
        printf("O zi buna!");
        return 1;
    }
    else return 0;
}
int tabel2()
{
    int pointer=0,p=2;
    inc:
    v[0]='1';v[1]='2';v[2]='3';v[3]='4';v[4]='5';v[5]='6';v[6]='7';v[7]='8';v[8]='9';
    printf("Care este numele primului jucator?");
    scanf("%s",nume1);
    printf("Care este numele celui de-al doilea jucator?");
    scanf("%s",nume2);
    sus:
    while(true)
    {
        system("CLS");
        if(pointer==0)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[0]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\n",v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==1)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|",v[0]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[1]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\n",v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==2)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|",v[0],v[1]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[2]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\n",v[3],v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==3)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n",v[0],v[1],v[2]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[3]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c|%c\n-+-+-\n%c|%c|%c\n",v[4],v[5],v[6],v[7],v[8]);
        }
        else if(pointer==4)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|",v[0],v[1],v[2],v[3]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[4]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c\n-+-+-\n%c|%c|%c\n",v[5],v[6],v[7],v[8]);
        }
        else if(pointer==5)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|",v[0],v[1],v[2],v[3],v[4]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[5]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("\n-+-+-\n%c|%c|%c\n",v[6],v[7],v[8]);
        }
        else if(pointer==6)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n",v[0],v[1],v[2],v[3],v[4],v[5]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[6]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c|%c\n",v[7],v[8]);
        }
        else if(pointer==7)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|",v[0],v[1],v[2],v[3],v[4],v[5],v[6]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c",v[7]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("|%c\n",v[8]);
        }
        else if(pointer==8)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
            printf("%c\n",v[8]);
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
        }
        else if(pointer>8)
            pointer=8;
        else if(pointer<0)
            pointer=0;
        if(p%2==0)
            printf("\nAcum joaca %s.\nS-a facut un total de %d mutari.",nume1,m);
        else printf("\nAcum joaca %s.\nS-a facut un total de %d mutari.",nume2,m);
        while(true)
        {
            if(GetAsyncKeyState(VK_UP)!=0)
            {
                pointer-=3;
                if(pointer<0)
                    pointer=0;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_DOWN)!=0)
            {
                pointer+=3;
                if(pointer>8)
                    pointer=8;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_RIGHT)!=0)
            {
                pointer+=1;
                if(pointer>8)
                    pointer=8;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_LEFT)!=0)
            {
                pointer-=1;
                if(pointer<0)
                    pointer=0;
                m+=1;
                break;
            }
            else if(GetAsyncKeyState(VK_RETURN)!=0)
            {
                switch(pointer)
                {
                    case 0: {
                        if(p%2==0 && v[0]=='1' && m>0)
                            v[0]='X';
                        else if(p%2!=0 && v[0]=='1' && m>0)
                            v[0]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 1: {
                        if(p%2==0 && v[1]=='2')
                            v[1]='X';
                        else if(p%2!=0 && v[1]=='2')
                            v[1]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 2: {
                        if(p%2==0 && v[2]=='3')
                            v[2]='X';
                        else if(p%2!=0 &&v[2]=='3')
                            v[2]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 3: {
                        if(p%2==0 && v[3]=='4')
                            v[3]='X';
                        if(p%2!=0 && v[3]=='4')
                            v[3]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 4: {
                        if(p%2==0 && v[4]=='5')
                            v[4]='X';
                        else if(p%2!=0 && v[4]=='5')
                            v[4]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 5: {
                        if(p%2==0 && v[5]=='6')
                            v[5]='X';
                        else if(p%2!=0 && v[5]=='6')
                            v[5]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 6: {
                        if(p%2==0 && v[6]=='7')
                            v[6]='X';
                        else if(p%2!=0 && v[6]=='7')
                            v[6]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 7: {
                        if(p%2==0 && v[7]=='8')
                            v[7]='X';
                        else if(p%2!=0 && v[7]=='8')
                            v[7]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    case 8: {
                        if(p%2==0 && v[8]=='9')
                            v[8]='X';
                        else if(p%2!=0 && v[8]=='9')
                            v[8]='O';
                        p+=1; Sleep(500);
                        goto sus;
                    } break;
                    default: {
                        printf("Casuta pe care ai ales-o nu este corecta.");
                        goto sus;
                    } break;
                }
            }
        if((v[0]=='X' && v[1]==v[0] && v[1]==v[2])or
        (v[3]=='X' && v[4]==v[5] && v[5]==v[3])or
        (v[6]=='X' && v[7]==v[8] && v[8]==v[6])or
        (v[0]=='X' && v[4]==v[8] && v[8]==v[0])or
        (v[2]=='X' && v[4]==v[6] && v[6]==v[2])or
        (v[0]=='X' && v[3]==v[6] && v[7]==v[0])or
        (v[1]=='X' && v[4]==v[7] && v[7]==v[1])or
        (v[2]=='X' && v[5]==v[8] && v[8]==v[2])or
        (v[0]=='X' && v[0]==v[3] && v[3]==v[6]))
        {
            system("CLS");
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\nJucatorul %s a castigat. Felicitari!",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],nume1);
            Sleep(5000);
            goto afara;
        }
        else if((v[0]=='O' && v[1]==v[0] && v[1]==v[2])or
                (v[3]=='O' && v[4]==v[5] && v[5]==v[3])or
                (v[6]=='O' && v[7]==v[8] && v[8]==v[6])or
                (v[0]=='O' && v[4]==v[8] && v[8]==v[0])or
                (v[2]=='O' && v[4]==v[6] && v[6]==v[2])or
                (v[0]=='O' && v[3]==v[6] && v[7]==v[0])or
                (v[1]=='O' && v[4]==v[7] && v[7]==v[1])or
                (v[2]=='O' && v[5]==v[8] && v[8]==v[2])or
                (v[0]=='O' && v[0]==v[3] && v[3]==v[6]))
        {
            system("CLS");
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\nJucatorul %s a castigat. Felicitari!",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],nume2);
            Sleep(5000);
            goto afara;
        }
        else if(v[0]!='1' && v[1]!='2' && v[2]!='3' &&
                v[3]!='4' && v[4]!='5' && v[5]!='6' &&
                v[6]!='7' && v[7]!='8' && v[8]!='9')
        {
            system("CLS");
            printf("%c|%c|%c\n-+-+-\n%c|%c|%c\n-+-+-\n%c|%c|%c\nNimeni nu a castigat.",v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]);
            Sleep(5000);
            goto afara;
        }
        }
        Sleep(250);
    }
    afara:
    printf("Doriti sa mai jucati o data? Da/Nu");
    scanf("%s",verificare);
    if((verificare[0]=='D' or verificare[0]=='d') && (verificare[1]=='A' or verificare[1]=='a'))
        goto inc;
    else if((verificare[0]=='N' or verificare[0]=='n') && (verificare[1]=='u' or verificare[1]=='U'))
    {
        printf("O zi buna!");
        return 1;
    }
    else return 0;
}
int main()
{
    int pointer=0;
    while(true)
    {
        system("CLS");
        printf("\n\n\n\n\n\n\n\n");
        for(i=0;i<4;i+=1)
        {
            if(pointer==i)
            {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                //printf("\t\t\t%s\n",tabel[i]);
                if(pointer==0)
                {
                    printf("\t\t\t%s\n",tabel[i]);
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
                    printf("\t\t(X si 0 impotriva calculatorului)\n");
                }
                else if(pointer==1)
                {
                    printf("\t\t\t%s\n",tabel[i]);
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
                    printf("\t(Vrei sa testezi injuraturi pe un coleg? Lasa-l sa castige)\n");
                }
                else if(pointer==2)
                {
                    printf("\t\t\t%s\n",tabel[i]);
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
                    printf("\t\t\t(Vezi ce e nou)\n");
                }
                else if(pointer==3)
                {
                    printf("\t\t\t%s\n",tabel[i]);
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
                    printf("\t\t\t(Vrei sa iesi?)\n");
                }
            }
            else
            {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
                printf("\t\t\t%s\n",tabel[i]);
            }
        }
        Sleep(250);
        while(true)
        {
            if(GetAsyncKeyState(VK_UP)!=0)
            {
                pointer-=1;
                if(pointer<0)
                    pointer=3;
                break;
            }
            else if(GetAsyncKeyState(VK_DOWN)!=0)
            {
                pointer+=1;
                if(pointer>3)
                    pointer=0;
                break;
            }
            else if(GetAsyncKeyState(VK_RETURN)!=0)
                switch(pointer)
                {
                case 0: {
                    variabila=tabel1();
                    if(variabila==1)
                        goto finish;
                    else pointer=0;
                } break;
                case 1: {
                    variabila=tabel2();
                    if(variabila==1)
                        goto finish;
                    else pointer=1;
                } break;
                case 2: {
                    system("CLS");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                    printf("~~~~~~~~~~~~~~~~UPDATES~~~~~~~~~~~~~~~~");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
                    printf("\n\t\t\t-V0.1");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
                    printf("\n\t-Programul a fost restructurat\n\t-Rezolvate unele probleme minore\n\t\t\t");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
                    printf("\n\t\t\t-V0.2");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
                    printf("\n\t-Adaugat meniu:\n\t\t-Tic Toe Game(1P)\n\t\t-Tic Toe Game(2P)\n\t\t-Updates\n\t\t-Exit\n\t-Adaugate cateva texte inaccesibile la meniu");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
                    printf("\n\t\t\t-V0.3");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
                    printf("\n\t-Adaugata versiunea Single Player\n\t-Problema ce facea ca unii jucatori sa nu castige rezolvata");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
                    printf("\n\t\t\t-V0.4");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
                    printf("\n\t-Adaugata \"Tabla de joc\"\n\t-Rezolvat un bug ce facea casuta \'9\' inaccesibila pentru calculator");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
                    printf("\n\t\t\t-V0.5");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
                    printf("\n\t-A fost refacut intregul sistem, acum:\n\t\t-\"navigarea\" se face cu sageti\n\t\t-Selectarea se face cu enter\n\t\tAdaugate cateva culori pe \"tabla de joc\"\n\t-Acum nu vor mai exista probleme legate de tipul variabilelor");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
                    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
                    printf("\nApasati pe sageata sus sau sageata jos pentru a reveni la meniu.");
                } break;
                case 3: goto finish;
            }
        }
    }
    finish:
    return 0;
}

Stiu ca nu e foarte bine optimizat si ca e mai mult C decat C++.

Scuze de intarziere, nu prea am mai intrat pe forum.

Edited by Cdorsu
Link to comment
Share on other sites

Asta nu e facut de tine :))

 

Ce te da de gol:

 

- E facut in C, nu C++, deci habar nu ai nici macar in ce limbaj e scris

- Nu se face C++ in scoala

- Nu se face C in clasa a 9-a, se fac algoritmi

- windows.h ? Cu libraria asta nu se lucreaza in scoli, sa zicem ca te-ai documentat pe net despre ea. Daca imi zici la ce o folosesti imi retrag jumatate din acuzatii.

 

Si evident, cum a zis Paul:

Prea mult cod pentru ceva prea simplu...

 

Observatii :

- foloseste switch peste tot, in loc de harababura aia de else if-uri.

- break; la switch desi nu ajungi niciodata la el... timp si viata tastaturii irosite

- goto afara; ? :)) Asta chiar m-a facut sa zambesc. Apreciez ca ai stat sa traduci tot codul in romana de unde l-oi fi copiat, dar in general, in programare numim etichetele de iesire din loop "end" "endloop" sau "exit".

 

 

Intrebare de 10 puncte: De cate ori ai refacut codul, conform observatiilor scrise "de tine" ?

Edited by DoTT
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.