Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: xcoverdalex en 27 Agosto 2010, 00:38 am



Título: Ayuda Para Completar El Codigo de Tic Tac Toe :S!
Publicado por: xcoverdalex 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?