Advertisement
lorenzo_valentini

Untitled

Feb 17th, 2021
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. constexpr auto W=10;        //altro modo per scrivere #define
  5. constexpr auto H=10;
  6.  
  7. char map[W][H];
  8.  
  9. void init_map(){                        //funzione per stampare la mappa
  10.     for (int i = 0; i < H; i++){        //la coordinata x è uguale alla coordianta y
  11.         for (int j = 0; j < W; j++)     //la coordinata j è uguale alla coordinata x
  12.         {
  13.             map[i][j]='.';
  14.         }
  15.     }
  16. }
  17.  
  18. void print_entity(int , int , char );         //funzione per stampare l'eroe sulla mappa
  19.  
  20. int main(){
  21.     char hero_glyph= '@';
  22.     int hero_j=5, hero_i=5;
  23.     bool running = true;
  24.     cout<<"BENVENUTO NEL GIOCO!\n";
  25.     cout<<"\n";
  26.     cout<<"+================================================+"<<endl;
  27.     cout<<"|                                                |"<<endl;
  28.     cout<<"|                    L'EROE @                    |"<<endl;
  29.     cout<<"|                   VI SALUTA                    |"<<endl;
  30.     cout<<"|                      !!!                       |"<<endl;
  31.     cout<<"|                                                |"<<endl;
  32.     cout<<"+================================================+"<<endl;
  33.     cout<<"\n";
  34.     cout<<"THE END"<<endl;
  35.     cout<<"\n";
  36.  
  37.     //inizializzazione mappa
  38.     init_map();
  39.  
  40.     //posizione eroe nella mappa
  41.     print_entity(hero_j, hero_i, hero_glyph);
  42.  
  43.     while(running){
  44.     //stampa mappa
  45.     for (int i = 0; i < H; i++){        //la coordinata x è uguale alla coordianta y
  46.         for (int j = 0; j < W; j++){    //la coordinata j è uguale alla coordinata x
  47.             cout<<map[i][j];
  48.             }
  49.         cout<<endl;
  50.         }
  51.     char cmd;
  52.     cout<<"\n"<<"> ";
  53.     cin>>cmd;
  54.     if(cmd=='q'){       //interrompere il promt
  55.         running= false;
  56.     }
  57.     cout<<endl;
  58.     }
  59.    
  60.     system("pause");
  61.     return 0;
  62. }
  63.  
  64. void print_entity(int j, int i, char glyph){
  65.     map[i][j]=glyph;        //coordinata y è uguale a i
  66.                             //coordinata x è uguale a j
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement