Results 1 to 9 of 9
  1. #1
    VvITylerIvV's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    The streets
    Posts
    668
    Reputation
    5
    Thanks
    61
    My Mood
    In Love

    Yay I made a tictactoe game :)

    [php]
    #include<iostream>
    #include<stdio.h>
    #include<conio.h>
    using namespace std;
    int display(char a[3][3]);
    void main()
    {
    int e,f,g,h,i,j;

    char a[3][3] , l='0';
    while(l == '0')
    {
    e=0;
    f=0;
    a[0][0]='1';
    a[0][1]='2';
    a[0][2]='3';
    a[1][0]='4';
    a[1][1]='5';
    a[1][2]='6';
    a[2][0]='7';
    a[2][1]='8';
    a[2][2]='9';
    e=display(a);
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    a[i][j]=' ';
    while(e==0)
    {
    h=1;
    while(h!=0)
    {
    cout<<"Enter the number of the box you wish to use."<<endl;
    cin>>g;
    if(g<1||g>9)
    {
    cout<<"Does not compute..."<<endl;
    f=1;
    }
    else
    {
    if((a[(g-1)/3][(g-1)%3]=='x')||(a[(g-1)/3][(g-1)%3]=='o'))
    {
    cout<<"wait?what... That wasn't a usable spot..."<<endl;
    f=1;
    }
    else
    h=0;
    }
    }
    if(f%2==0)
    a[(g-1)/3][(g-1)%3]='x';
    else
    a[(g-1)/3][(g-1)%3]='o';
    e=display(a);
    f++;
    }
    if(e==1)
    cout<<"player 1 wins"<<endl;
    if(e==2)
    cout<<"player 2 wins"<<endl;
    if(e==3)
    cout<<"game is drawn"<<endl;
    cout<<"wanna play another game \n press 0 to continue"<<endl;
    l=getchar();
    }
    getch();
    }
    int display(char a[3][3])
    {
    int i,j,e=0,s;
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    cout<<a[i][j]<<"|";
    }
    cout<<"\n";

    cout<<"-|-|-"<<endl;
    }
    if((a[0][0]=='x')&&(a[1][1]=='x')&&(a[2][2]=='x'))
    e=1;

    if((a[0][0]=='x')&&(a[0][1]=='x')&&(a[0][2]=='x'))
    e=1;

    if((a[0][0]=='x')&&(a[1][0]=='x')&&(a[2][0]=='x'))
    e=1;

    if((a[2][0]=='x')&&(a[2][1]=='x')&&(a[2][2]=='x'))
    e=1;

    if((a[1][0]=='x')&&(a[1][1]=='x')&&(a[1][2]=='x'))
    e=1;

    if((a[0][1]=='x')&&(a[1][1]=='x')&&(a[2][1]=='x'))
    e=1;

    if((a[0][2]=='x')&&(a[1][2]=='x')&&(a[2][2]=='x'))
    e=1;

    if((a[0][2]=='x')&&(a[1][1]=='x')&&(a[2][0]=='x'))
    e=1;

    if((a[0][0]=='o')&&(a[1][1]=='o')&&(a[2][2]=='o'))
    e=2;

    if((a[0][0]=='o')&&(a[0][1]=='o')&&(a[0][2]=='o'))
    e=2;

    if((a[0][0]=='o')&&(a[1][0]=='o')&&(a[2][0]=='o'))
    e=2;

    if((a[2][0]=='o')&&(a[2][1]=='o')&&(a[2][2]=='o'))
    e=2;

    if((a[1][0]=='o')&&(a[1][1]=='o')&&(a[1][2]=='o'))
    e=2;

    if((a[0][1]=='o')&&(a[1][1]=='o')&&(a[2][1]=='o'))
    e=2;

    if((a[0][2]=='o')&&(a[1][2]=='o')&&(a[2][2]=='o'))
    e=2;

    if((a[0][2]=='o')&&(a[1][1]=='o')&&(a[2][0]=='o'))
    e=2;

    s=0;
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
    if((a[i][j]=='x')||(a[i][j]=='o'))
    s++;
    }
    if(e!=1&&e!=2&&s==9)
    return (3);
    if(e==1|e==2)
    return e;
    if(e!=1&&e!=2)
    if(s!=9)
    return (0);
    }
    [/php]

    Been working on it for a few days now... Thought I'd release the messy code
    Favourite quotes:

    Code:
    I don't need easy, I just need possible. ~ Me 
    
    There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this
    
    Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
    Quote Originally Posted by VirtualSia View Post
    You both have a very weird and awkward view on Computer science.
    Computer science is about computing, which is programming.
    Definition of computing: The use or operation of computers.
    Turning on my computer = computing = programming
    LAWLFAIL

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Nice, just a comment: you could cut a bit your if's if you had a cycle or two ^^

    Btw, now try to use this, if you understand: SetConsoleCursorPosition Function (Windows)

    The game will look better for sure ;D
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. #3
    asdzxcvbqwerty's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    69
    Reputation
    10
    Thanks
    19
    Dam...that looks advance

  4. #4
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted
    Nice work, I made an AI once for tic-tac-toe
    And since that's all I do at school I was realy pro but I've never beat my AI XD he was the perfect player

  5. #5
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    You could just create a game class to draw the board. but nice

    and when you used [php]void main()[/php]
    Why did you return?
    Last edited by Kallisti; 08-13-2010 at 01:00 AM.

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




  6. #6
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    he is not returning main, even as dead i can see better then you
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  7. #7
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    ohyeea. oops.

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




  8. #8
    scuarplex's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    16
    Reputation
    13
    Thanks
    0
    My Mood
    Psychedelic
    Could be used "Case" instead of all those if?

  9. #9
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    Quote Originally Posted by scuarplex View Post
    Could be used "Case" instead of all those if?
    You cant put logical operators in a case

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




Similar Threads

  1. Question To ANY Experienced C++ Coder (who Has Made Hacks For Games)
    By OmEgaGaMeHaXor in forum C++/C Programming
    Replies: 25
    Last Post: 12-02-2009, 07:47 PM
  2. Yay finally road to self made hacks
    By Cancelled in forum C++/C Programming
    Replies: 2
    Last Post: 03-20-2009, 11:38 PM
  3. hacks are made by the same people who make the game?
    By angelslayer7 in forum Combat Arms Hacks & Cheats
    Replies: 7
    Last Post: 03-12-2009, 08:04 PM
  4. home made fps game LOOK NOW FUCKERS.
    By gbitz in forum General
    Replies: 118
    Last Post: 02-18-2009, 04:24 PM