Advertisement
MiDo3

TicTacToe (fun.cpp)

Jan 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.66 KB | None | 0 0
  1. #include "fun.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. Game::Game(){
  5.     system("COLOR 8c");
  6. }
  7.  
  8. char Game::check[3][3];
  9. Game::Game(int i,char p ,int s):input(i),player(p),score(&s){
  10. status = false;
  11. status3= false;
  12. status4= false;
  13. system("COLOR 4f");
  14. }
  15.  
  16.  
  17. void Game::setup(){
  18.  
  19.     if(input<4 && check[0][input-1]==NULL)
  20.         check[0][input-1]= player;
  21.     else if(input>=4 && input<=6 && check[1][input-4]==NULL)
  22.         check[1][input-4] = player;
  23.         else if(input>=7 && check[2][input-7]==NULL)
  24.             check[2][input-7] = player;
  25.         else{
  26.         std::cout<<"this element not empty try again"<<std::endl;
  27.          status3 = true;
  28.         }
  29.         for(int x=0; x<3; x++){
  30.             std::cout<<"-------------"<<std::endl;
  31.             for(int d=0; d<3; d++){
  32.                 if(d!=0)
  33.                 std::cout<<" ";
  34.                 std::cout<<"| ";
  35.                 std::cout<<check[x][d];
  36.                 if(d==2)
  37.                 std::cout<<" |";
  38.  
  39.             }
  40.  
  41.             std::cout<<std::endl;
  42.               if(x==2)
  43. std::cout<<"-------------"<<std::endl;
  44.         }
  45.  
  46. }
  47.  
  48. void Game::PanelNum(){
  49.      int counter = 0;
  50.     for(int y=0; y<3; y++){
  51.  
  52.         std::cout<<"-------------"<<std::endl;
  53.  
  54.  
  55.         for(int g=0; g<3; g++){
  56.             if(g!=0)
  57.                 std::cout<<" ";
  58.             std::cout<<"| ";
  59.             std::cout<<++counter;
  60.             if(g==2)
  61.             std::cout<<" |";
  62.  
  63. }
  64. std::cout<<std::endl;
  65.          if(y==2)
  66. std::cout<<"-------------"<<std::endl;
  67. }
  68.  
  69. }
  70.  
  71. void Game::win(){
  72.     using namespace std;
  73.      for(int t=0; t<3; t++){
  74.                         for(int q=0; q<3; q++){
  75.                             win2[t][q] = check[t][q];
  76.                         }
  77.                     }
  78.  
  79.  
  80.     if(win2[0][0]==player&&win2[0][1]==player&&win2[0][2]==player){
  81.                 //Player win
  82.             ++*score;
  83.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  84.                     for(int t=0; t<3; t++){
  85.                         for(int q=0; q<3; q++){
  86.                             win2[t][q] = NULL;
  87.                             check[t][q] = NULL;
  88.                         }
  89.                     }
  90.                     status = true;
  91.                 }
  92.             else if(win2[0][0]==player&&win2[1][1]==player&&win2[2][2]==player){
  93.                   //Player win
  94.                 ++*score;
  95.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  96.                     for(int t=0; t<3; t++){
  97.                         for(int q=0; q<3; q++){
  98.                             win2[t][q] = NULL;
  99.                             check[t][q] = NULL;
  100.                         }
  101.                     }
  102.                 status = true;
  103.     }
  104.            else if(win2[2][0]==player&&win2[1][1]==player&&win2[0][2]==player){
  105.                   //Player win
  106.               ++*score;
  107.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  108.                     for(int t=0; t<3; t++){
  109.                         for(int q=0; q<3; q++){
  110.                             win2[t][q] = NULL;
  111.                             check[t][q] = NULL;
  112.                         }
  113.                     }
  114.                     status = true;
  115.     }
  116.                  else if(win2[1][0]==player&&win2[1][1]==player&&win2[1][2]==player){
  117.                   //Player win
  118.                ++*score;
  119.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  120.                     for(int t=0; t<3; t++){
  121.                         for(int q=0; q<3; q++){
  122.                             win2[t][q] = NULL;
  123.                             check[t][q] = NULL;
  124.                         }
  125.                     }
  126.                     status = true;
  127.     }
  128.                 else if(win2[2][0]==player&&win2[2][1]==player&&win2[2][2]==player){
  129.                   //Player win
  130.                     ++*score;
  131.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  132.                     for(int t=0; t<3; t++){
  133.                         for(int q=0; q<3; q++){
  134.                             win2[t][q] = NULL;
  135.                             check[t][q] = NULL;
  136.                         }
  137.                     }
  138.                     status = true;
  139.                 }
  140.                     else if(win2[0][0]==player&&win2[1][0]==player&&win2[2][0]==player){
  141.                   //Player win
  142.                     ++*score;
  143.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  144.                     for(int t=0; t<3; t++){
  145.                         for(int q=0; q<3; q++){
  146.                             win2[t][q] = NULL;
  147.                             check[t][q] = NULL;
  148.                         }
  149.                     }
  150.                     status = true;
  151.     }
  152.         else if(win2[0][1]==player&&win2[1][1]==player&&win2[2][1]==player){
  153.                   //Player win
  154.                     ++*score;
  155.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  156.                     for(int t=0; t<3; t++){
  157.                         for(int q=0; q<3; q++){
  158.                             win2[t][q] = NULL;
  159.                             check[t][q] = NULL;
  160.                         }
  161.                     }
  162.                     status = true;
  163.     }
  164.         else if(win2[0][2]==player&&win2[1][2]==player&&win2[2][2]==player){
  165.                   //Player win
  166.                     ++*score;
  167.                     cout<<"Player " <<player<<" WIN PLAY AGAIN.."<<endl;
  168.                     for(int t=0; t<3; t++){
  169.                         for(int q=0; q<3; q++){
  170.                             win2[t][q] = NULL;
  171.                             check[t][q] = NULL;
  172.                         }
  173.                     }
  174.                     status = true;
  175.     }
  176.         //GameOver
  177.         else if(win2[0][0]!=NULL && win2[0][1]!=NULL  && win2[0][2]!=NULL  && win2[1][0]!=NULL &&
  178.             win2[1][1]!=NULL  && win2[1][2]!=NULL  && win2[2][0]!=NULL && win2[2][1]!=NULL &&
  179.             win2[2][2]!=NULL){
  180.         std::cout<<"Game over 'No one win'.."<<std::endl;
  181.             for(int t=0; t<3; t++){
  182.             for(int q=0; q<3; q++){
  183.         win2[t][q]= NULL;
  184.         check[t][q]=NULL;
  185.             }
  186.             }
  187.             status4= true;
  188. }
  189.     }
  190.  
  191. int Game::Scores(){
  192.  
  193.     return *score;
  194. }
  195. bool Game::status2(){
  196.     return status3;
  197. }
  198. bool Game::status5(){
  199.     return status4;
  200. }
  201. bool Game::status1(){
  202.     return status;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement