Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <iomanip>
- #include <ctime>
- using namespace std;
- int main(){
- system("clear");
- #define RESET "\033[0m"
- #define BLACK "\033[30m" /* Black */
- #define RED "\033[31m" /* Red */
- #define GREEN "\033[32m" /* Green */
- #define YELLOW "\033[33m" /* Yellow */
- #define BLUE "\033[34m" /* Blue */
- #define MAGENTA "\033[35m" /* Magenta */
- #define CYAN "\033[36m" /* Cyan */
- #define WHITE "\033[37m" /* White */
- #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
- #define BOLDRED "\033[1m\033[31m" /* Bold Red */
- #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
- #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
- #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
- #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
- #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
- #define BOLDWHITE "\033[1m\033[37m" /* Bold White */
- const int n=10;
- int maxships=3,ships=0,asse_x,asse_y,x,y,a;
- char map1[n][n]={},map2[n][n]={};
- srand(time(0));
- char map[n][n]={};
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- map[i][j]='*';
- }
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- map1[i][j]='*';
- }
- {
- x=rand()%n;
- y=rand()%n;
- map1[x][y]='#';
- }
- cout<<x<<" "<<y<<endl;
- cout<< " ♣ Battaglia Navale ♣\n\n\n"<<endl;
- // Stampa solo per la prima volta or stampa la mare
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- cout<<CYAN<<setw(3)<< map[i][j]<<RESET;
- cout<<endl;
- }
- //attack or guess
- do{
- asse_x=0;asse_y=0;
- cout<<"Insersci la coordinata di righa (numero intero): ";
- cin>>asse_x;
- cout<<"Insersci la coordinata in colonna (numero intero):";
- cin>>asse_y;
- if(map1[asse_x][asse_y]== map1[x][y]){
- cout<<BOLDGREEN<<"\n\n\n"<<setw(23)<<"VINTO\n\n"<<RESET<<endl;
- a++;
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- if(map1[asse_x][asse_y]!=map1[i][j])
- cout<<" "<<CYAN<< map1[i][j]<<RESET;
- else
- cout<<BOLDGREEN<<setw(3)<< map[x][y]<<RESET;
- cout<<endl;
- }
- }
- else
- {
- cout<<BLUE<<"\n\n\n"<<"Fallito il Tentativo\n\n"<<endl;
- cout<<RESET;
- map[asse_x][asse_y]='o';
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- if(map[i][j]==map[asse_x][asse_y])
- cout<<CYAN<<setw(3)<< map[i][j]<<RESET;
- else
- cout<<YELLOW<<setw(3)<< map[i][j]<<RESET;
- cout<<endl;
- }
- }
- if(map1[asse_x][asse_y]== map1[x][y])
- break;
- }while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment