elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: Juego Gato Inteligente. en: 2 Septiembre 2010, 15:00 pm
Simplemente podrias usar un .txt o .dat

Y crear una struct score {   };  donde guarde las ganas y perdidas y las guarde dentro del archivo.. y luego las recupere cuando quieras leerlas

poniendo una opcion Extra en la pantalla principal donde te muestre cuantas veces ganaste o perdiste

Hiciste todo el juego y no tienes idea de como hacer para guardar el puntaje? =/

eso lo se, aqui el problema esque crea un archivo .dat eh hice los metodos para ganancia, perdida y empate, pero el problema real esque todas las clases tienen herencia, entonces me complique un poco al momento de hacerlo, y ahora necesito orientacion porque estoy un poco perdido, dejame actualizar el codigo.. al que recien modifique.. que es el que crea el archivo ".dat" y comentare la parte donde tengo el problema.. dame un segundo para eso
2  Programación / Programación C/C++ / Re: Juego Gato Inteligente. en: 1 Septiembre 2010, 20:09 pm
probando el code creo qe encontre un pequeño problema... en realidad no entiendo nada de C++ jajaja por eso te digo creo :P

cuando es empate, ya probe 2 veces y me dice:

"Perdiste, La Primicia Es Mia..Bueno Fue Empate quieres la revancha?.
tic tac toe by Alberto Coverdale

Quieres jugar de nuevo??"

Creo qe el perdiste al principio no deberia aparecer no?

salu2!!

si lo siento! esos son errores mios,
y gracias por intentar ayudarme xD
3  Programación / Programación C/C++ / Juego Gato Inteligente. en: 1 Septiembre 2010, 16:02 pm
hola quiero ver si alguien me puede ayudar..
eh casi terminado con mi juego de gato pero el profesor me pido que guarde el score de victorias y/o perdidas, eh logrado que cree el archivo pero no escribe sobre el..
alguien puede ayudarme u orientarme a termianar el codigo porfavor...
de esto depende mi calificacion:S




Código
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #include<fstream>
  5. #include<time.h>
  6. #include <stdlib.h>
  7. #include <windows.h>
  8. using namespace std;
  9. using std::tolower;
  10.  
  11.  
  12. class tttboard
  13. {
  14. private:
  15.    char board[3][3];
  16. public:
  17.    static const char NOBODY = ' ', PLAYER1 = 'X', PLAYER2 = 'O';
  18.  
  19.    tttboard();
  20.    void init_board();
  21.    void display();
  22.    void set(int x, int y, char c);
  23.    char get(int x, int y) const;
  24.  
  25.  
  26. };
  27.  
  28. tttboard::tttboard()
  29.                     {
  30.                        init_board();
  31.                     }
  32.  
  33.  
  34.  
  35. void tttboard::init_board()
  36. {
  37.    for(int x = 0; x < 3; x ++)
  38.                                {
  39.                                for(int y = 0; y < 3; y ++)
  40.                                                 {
  41.                                                  board[x][y] = NOBODY;
  42.                                                 }      
  43.                                 }
  44. }
  45.  
  46. void tttboard::display()
  47. {
  48.     system("cls");
  49.    cout << endl;
  50.  
  51.    for(int y = 0; y < 3; y ++)
  52.  
  53.    {
  54.  
  55.                     for(int x = 0; x < 3; x ++)
  56.                             {
  57.  
  58.                                 cout << board[x][y];
  59.                                 if(x < 2) cout << '|';
  60.                             }
  61.  
  62.        cout << endl;
  63.        if(y < 2) cout << "-+-+-\n";
  64.    }
  65. }
  66.  
  67. void tttboard::set(int x, int y, char c)
  68.     {
  69.  
  70.    board[x][y] = c;
  71.  
  72.    }
  73.  
  74.  
  75. char tttboard::get(int x, int y) const
  76. {
  77.  
  78.    return board[x][y];
  79.  
  80. }
  81.  
  82.  
  83. class opponent
  84. {
  85.  
  86. //private:  
  87. //      
  88. //       string name;
  89.  
  90. protected:
  91.  
  92.    char c;
  93.    void set_name(string name, char c);
  94. public:
  95.     string name;  
  96.    virtual void move(const tttboard &board, int &xpos, int &ypos) = 0;
  97.    string get_name()
  98.    {
  99.            return name;
  100.    }
  101. };
  102.  
  103.  
  104. void opponent::set_name(string name, char c)
  105. {
  106.    this->name = name + " (" + c + ")";
  107.    this->c = c;
  108. }
  109.  
  110. class aiopponent : public opponent
  111. {
  112. private:
  113.    int two(char c, char x, char y, char z);
  114. public:
  115.    aiopponent(string name, char c);
  116.    void move(const tttboard &board, int &xpos, int &ypos);
  117. };
  118.  
  119. aiopponent::aiopponent(string name, char c)
  120. {
  121.    set_name(name, c);
  122. }
  123.  
  124.  
  125. int aiopponent::two(char c, char x, char y, char z)
  126. {
  127.    if(x == c && y == c && z == tttboard::NOBODY) return 3;
  128.    if(x == c && y == tttboard::NOBODY && z == c) return 2;
  129.    if(x == tttboard::NOBODY && y == c && z == c) return 1;
  130.  
  131.    return 0;
  132. }
  133.  
  134. void aiopponent::move(const tttboard &board, int &xpos, int &ypos)
  135. {
  136.    int r;
  137.    char ic; // = (c == tttboard::PLAYER1 ? tttboard::PLAYER2 : tttboard::PLAYER1);
  138.  
  139.    if(c == tttboard::PLAYER1) ic = tttboard::PLAYER2;
  140.    else ic = tttboard::PLAYER1;
  141.  
  142.    /* Busca lugares para ganar */
  143.    for(int x = 0; x < 3; x ++)
  144.    {
  145.        if((r = two(c, board.get(0, x), board.get(1, x), board.get(2, x))))
  146.        {
  147.            ypos = x, xpos = r-1;
  148.            return;
  149.        }
  150.  
  151.        if((r = two(c, board.get(x, 0), board.get(x, 1), board.get(x, 2))))
  152.        {
  153.            xpos = x, ypos = r-1;
  154.            return;
  155.        }
  156.    }
  157.  
  158.    if((r = two(c, board.get(0, 0), board.get(1, 1), board.get(2, 2))))
  159.    {
  160.        xpos = r-1, ypos = r-1;
  161.        return;
  162.    }
  163.  
  164.    if((r = two(c, board.get(2, 0), board.get(1, 1), board.get(0, 2))))
  165.    {
  166.        xpos = 3-r, ypos = r-1;
  167.        return;
  168.    }
  169.  
  170.    /* Blokea lugares perdidos */
  171.    for(int x = 0; x < 3; x ++)
  172.    {
  173.        if((r = two(ic, board.get(0, x), board.get(1, x), board.get(2, x))))
  174.        {
  175.            ypos = x, xpos = r-1;
  176.            return;
  177.        }
  178.  
  179.    if((r = two(ic, board.get(x, 0), board.get(x, 1), board.get(x, 2))))
  180.        {
  181.            xpos = x, ypos = r-1;
  182.            return;
  183.        }
  184.    }
  185.  
  186.    if((r = two(ic, board.get(0, 0), board.get(1, 1), board.get(2, 2))))
  187.    {
  188.        xpos = r-1, ypos = r-1;
  189.        return;
  190.    }
  191.  
  192.    if((r = two(ic, board.get(2, 0), board.get(1, 1), board.get(0, 2))))
  193.    {
  194.        xpos = 3-r, ypos = r-1;
  195.        return;
  196.    }
  197.  
  198.    /*Pone la ficha en el centro si esta disponible*/                                        
  199.  
  200.  
  201.   if(board.get(1, 1) == tttboard::NOBODY)
  202.    {
  203.        xpos = 1, ypos = 1;
  204.        return;
  205.    }
  206.  
  207.  
  208.    /* Toma la esquina si esta no esta ocupada aun */
  209.  
  210.    if(board.get(0, 0) != c && board.get(2, 0) != c
  211.        && board.get(0, 2) != c && board.get(2, 2) != c)
  212.        {
  213.  
  214.  
  215.        if(board.get(0, 0) == tttboard::NOBODY)
  216.  
  217.        {
  218.            xpos = 0, ypos = 0;
  219.            return;
  220.        }
  221.  
  222.    if(board.get(2, 0) == tttboard::NOBODY)
  223.        {
  224.            xpos = 2, ypos = 0;
  225.            return;
  226.        }
  227.        if(board.get(0, 2) == tttboard::NOBODY)
  228.        {
  229.            xpos = 0, ypos = 2;
  230.            return;
  231.        }
  232.        if(board.get(2, 2) == tttboard::NOBODY)
  233.        {
  234.            xpos = 2, ypos = 2;
  235.            return;
  236.        }
  237.       }
  238.  
  239.  
  240.    for(int x = 0; x < 3; x ++) {
  241.        for(int y = 0; y < 3; y ++) {
  242.            if(board.get(x, y) == tttboard::NOBODY) {
  243.                xpos = x, ypos = y;
  244.                return;
  245.            }
  246.        }
  247.    }
  248. }
  249.  
  250.  
  251. class humanopponent : public opponent
  252. {
  253.  
  254. public:
  255.    int v,p,e;  
  256.    humanopponent(char c);
  257.    void move(const tttboard &board, int &xpos, int &ypos);
  258.    void victory()
  259.    {
  260.         v+=1;
  261.    }
  262.    void lost()
  263.    {
  264.         p+=1;
  265.    }
  266.    void tie()
  267.    {
  268.         e+=1;
  269.    }
  270.  
  271.    int getvictory()
  272.    {
  273.        return v;
  274.    }
  275.    int getlost()
  276.    {
  277.        return p;
  278.    }
  279.    int gettie()
  280.    {
  281.        return e;
  282.    }
  283.    void print()
  284.    {
  285.         cout<<"Victorias "<<v<<endl;
  286.         cout<<"Perdidas "<<p<<endl;
  287.         cout<<"Empates "<<e<<endl;
  288.    }
  289.    void get()
  290.    {
  291.         cout<<name;
  292.         cout<<"Victorias "<<getvictory<<endl;
  293.         cout<<"Perdidas "<<getlost<<endl;
  294.         cout<<"Empates "<<gettie;
  295.    }
  296.  
  297. };
  298.  
  299.  
  300. humanopponent::humanopponent(char c)
  301. {                              
  302.    cout << "\nIngresa Tu Nombre: ";
  303.    string name;
  304.    cin >> name;
  305.    set_name(name, c);
  306.    v=0;
  307.    p=0;
  308.    e=0;
  309.  
  310. }
  311.  
  312. void humanopponent::move(const tttboard &board, int &xpos, int &ypos)
  313. {
  314.  
  315.    for(;;)
  316.  
  317.   {
  318.        cout << "Ingresa Numero De Columna (1-3): ";
  319.        while(!(cin >> xpos) || xpos <= 0 || xpos > 3)
  320.        {
  321.            // !!!
  322.            cin.clear();
  323.            cout << ": ";
  324.        }
  325.  
  326.        cout << "Ingresa Numero De Fila (1-3): ";
  327.        while(!(cin >> ypos) || ypos <= 0 || ypos > 3)
  328.  
  329.        {
  330.            cin.clear();
  331.            cout << ": ";
  332.        }
  333.  
  334.        xpos --, ypos --;
  335.  
  336.        if(board.get(xpos, ypos) != tttboard::NOBODY)
  337.  
  338.        {
  339.            cout << "Ya Esta Ocupado \n";
  340.            continue;
  341.        }
  342.  
  343.        break;
  344.    }
  345. }
  346.  
  347. class ttt : public opponent
  348.  
  349. {
  350.  
  351. private:
  352.  
  353.    tttboard board;
  354.    opponent *player[2];
  355.  
  356.    int turn;
  357.  
  358. public:
  359.  
  360.    ttt();
  361.    ~ttt();
  362.    bool new_game();
  363.    void play_game();
  364.    int game_done();
  365.    void move(const tttboard &board, int &xpos, int &ypos)
  366.    {
  367.    }
  368. };
  369.  
  370.  
  371. ttt::ttt() : turn(0)
  372. {
  373.    player[0] = player[1] = NULL;
  374. }
  375.  
  376. ttt::~ttt()
  377. {
  378.    for(int x = 0; x < 2; x ++)
  379.    {
  380.        if(player[x]) delete player[x];
  381.    }
  382. }
  383.  
  384. bool ttt::new_game()
  385. {
  386.    cout << "\nJuego Nuevo\nJugador  #1 ([A]I/[H]uman/[Q]uit): ";
  387.  
  388.    char one;
  389.    for(;;)
  390.    {
  391.        if(!(cin >> one))
  392.        {
  393.            cin.clear();
  394.            continue;
  395.        }
  396.  
  397.        one = tolower(one);
  398.        if(one == 'q') return false;
  399.        if(one == 'a' || one == 'h') break;
  400.    }
  401.  
  402.    cout << "Jugador #2 ([A]I/[H]uman/[Q]uit): ";
  403.  
  404.    char two;
  405.    for(;;)
  406.    {
  407.        if(!(cin >> two))
  408.        {
  409.            cin.clear();
  410.            continue;
  411.        }
  412.  
  413.        two = tolower(two);
  414.        if(two == 'q') return false;
  415.        if(two == 'a' || two == 'h') break;
  416.    }
  417.  
  418.    if(one == 'h') player[0] = new humanopponent(tttboard::PLAYER1);
  419.    else
  420.    {
  421.        player[0] = new aiopponent("AI for player #1", tttboard::PLAYER1);
  422.    }
  423.  
  424.    if(two == 'h') player[1] = new humanopponent(tttboard::PLAYER2);
  425.    else
  426.    {
  427.        player[1] = new aiopponent("AI for player #2", tttboard::PLAYER2);
  428.    }
  429.  
  430.    turn = 0;
  431.    play_game();
  432.  
  433.    return true;
  434. }
  435.  
  436. void ttt::play_game()
  437. {
  438.    int v,p,e;
  439.    int x, y, won;
  440.    char again;
  441.  
  442.    do
  443.     {
  444.        board.init_board();
  445.  
  446.        while(!(won = game_done()))
  447.        {
  448.            board.display();
  449.            cout << player[turn]->get_name() << endl;
  450.            player[turn]->move(board, x, y);
  451.            cout << player[turn]->get_name() << " picked position "
  452.                << x+1 << ", " << y+1 << endl;
  453.            board.set(x, y, turn ? tttboard::PLAYER2 : tttboard::PLAYER1);
  454.            turn = !turn;
  455.        }
  456.  
  457.        board.display();
  458.        cout << "Perdiste,La Primicia Es Mia..";
  459.  
  460.        switch(won) // aqui tengo el problema, para mandar llamar las variables.//
  461.        {
  462.        case -1: cout << "Bueno Fue Empate quieres la revancha?.";break;
  463.        case 1: cout << player[0]->get_name() << "Felicidades Tienes la Primicia!"; break;
  464.        case 2: cout << player[1]->get_name() << "Felicidades Tienes la Primicia!"; break;
  465.  
  466.        }
  467.  
  468.        cout << endl;
  469.        cout << "tic tac toe by Alberto Coverdale\n"<<endl;
  470.        cout << "Quieres jugar de nuevo??";
  471.        ofstream rankFileOut("rank.dat", ios::app);
  472.        rankFileOut<<opponent::get_name();
  473.        rankFileOut.close();  
  474.        cin >> again;
  475.    }
  476.  
  477.     while(tolower(again) == 'y');
  478. }
  479.  
  480. int ttt::game_done()
  481. {
  482.    int n, flag = 0;
  483.  
  484.    for(int x = 0; x < 3 && !flag; x ++)
  485.    {
  486.        for(int y = 0; y < 3 && !flag; y ++)
  487.        {
  488.            if(board.get(x, y) == tttboard::NOBODY) flag = 1;
  489.        }
  490.    }
  491.  
  492.    if(!flag) return -1;
  493.  
  494.    for(int x = 0; x < 3; x ++)
  495.    {
  496.        if((n = board.get(x, 0)) != tttboard::NOBODY)
  497.        {
  498.            if(n == board.get(x, 1) && n == board.get(x, 2))
  499.            {
  500.                return n == tttboard::PLAYER1 ? 1 : 2;
  501.            }
  502.        }
  503.    }
  504.  
  505.    for(int y = 0; y < 3; y ++)
  506.    {
  507.        if((n = board.get(0, y)) != tttboard::NOBODY)
  508.        {
  509.            if(n == board.get(1, y) && n == board.get(2, y))
  510.            {
  511.                return n == tttboard::PLAYER1 ? 1 : 2;
  512.            }
  513.        }
  514.    }
  515.  
  516.    if((n = board.get(0, 0)) != tttboard::NOBODY)
  517.    {
  518.        if(n == board.get(1, 1) && n == board.get(2, 2))
  519.        {
  520.            return n == tttboard::PLAYER1 ? 1 : 2;
  521.        }
  522.    }
  523.  
  524.    if((n = board.get(2, 0)) != tttboard::NOBODY)
  525.    {
  526.        if(n == board.get(1, 1) && n == board.get(0, 2))
  527.        {
  528.            return n == tttboard::PLAYER1 ? 1 : 2;
  529.        }
  530.    }
  531.  
  532.    return 0;
  533. }
  534.  
  535.  
  536.  
  537.  
  538.  
  539. int main()
  540. {      
  541.    int trn=1;  
  542.     int i=1;
  543.     char ch='y';    
  544.     int winner=1;    
  545.     int ctrl1,ctrl2;  
  546.     int ctr=0;
  547.     int check_for_tie;
  548.     char begin,Yeah, inst, jum, choice;
  549.     int dec;    
  550.  
  551.  
  552.  
  553.  
  554.  
  555.     cout<<"Este Juego fue creado por Alberto Coverdale"<<endl;
  556.     cout<<"Desea Comenzar el juego??"<<endl;
  557.     cout<<"[Y][N]"<<endl;
  558.     cin>>Yeah;
  559.     if (Yeah=='Y' ||Yeah=='y')
  560.     {
  561.         cout<<"\n\n\n\n\n";
  562.  
  563.         cout<<"\n**     **  ********  *******";
  564.         cout<<"\n**     **  ********  ********";
  565.         cout<<"\n**     **  **    **  **    **";
  566.         cout<<"\n**  *  **  ********  *******";
  567.         cout<<"\n** *** **  ********  *******";
  568.         cout<<"\n***   ***  **    **  **    **";
  569.         cout<<"\n**     **  **    **  **    **";
  570.         cout<<"\n\n\n";
  571.         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  572.         {
  573.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  574.           {
  575.           }
  576.         }        
  577.         cout<<"\n\t\t********  ********";
  578.         cout<<"\n\t\t********  ********";
  579.         cout<<"\n\t\t**    **  **";
  580.         cout<<"\n\t\t**    **  *****";
  581.         cout<<"\n\t\t**    **  *****";
  582.         cout<<"\n\t\t********  **";
  583.         cout<<"\n\t\t********  **";
  584.         cout<<"\n\n\n";
  585.         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  586.         {
  587.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  588.           {
  589.           }
  590.         }
  591.         cout<<"\n\t\t\t********  **    **  ********";
  592.         cout<<"\n\t\t\t********  **    **  ********";
  593.         cout<<"\n\t\t\t   **     ********  **";
  594.         cout<<"\n\t\t\t   **     ********  *****";
  595.         cout<<"\n\t\t\t   **     **    **  **";
  596.         cout<<"\n\t\t\t   **     **    **  ********";
  597.         cout<<"\n\t\t\t   **     **    **  ********";
  598.         cout<<"\n\n\n";
  599.         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  600.         {
  601.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  602.           {
  603.           }
  604.         }
  605.         cout<<"\n      **         ********    ****       ****   ********  ****          *******";
  606.         cout<<"\n      **         ********    ** **     ** **   ********  ****          ********";
  607.         cout<<"\n      **         **    **    **  **   **  **   **    **  ****          **";
  608.         cout<<"\n      **         ********    **   ** **   **   ********  ****             **";
  609.         cout<<"\n      **         ********    **    ***    **   ********  ****                **";
  610.         cout<<"\n *************   **    **    **           **   **    **  ************   ********";
  611.         cout<<"\n *************   **    **    **           **   **    **  ************   ********";
  612.  
  613.     }
  614.         else
  615.         {
  616.             return 0;
  617.         }                
  618.  
  619.  
  620.  
  621.  
  622. cout<<"\n\n\n\n\n\t\t La Guerra De Los Tamales.\n\n\t\t"<<endl;
  623. cout<<" Este juego es sobre un hombre que vende tamales para alimentar a su familia"<<endl;
  624. cout<<" Estas dispuesto a jugarte la vida por un tamal de chicharron?"<<endl;
  625. cout<<" Aceptaras el desafio por alimentar a tu familia?"<<endl;
  626. cout<<" Qieres Saber la historia de este juego? [Y/N]"<<endl;
  627. cin>>  inst;
  628.  
  629. if (inst=='Y' ||inst=='y')
  630. {
  631.               cout<<"Hace tiempo existio un hombre llamado Elias Diaz"<<endl;
  632.               cout<<"Apodado 'El Naco Diaz'"<<endl;
  633.               cout<<"El Naco tenia todo lo que un hombre podia decear..una bonita casa,una hermosa esposa y adorables hijos.."<<endl<<endl;
  634.               cout<<"Pero el destino le dio una mala jugada y perdio casi todo lo que tenia..."<<endl;
  635.               cout<<"El Naco no podia soportar que lo unico que le quedaba su familia muriera de hambre..."<<endl;
  636.               cout<<"Asi que se dispuso a vender el santo grial de la comida del barrio 'Tamales'"<<endl;
  637.               cout<<"Asi fue como El Naco, comenzo su negocio de tamales..pero no contaba con que tendria un rival.."<<endl;
  638.               cout<<"Era un taquero muy famoso en la colonia apodado Don Fito, que no queria que El Naco le robara la clientela"<<endl;
  639.               cout<<"Don Fito,declaro la guerra a El Naco...por la primicia de sus respectivos lugares en el barrio..."<<endl;
  640.               cout<<"Este juego trata sobre eso, el tablero es un mapa del barrio, y para ganar tienes que hacerte de una calle completa..."<<endl;
  641.               cout<<"La idea de este juego es crear una linea perpendicular o paralela para ganar el juego"<<endl;
  642.               cout<<"Las [x] corresponde Al Naco Diaz."<<endl;
  643.               cout<<"Las [O] corresponden Don Fito."<<endl;
  644.               cout<<"Es tu Desicion elegir el personaje que mas te guste para tratar de ganar.."<<endl;
  645.  
  646.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  647.         {
  648.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  649.           {
  650.           }
  651.         }
  652.     cout<<"Este tablero muestra la colonia donde estan ubicados nuestros hombres"<<endl<<endl<<endl;
  653.  
  654.     cout << "\n"<< 0 << " | " << 1 << " | " << 2 << endl;
  655.     cout<< " ---------" << endl;
  656.     cout<< 3 << " | " << 4 << " | " << 5 << endl;
  657.     cout<< " ---------" << endl;
  658.     cout<< 6 << " | " << 7 << " | " << 8 << endl;
  659.  
  660.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  661.         {
  662.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  663.           {
  664.           }
  665.         }
  666.  
  667.  
  668. cout<<" Este juego se juega de la siguiente manera"<<endl<<endl;
  669. cout<<" Primero elejimos el turno.. quien sera eL Naco y quien Don Fito."<<endl;
  670. cout<<" Puedes jugar como el personajes que elijas dando la opcion que quieres."<<endl;
  671. cout<<" Puedes jugar contra la maquina o contra persona, pero esa sera tu eleccion"<<endl<<endl;
  672. cout<<" El juego se juega por coordenadas..."<<endl;
  673. cout<<" 123.columna y 123.linea"<<endl;
  674. cout<<" Trata de ganar la primicia del barrio... Estas Listo??"<<endl;
  675. cout<<" Comenzar el juego??? [Y/N]";
  676. cin>> jum;
  677.  
  678. if (jum=='Y' ||jum=='y')
  679.  
  680.   {
  681.       ttt tictactoe;
  682.   while(tictactoe.new_game());  
  683.  
  684.   }
  685.  
  686.  
  687. }  
  688. return 0;    
  689.  
  690.  return 0;
  691. }
  692.  
  693.  
  694.  
4  Programación / Programación C/C++ / Ayuda Para Completar El Codigo de Tic Tac Toe :S! en: 27 Agosto 2010, 00:38 am
Estoy en primer semestre de Gamming Curriculum, y tengo como proyecto hacer un tic tac toe + la historia, tengo gran parte del codigo, pero me eh bloqueado totalmente.. alguna idea de como continuar?

me falta literalmente lo mas importante.. pero necesito un empujon para seguir;




Código
  1. #include<iostream>
  2. #include<fstream.h>
  3. #include<time.h>
  4. #include <stdlib.h>
  5. #include <windows.h>  
  6. using namespace std;
  7.  
  8. int XOBoard[3][3];     /*global variable board */
  9. class Player          /*Class of Players*/
  10. {
  11. public:
  12.      Player()  
  13.      {
  14.                //CODE
  15.  
  16.      }
  17.      void Draw()          /*Function of Player class to draw the game board  */
  18.      {
  19.  
  20.           cout<<"\n\n\n\n\n";
  21.           cout<<"\t\t\t            Top        ";
  22.                      cout<<"\n\t\t\t***************************\n";
  23.           cout<<"\t\t\t*  .  1       2       3   *\n\t\t\t*.........................*\n";
  24.           if ( XOBoard[0][0] == 0 )      /*If else condition to draw the game board */
  25.           {
  26.              cout<<"\t\t\t* 1.     |";
  27.           }
  28.           else if ( XOBoard[0][0] == 1)
  29.           {
  30.                cout<<"\t\t\t* 1.  X  |";
  31.                }
  32.           else if ( XOBoard[0][0] == -1) {
  33.                cout<<"\t\t\t* 1.  O  |";
  34.                }
  35.           if ( XOBoard[1][0] == 0) {
  36.                cout<<"        |";
  37.                }
  38.           else if ( XOBoard[1][0] == 1) {
  39.                cout<<"    X   |";
  40.                }
  41.           else if ( XOBoard[1][0] == -1) {
  42.                cout<<"    O   |";
  43.                }
  44.           if ( XOBoard[2][0] == 0) {
  45.                cout<<"       *";
  46.                }
  47.           else if ( XOBoard[2][0] == 1) {
  48.                cout<<"   X   *";
  49.           }
  50.           else if ( XOBoard[2][0] == -1) {
  51.                cout<<"   O   *";
  52.                }
  53.           cout<<"\n\t\t\t*  .----------------------*\n";
  54.           if ( XOBoard[0][1] == 0) {
  55.              cout<<"\t\t  Side  * 2.     |";
  56.              }
  57.           else if ( XOBoard[0][1] == 1) {
  58.                cout<<"\t\t  Side  * 2.  X  |";
  59.                }
  60.           else if ( XOBoard[0][1] == -1) {
  61.                cout<<"\t\t  Side  * 2.  O  |";
  62.                }
  63.           if ( XOBoard[1][1] == 0) {
  64.                cout<<"        |";
  65.                }
  66.           else if ( XOBoard[1][1] == 1) {
  67.                cout<<"    X   |";
  68.                }
  69.           else if ( XOBoard[1][1] == -1) {
  70.                cout<<"    O   |";
  71.                }
  72.           if ( XOBoard[2][1] == 0) {
  73.                cout<<"       *";
  74.                }
  75.           else if ( XOBoard[2][1] == 1) {
  76.                cout<<"   X   *";
  77.                }
  78.           else if ( XOBoard[2][1] == -1) {
  79.                cout<<"   O   *";
  80.                }
  81.           cout<<"\n\t\t\t*  .----------------------*\n";
  82.           if ( XOBoard[0][2] == 0) {
  83.              cout<<"\t\t\t* 3.     |";
  84.              }
  85.           else if ( XOBoard[0][2] == 1) {
  86.                cout<<"\t\t\t* 3.  X  |";
  87.                }
  88.           else if ( XOBoard[0][2] == -1) {
  89.                cout<<"\t\t\t* 3.  O  |";
  90.                }
  91.           if ( XOBoard[1][2] == 0) {
  92.                cout<<"        |";
  93.                }
  94.           else if ( XOBoard[1][2] == 1) {
  95.                cout<<"    X   |";
  96.                }
  97.           else if ( XOBoard[1][2] == -1) {
  98.                cout<<"    O   |";
  99.                }
  100.           if ( XOBoard[2][2] == 0) {
  101.                cout<<"       *";
  102.                }
  103.           else if ( XOBoard[2][2] == 1) {
  104.                cout<<"   X   *";
  105.                }
  106.           else if ( XOBoard[2][2] == -1) {
  107.                cout<<"   O   *";
  108.                }
  109.           cout<<"\n\t\t\t***************************\n";
  110.           }
  111.  
  112.      int Human_win()   /*function of class Player to output when user has won*/
  113.      {
  114.                        //code
  115.  return 0;
  116.      }
  117.      int Computer_win()  /*function of class Player to output when computer has won*/
  118.      {
  119.           //code
  120.           return 0;  
  121.      }
  122.      int chkwinner()    
  123.      {
  124.  
  125.           return 0;
  126. }
  127.     void Reset_board ()                                                                  
  128.     {
  129.  
  130.  
  131.     }
  132.     void fill_XOBoard(int column, int row, int move_by)    
  133.     {
  134.  
  135.     }
  136.     bool used_cell_check_for_Human(int column, int row)                                                   /*function of class Player to check whether the cell inout by Player has been occupied earlier or not*/
  137.     {
  138.  
  139.             return true;
  140.     }
  141.      bool used_cell_check_for_Computer(int column, int row)                                                   /*function of class Player to check whether the cell inout by Player has been occupied earlier or not*/
  142.     {
  143.  
  144.             return true;
  145.      }
  146.      int Chk_tie()
  147.      {
  148.  
  149.       return 0;
  150.       }
  151.  
  152.          int chk_cols()                                            
  153.          {
  154.  
  155.           return 0;
  156.           }
  157.  
  158.  
  159.           int chk_rows()      
  160.           {
  161.  
  162.          return 0;
  163.          }
  164.  
  165.  
  166.      int chk_diags()          
  167.      {
  168.  
  169.       return 0;
  170.         }
  171.  
  172.  
  173. };            /*end class Player*/
  174.  
  175. class Human_Player : public Player                                                        
  176. {
  177.  
  178. };            /*end class human*/
  179.  
  180. class Computer_Player: public Player    /*inherited class computer from Player class*/
  181. {
  182.  
  183. };           /*end class computer*/
  184.  
  185.  
  186.  
  187. int main()        /*main function begins*/
  188. {
  189.     Player Play;         /*object of class Player*/
  190.     Human_Player h;     /*object of class human*/
  191.     Computer_Player c;
  192.  
  193.     int trn=1;    /*variable to denote turn of Player*/
  194.     int i=1;
  195.     char ch='y';    /*character to input if Player wants to play again or not*/
  196.     int winner=1;    /*integer to denote winner*/
  197.     int ctrl1,ctrl2;   /*integer to denote winner*/
  198.     int ctr=0;
  199.     int check_for_tie;
  200.     char begin, Instruct;
  201.  
  202.  
  203.         cout<<"\n\n\n\n\n";
  204.  
  205.         cout<<"\n**     **  ********  *******";
  206.         cout<<"\n**     **  ********  ********";
  207.         cout<<"\n**     **  **    **  **    **";
  208.         cout<<"\n**  *  **  ********  *******";
  209.         cout<<"\n** *** **  ********  *******";
  210.         cout<<"\n***   ***  **    **  **    **";
  211.         cout<<"\n**     **  **    **  **    **";
  212.         cout<<"\n\n\n";
  213.         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  214.         {
  215.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  216.           {
  217.           }
  218.           }        
  219.         cout<<"\n\t\t********  ********";
  220.         cout<<"\n\t\t********  ********";
  221.         cout<<"\n\t\t**    **  **";
  222.         cout<<"\n\t\t**    **  *****";
  223.         cout<<"\n\t\t**    **  *****";
  224.         cout<<"\n\t\t********  **";
  225.         cout<<"\n\t\t********  **";
  226.         cout<<"\n\n\n";
  227.         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  228.         {
  229.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  230.           {
  231.           }
  232.           }
  233.         cout<<"\n\t\t\t********  **    **  ********";
  234.         cout<<"\n\t\t\t********  **    **  ********";
  235.         cout<<"\n\t\t\t   **     ********  **";
  236.         cout<<"\n\t\t\t   **     ********  *****";
  237.         cout<<"\n\t\t\t   **     **    **  **";
  238.         cout<<"\n\t\t\t   **     **    **  ********";
  239.         cout<<"\n\t\t\t   **     **    **  ********";
  240.         cout<<"\n\n\n";
  241.         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  242.         {
  243.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  244.           {
  245.           }
  246.           }
  247.         cout<<"\n\t\t\t       **        ********  **    **  *******    *******";
  248.         cout<<"\n\t\t\t       **        ********  ***   **  ********  ********";
  249.         cout<<"\n\t\t\t       **        **    **  ****  **  **    **   **";
  250.         cout<<"\n\t\t\t       **        ********  ** ** **  **    **    **";
  251.         cout<<"\n\t\t\t       **        ********  **  ****  **    **      **";
  252.         cout<<"\n\t\t\t       ********  **    **  **   ***  ********  ********";
  253.         cout<<"\n\t\t\t       ********  **    **  **    **  *******   *******";
  254.  
  255.     cout<<"\n\n\n\n\n\t\t    Welcome to the game WAR OF THE LANDS.\n\n\t\t";    
  256.  
  257.     cout<<"\nHello , I need to tell you the story of War of the Lands. ";
  258.     cout<<"\nDo you want to read the instructions or simply proceede with the game ? \n(R)ead or (P)roceede :";
  259.     cin>>Instruct;
  260.     if (Instruct=='R' ||Instruct=='r')
  261.     {
  262.  
  263.  
  264.  
  265.  
  266.     cout<<"\n\n     A disputed area of 900 square meters lies between two neighboring villages. ";
  267.     cout<<"\n     The dispute between the neighboring villages has been running for  ";
  268.     cout<<"\n     generations. The government has finally taken a decision to resolve  ";
  269.     cout<<"\n     the dispute and grant the possession of this land to one of the ";
  270.     cout<<"\n     villages using a fair method. ";
  271.     cout<<"\n\n\n     The government has divided the disputed land into 9 equal square plots each";
  272.     cout<<"\n     of 300 square meters as shown in the following figure:";
  273.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  274.         {
  275.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  276.           {
  277.           }
  278.           }
  279.     Play.Draw();
  280.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  281.         {
  282.          for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
  283.           {
  284.           }
  285.           }
  286.     cout<<"\n\n     The following method will be used to grant possession of the land to \n     one of the villages: ";      
  287.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  288.         {
  289.          for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
  290.           {
  291.           }
  292.           }
  293.     cout<<"\n\n     The government has decided that the entire land will be given to the \n     village that makes three successful plantations.";
  294.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  295.         {
  296.          for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
  297.           {
  298.           }
  299.           }
  300.     cout<<"\n\n     At one point of time, only one village will plant vegetation on a \n     square plot. Each village will be given a fair chance to grow \n     vegetation in a square block, turn-by-turn.";
  301.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  302.         {
  303.          for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
  304.           {
  305.           }
  306.           }
  307.     cout<<"\n\n     The first village that will plant vegetation on three square plots\n     from one corner to the opposite corner (vertically, horizontally,\n     or diagonally) will be given possession. For example,\n     on plots (1,1), (2,2) and (3,3) or (2,1), (2,2), and (2, 3) and so on";
  308.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  309.         {
  310.          for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
  311.           {
  312.           }
  313.           }
  314.     cout<<"\n\n     Each village can plant in a way to block the other village from planting\n     vegetation in three consecutive plots of land.";
  315.     for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  316.         {
  317.          for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
  318.           {
  319.           }
  320.           }
  321.     cout<<"\n\n     In case all the plots have been planted and neither village has planted\n     threeconsecutive plots of land, the government holds\n     possession of the entire land. Both villages will be then\n     given another chance to restart the plantation all over again.";
  322.          for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
  323.         {
  324.          for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
  325.           {
  326.           }
  327.           }
  328.     cout<<"\n\n     In the current scenario, one village is represented by I, the computer\n     and the other village is by you, that is .\n     The decision that who makes the first move lies with the you.\n     Your plantation will be represented by 'X' on the plot of land\n     and the computer's by 'O'.";      
  329.     cout<<"\n\n     Each player will choose a plot of land by selecting the top and left\n     coordinate pointing to the specific plot of land.";    
  330.     cout<<"\n\n\n\n\n     Go ahead...Press ENTER when you are ready to face the challenge!!!";
  331.     cin.get();
  332.  
  333. }
  334.     while(ch=='y' || ch=='Y')     /*while loop to continue playing until user quits*/
  335.     {
  336.  
  337.     cout<<"\n\n    So, do you want to make the first move or \n    Should I make the first move?\n    Enter (C) if you want me to begin , else press (I): ";
  338.     cin>>begin;
  339.     if (begin=='I'||begin=='i')
  340.     trn=1;
  341.     else if (begin=='c'||begin=='C')
  342.     trn=-1;
  343.  
  344.     do                    /*do wbile loop to continue until there is a winner*/
  345.          {
  346.            Play.Draw();
  347.  
  348.                            /*call function of class Player to draw the XOBoard*/
  349.  
  350.        }while (winner!=1);  
  351.  
  352.            ch='n';
  353.        }
  354.  
  355.        cout<<"\n\n\n\n\n\n\n\n\n\t\tBye bye !!!. See you soon...";
  356.        cin.get();
  357.        system("pause");
  358.        return 0;
  359. }    


Alguna idea?
para completar el codigo?
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines