Phoenix_Hijacker

battleshit_ship_1v.cpp

Feb 26th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <iomanip>
  4. #include <ctime>
  5. const int n=10;
  6. int maxships=3,ships=0,asse_x,asse_y,x,y,a;
  7. char map[n][n]={},map1[n][n]={};
  8.        
  9.         #define RESET   "\033[0m"
  10.     #define BLACK   "\033[30m"      /* Black */
  11.     #define RED     "\033[31m"      /* Red */
  12.     #define GREEN   "\033[32m"      /* Green */
  13.     #define YELLOW  "\033[33m"      /* Yellow */
  14.     #define BLUE    "\033[34m"      /* Blue */
  15.     #define MAGENTA "\033[35m"      /* Magenta */
  16.     #define CYAN    "\033[36m"      /* Cyan */
  17.     #define WHITE   "\033[37m"      /* White */
  18.     #define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
  19.     #define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
  20.     #define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
  21.     #define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
  22.     #define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
  23.     #define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
  24.     #define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
  25.     #define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
  26.  
  27.  
  28.  
  29. using namespace std;
  30.  
  31.  
  32. void fillmat();
  33. void fillship();
  34. void attack();
  35. void mapshow();
  36.  
  37. void fillmat(){
  38.    for(int i =0;i<n;i++)
  39.       for(int j=0;j<n;j++){
  40.      map[i][j]='*';
  41.          map1[i][j]='*';
  42.    }
  43. }
  44.  
  45.  
  46. void fillship(){
  47.  
  48.     x=rand()%n+1;
  49.     y=rand()%n+1;  
  50.     map1[x][y]='#';
  51.  
  52. }
  53.  
  54.  
  55. void mapshow(){
  56.   for(int i =0;i<n;i++){
  57.       for(int j=0;j<n;j++)
  58.      cout<<setw(3)<<map[i][j];
  59.       cout<<endl;
  60.   }
  61. }
  62.  
  63. void mapshow1(){
  64.    cout<<x<<" "<<y<<endl;
  65.    for(int i =0;i<n;i++){
  66.       for(int j=0;j<n;j++)
  67.          if(map1[x][y]==map1[i][j])
  68.         cout<<setw(3)<<map1[x][y];
  69.          else
  70.             cout<<setw(3)<<map1[i][j];
  71.       cout<<endl;
  72. }
  73. }
  74.  
  75. void attack(){
  76. do{
  77.     a:
  78.     cout<<"Insersci la coordinata di righa (numero intero): ";cin>>asse_x;
  79.     cout<<"Insersci la coordinata in colonna (numero intero):";cin>>asse_y;
  80.  
  81.     if(map1[asse_x][asse_y]== map1[x][y]){
  82.        cout<<GREEN<<"\n\n\n\nVINTO"<<endl;     
  83.        a++;
  84.            for(int i =0;i<n;i++){
  85.           for(int j=0;j<n;j++)
  86.             cout<<"  "<<GREEN<< map1[i][j]<<RESET;
  87.           cout<<endl;  
  88.          
  89.            }
  90.  
  91.     }
  92.        
  93.     else
  94.     {
  95.       cout<<RED<<"\n\n\nFallito il tentativo"<<endl;
  96.      // map[asse_x][asse_y]='*';
  97.           for(int i =0;i<n;i++){
  98.         for(int j=0;j<n;j++)
  99.                //if(map[asse_x][asse_y]==map[i][j])
  100.              //cout<<RED<<setw(3)<< map[i][j]<<RESET;
  101.                //else
  102.                 cout<<CYAN<<setw(3)<< map[i][j]<<RESET;
  103.         cout<<endl;  
  104.            
  105.          }
  106.        
  107.            
  108.     }
  109.  
  110.     if(map1[asse_x][asse_y]== map1[x][y])
  111.        break;      
  112.     }while(1);
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. int main(){
  121. mapshow();
  122. fillmat();
  123. fillship();
  124. mapshow1();cout<<"\n\n\n\n\n";
  125.  
  126. attack();
  127. mapshow();
  128. return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment