Phoenix_Hijacker

Tris

Apr 7th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.     char map[3][3]={{'-','-','-'},
  5.                 {'-','-','-'},
  6.                 {'-','-','-'}};
  7.     int r,c,p1_count,p2_count,win,loss;
  8.     string p1,p2;
  9.     int main (){
  10.     p1="test";
  11.     p2="test1";
  12.     p1_count=p2_count=win=0;
  13.    
  14.    
  15.     for(int i=0;i<3;i++){
  16.         for(int j=0;j<3;j++)
  17.             cout <<map[i][j]<<"|";
  18.             cout<<endl;        
  19.     }
  20.    
  21.     //Get coordinates
  22.     do{
  23.    
  24.         do{
  25.             cout<<p1<< " Turn\n\n"<<endl;
  26.             do{
  27.                 cout << "Riga p1: " ;
  28.                 cin >> r;
  29.                 // check for valid input
  30.                 if (r > 2 || r < 0)
  31.                 cout << "scegli riga tra  0, 1, or 2 : " ;
  32.             }while (r > 2 || r < 0);
  33.            
  34.             do{
  35.                 cout<<"Colonna p1: " ;
  36.                 cin >> c;
  37.                 // check for valid input
  38.                 if (c > 2 || c < 0)
  39.                 cout << "Scegli colonna tra 0, 1, or 2: ";
  40.             } while (c > 2 || c < 0);
  41.            
  42.             if(map[r][c]=='-')
  43.                 map[r][c]='X';
  44.             else
  45.                 cout<< "Field Already Full. Reinsert"<<endl;
  46.         }while(!map[r][c]=='X');
  47.             for(int i=0;i<3;i++){
  48.                 for(int j=0;j<3;j++)
  49.                     cout <<map[i][j]<<"|";
  50.                     cout<<endl;            
  51.             }
  52.             cout<<"\n\n"<<endl;
  53.            
  54.             if((map[0][0]== 'X' && map[0][1]== 'X' && map[0][2] == 'X')||
  55.                (map[1][0]== 'X' && map[1][1]== 'X' && map[1][2] == 'X')||
  56.              (map[2][0]== 'X' && map[2][1]== 'X' && map[2][2] == 'X')||
  57.              (map[0][0]== 'X' && map[1][0]== 'X' && map[2][0] == 'X')||
  58.              (map[0][1]== 'X' && map[1][1]== 'X' && map[2][1] == 'X')||
  59.              (map[0][2]== 'X' && map[1][2]== 'X' && map[2][2] == 'X')||
  60.              (map[0][0]== 'X' && map[1][1]== 'X' && map[2][2] == 'X')||
  61.              (map[0][2]== 'X' && map[1][1]== 'X' && map[2][0] == 'X' )){
  62.                 cout<<p1<<" Won"<<endl;
  63.                 p1_count=1;
  64.                 break;
  65.             }
  66.         do{
  67.             cout<<p2<< " Turn\n\n"<<endl;
  68.             do{
  69.                 cout << "Riga p2: " ;
  70.                 cin >> r;
  71.                 // check for valid input
  72.                 if (r > 2 || r < 0)
  73.                 cout << "scegli riga tra  0, 1, or 2 : " ;
  74.             }while (r > 2 || r < 0);
  75.            
  76.             do{
  77.                 cout<<"Colonna p2: " ;
  78.                 cin >> c;
  79.                 // check for valid input
  80.                 if (c > 2 || c < 0)
  81.                 cout << "Scegli colonna tra 0, 1, or 2: ";
  82.             } while (c > 2 || c < 0);
  83.            
  84.             if(map[r][c]=='-')
  85.                 map[r][c]='o';
  86.             else
  87.                 cout<< "Field Already Full. Reinsert"<<endl;
  88.         }while(map[r][c]=='X');
  89.            
  90.             for(int i=0;i<3;i++){
  91.                 for(int j=0;j<3;j++)
  92.                     cout <<map[i][j]<<"|";
  93.                     cout<<endl;        
  94.             }
  95.             cout<<"\n\n"<<endl;
  96.             if((map[0][0]== 'o' && map[0][1]== 'o' && map[0][2] == 'o')||
  97.              (map[1][0]== 'o' && map[1][1]== 'o' && map[1][2] == 'o')||
  98.              (map[2][0]== 'o' && map[2][1]== 'o' && map[2][2] == 'o')||
  99.              (map[0][0]== 'o' && map[1][0]== 'o' && map[2][0] == 'o')||
  100.              (map[0][1]== 'o' && map[1][1]== 'o' && map[2][1] == 'o')||
  101.              (map[0][2]== 'o' && map[1][2]== 'o' && map[2][2] == 'o')||
  102.              (map[0][0]== 'o' && map[1][1]== 'o' && map[2][2] == 'o')||
  103.              (map[0][2]== 'o' && map[1][1]== 'o' && map[2][0] == 'o' )){
  104.                 cout<<p2<<" Won"<<endl;
  105.                 p2_count=1;
  106.                 break;
  107.             }
  108.             cout<<win<<endl;
  109.            
  110.     }while(!(win==1)); 
  111.    
  112.     return 0;  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment