Results 1 to 5 of 5

Thread: Source C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: May:2008
    Location: varna
    Posts: 82

    Source C++

    ,
    , ( - ).
    .

    , ( , ) ( ) . , ,

    :

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    string point;
    int player;
    int win=0,lp=0;
    string playerXoO;
    string xy=" ",xy1=" ",xy2=" ";
    string x1y=" ",x1y1=" ",x1y2=" ";
    string x2y=" ",x2y1=" ",x2y2=" ";
    
    void table() {
                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11); 
                 cout << "Now Play Player: " << player << " !" << endl;
                 cout << "\n\n";
                 cout << "       y " << "    y1 " << "   y2 " << endl;
                 cout << "     _________________" << endl << endl;
                 cout << "x      " << xy << "  |  " << xy1 << "  |  " << xy2 << "  " << endl;
                 cout << "     -----|-----|-----" << endl;
                 cout << "x1     " << x1y << "  |  " << x1y1 << "  |  " << x1y2 << "  " << endl;
                 cout << "     -----|-----|-----" << endl;
                 cout << "x2     " << x2y << "  |  " << x2y1 << "  |  " << x2y2 << "  " << endl;
                 cout << "     _________________" << endl << endl;
                 cout << endl;
    }
    
    int game(void) {
         if (player == 1) { playerXoO="x"; }
         else playerXoO="o";
    
         while(! win==1) {
                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
                 lp++;
                 if (player==2) { playerXoO="o"; }
                 if (player==1) { playerXoO="x"; }
                 cin >> point;
                 system("cls");
    
                 if(point.size() > 4) { cout << "Only 2 Simbol's: xy,xy1,xy2,x1y,x1y1,x1y2,x2y,x2y1,x2y2: "; cin >> point; }
    
                 if(point=="xy" && xy == " ") { xy=playerXoO; }
                 else if(point=="xy1" && xy1 == " ") { xy1=playerXoO; }
                 else if(point=="xy2" && xy2 == " ") { xy2=playerXoO; }
                 else if(point=="x1y" && x1y == " ") { x1y=playerXoO; }
                 else if(point=="x1y1" && x1y1 == " ") { x1y1=playerXoO; }
                 else if(point=="x1y2" && x1y2 == " ") { x1y2=playerXoO; }
                 else if(point=="x2y" && x2y == " ") { x2y=playerXoO; }
                 else if(point=="x2y1" && x2y1 == " ") { x2y1=playerXoO; }
                 else if(point=="x2y2" && x2y2 == " ") { x2y2=playerXoO; }
                 else { cout << "That Not Possoble\n\n"; lp=lp-2; 
                 if (player == 1) { player = 2; }
                 else if (player == 2) { player = 1; } 
                 }
                 table();
    
                 if (xy==playerXoO && x1y1==playerXoO && x2y2==playerXoO || 
                     xy==playerXoO && x1y==playerXoO && x2y==playerXoO || 
                     xy==playerXoO && xy1==playerXoO && xy2==playerXoO || 
                     x1y==playerXoO && x1y1==playerXoO && x1y2==playerXoO || 
                     x2y==playerXoO && x2y1==playerXoO && x2y2==playerXoO ||
                     xy1==playerXoO && x1y1==playerXoO && x2y1==playerXoO ||
                     xy2==playerXoO && x1y2==playerXoO && x2y2==playerXoO ||
                     xy2==playerXoO && x1y1==playerXoO && x2y==playerXoO) { 
                                lp=0; cout << "Player " << player << " Win!!! :)\n\n" << endl; 
                                xy=" ",xy1=" ",xy2=" ",x1y=" ",x1y1=" ",x1y2=" ",x2y=" ",x2y1=" ",x2y2=" "; 
                                system("pause"); system("cls"); break;
                                }
    
                 if (lp >= 16) { lp =0; cout << "No Winner! :(\n\n" << endl; 
                                xy=" ",xy1=" ",xy2=" ",x1y=" ",x1y1=" ",x1y2=" ",x2y=" ",x2y1=" ",x2y2=" "; 
                                system("pause"); system("cls"); break;
                                }
    
                 if (player == 1) { player = 2; }
                 else if (player == 2) { player = 1; }
                 lp++;
                 }
    }
    int main() {
             system("cls");
             cout << "Tic-Tac-Toe By NoFeAr\n\n"; 
             SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
             cout << "Select Player:" << endl; 
             cout << "1 for X\n"  << "2 for O" << endl;
             cin >> player;
             if (player != 1 && player != 2) { main(); } 
             system("cls");
             table();
             game();
             if (point=="") { return 0; }
             return main();
    }

  2. #2
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    system(''cls") . , , .
    Code:
    void cls(HANDLE hConsole){
    
       COORD coordScreen = { 0, 0 }; 
       DWORD cCharsWritten;
       CONSOLE_SCREEN_BUFFER_INFO csbil; 
       DWORD dwConSize;
    
       if(!GetConsoleScreenBufferInfo(hConsole, &csbil))
          return;
       dwConSize = csbil.dwSize.X * csbil.dwSize.Y;
    
       if(!FillConsoleOutputCharacter(hConsole, (TCHAR)' ',
          dwConSize, coordScreen, &cCharsWritten))
          return;
    
       if(!GetConsoleScreenBufferInfo( hConsole, &csbil))
          return;
    
       if(!FillConsoleOutputAttribute( hConsole, csbil.wAttributes,
          dwConSize, coordScreen, &cCharsWritten))
          return;
    
       SetConsoleCursorPosition(hConsole, coordScreen);
    }
    :
    Code:
    cls(GetStdHandle(STD_OUTPUT_HANDLE))
    , GetStdHandle(STD_OUTPUT_HANDLE) .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  3. #3
    Registered User
    Join Date: May:2008
    Location: varna
    Posts: 82
    ,
    windows?

  4. #4
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    rabut,

    , , , ( refactor, ).

    - -, 3x3. .

  5. #5
    Registered User
    Join Date: Oct:2006
    Location: Plovdiv
    Posts: 305
    +1 ( bombera pheoman)

    - , "cls" - ++ batch , ?

    .
    prepBut nI vrbLike adjHungarian! qWhat's artThe adjBig nProblem?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |