Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <iomanip>
- #include <ctime>
- const int n=10;
- int maxships=3,ships=0,asse_x,asse_y,x,y,a;
- char map[n][n]={},map1[n][n]={};
- #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 */
- using namespace std;
- void fillmat();
- void fillship();
- void attack();
- void mapshow();
- void fillmat(){
- for(int i =0;i<n;i++)
- for(int j=0;j<n;j++){
- map[i][j]='*';
- map1[i][j]='*';
- }
- }
- void fillship(){
- x=rand()%n+1;
- y=rand()%n+1;
- map1[x][y]='#';
- }
- void mapshow(){
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- cout<<setw(3)<<map[i][j];
- cout<<endl;
- }
- }
- void mapshow1(){
- cout<<x<<" "<<y<<endl;
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- if(map1[x][y]==map1[i][j])
- cout<<setw(3)<<map1[x][y];
- else
- cout<<setw(3)<<map1[i][j];
- cout<<endl;
- }
- }
- void attack(){
- do{
- a:
- 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<<GREEN<<"\n\n\n\nVINTO"<<endl;
- a++;
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- cout<<" "<<GREEN<< map1[i][j]<<RESET;
- cout<<endl;
- }
- }
- else
- {
- cout<<RED<<"\n\n\nFallito il tentativo"<<endl;
- // map[asse_x][asse_y]='*';
- for(int i =0;i<n;i++){
- for(int j=0;j<n;j++)
- //if(map[asse_x][asse_y]==map[i][j])
- //cout<<RED<<setw(3)<< map[i][j]<<RESET;
- //else
- cout<<CYAN<<setw(3)<< map[i][j]<<RESET;
- cout<<endl;
- }
- }
- if(map1[asse_x][asse_y]== map1[x][y])
- break;
- }while(1);
- }
- int main(){
- mapshow();
- fillmat();
- fillship();
- mapshow1();cout<<"\n\n\n\n\n";
- attack();
- mapshow();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment