Facebook
From Colorant Penguin, 9 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 695
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <cstdlib>
  4. #include <iomanip>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. void rysuj_menu_gl(){
  10.         system("cls");
  11.         cout<<"\t \t Menu glowne"<<endl<<"1. Nowa Gra"<<endl<<"2. Wyswietl Pomoc"<<endl<<"3. Wyjscie"<<endl;
  12. }
  13.  
  14. void rysuj_menu_ng(){
  15.         system("cls");
  16.         cout<<"\t \t Wybor planszy"<<endl<<"1. Plansza nr 1"<<endl<<"2. Plansza nr 2"<<endl<<"3. Plansza nr 3"<<endl<<"Backspace - powrot";
  17. }
  18.  
  19. void pomoc(){
  20.         do {
  21.                 system("cls");
  22.                 cout<<"\t \t Pomoc"<<endl;
  23.                 cout<<"Do poruszania sie po menu uzywaj klawiszy 1, 2, 3"<<endl;
  24.                 cout<<"Do cofniecia sie do poprzedniego ekranu sluzy klawisz backspace"<<endl;
  25.                 cout<<"Podczas gry do poruszania 'R' sluza klawisze:"<<endl;
  26.                 cout<<"w - w gore"<<endl;
  27.                 cout<<"s - w dol"<<endl;
  28.                 cout<<"a - w lewo"<<endl;
  29.                 cout<<"d - w prawo"<<endl;
  30.                 cout<<"Mozliwe jest takze uzyskanie pomocy poprzez wprowadzenie '?'"<<endl;            
  31.         } while ((getch()!=8) and getch()!=27);
  32. }
  33.  
  34. void sterowanie(char plansza1[15][15], int poz_R_j, int poz_R_i, int poz_x_j, int poz_x_i, int poz_0_j, int poz_0_i){
  35.         do {
  36.                 system("cls");
  37.                 string akcja;
  38.                 for (int j=0; j<15; j++){
  39.                         for (int i=0; i<15; i++){
  40.                                 cout<<plansza1[j][i];
  41.                         }
  42.                         cout<<endl;
  43.                 }
  44.                 cin>>akcja;
  45.                 for (int i=0; i<akcja.length(); i++){
  46.                         switch(akcja[i]){
  47.                                 case 'd':
  48.                                         if (plansza1[(poz_R_j)][poz_R_i+1]==' '){
  49.                                                 plansza1[(poz_R_j)][poz_R_i+1]='R';
  50.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  51.                                                 poz_R_i++;
  52.                                         } else if (plansza1[(poz_R_j)][poz_R_i+1]=='x' and plansza1[(poz_R_j)][poz_R_i+2]==' '){
  53.                                                 plansza1[(poz_R_j)][poz_R_i+1]='R';
  54.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  55.                                                 plansza1[(poz_x_j)][poz_x_i+1]='x';
  56.                                                 poz_x_i++;
  57.                                                 poz_R_i++;                                             
  58.                                         } else if (plansza1[(poz_R_j)][poz_R_i+1]=='x' and plansza1[(poz_R_j)][poz_R_i+2]=='0'){
  59.                                                 plansza1[(poz_R_j)][poz_R_i+1]='R';
  60.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  61.                                                 plansza1[(poz_x_j)][poz_x_i+1]='X';
  62.                                                 poz_x_i++;
  63.                                                 poz_R_i++;
  64.                                         }
  65.                                         break;
  66.                                 case 'w':
  67.                                         if (plansza1[(poz_R_j-1)][poz_R_i]==' '){
  68.                                                 plansza1[(poz_R_j-1)][poz_R_i]='R';
  69.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  70.                                                 poz_R_j--;
  71.                                         } else if (plansza1[(poz_R_j-1)][poz_R_i]=='x' and plansza1[(poz_R_j-2)][poz_R_i]==' '){
  72.                                                 plansza1[(poz_R_j-1)][poz_R_i]='R';
  73.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  74.                                                 plansza1[(poz_x_j-1)][poz_x_i]='x';
  75.                                                 poz_x_j--;
  76.                                                 poz_R_j--;                                             
  77.                                         } else if (plansza1[(poz_R_j-1)][poz_R_i]=='x' and plansza1[(poz_R_j-2)][poz_R_i]=='0'){
  78.                                                 plansza1[(poz_R_j-1)][poz_R_i]='R';
  79.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  80.                                                 plansza1[(poz_x_j-1)][poz_x_i]='X';
  81.                                                 poz_x_j--;
  82.                                                 poz_R_j--;                                             
  83.                                         }
  84.                                         break;
  85.                                 case 's':
  86.                                         if (plansza1[(poz_R_j+1)][poz_R_i]==' '){
  87.                                                 plansza1[(poz_R_j+1)][poz_R_i]='R';
  88.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  89.                                                 poz_R_j++;
  90.                                         } else if (plansza1[(poz_R_j+1)][poz_R_i]=='x' and plansza1[(poz_R_j+2)][poz_R_i]==' '){
  91.                                                 plansza1[(poz_R_j+1)][poz_R_i]='R';
  92.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  93.                                                 plansza1[(poz_x_j+1)][poz_x_i]='x';
  94.                                                 poz_x_j++;
  95.                                                 poz_R_j++;                                                     
  96.                                         } else if (plansza1[(poz_R_j+1)][poz_R_i]=='x' and plansza1[(poz_R_j+2)][poz_R_i]=='0'){
  97.                                                 plansza1[(poz_R_j+1)][poz_R_i]='R';
  98.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  99.                                                 plansza1[(poz_x_j+1)][poz_x_i]='X';
  100.                                                 poz_x_j++;
  101.                                                 poz_R_j++;
  102.                                         }
  103.                                         break;
  104.                                 case 'a':
  105.                                         if (plansza1[(poz_R_j)][poz_R_i-1]==' '){
  106.                                                 plansza1[(poz_R_j)][poz_R_i-1]='R';
  107.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  108.                                                 poz_R_i--;
  109.                                         } else if (plansza1[(poz_R_j)][poz_R_i-1]=='x' and plansza1[(poz_R_j)][poz_R_i-2]==' '){
  110.                                                 plansza1[(poz_R_j)][poz_R_i-1]='R';
  111.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  112.                                                 plansza1[(poz_x_j)][poz_x_i-1]='x';
  113.                                                 poz_x_i--;
  114.                                                 poz_R_i--;                                             
  115.                                         } else if (plansza1[(poz_R_j)][poz_R_i-1]=='x' and plansza1[(poz_R_j)][poz_R_i-2]=='0'){
  116.                                                 plansza1[(poz_R_j)][poz_R_i-1]='R';
  117.                                                 plansza1[poz_R_j][poz_R_i]=' ';
  118.                                                 plansza1[(poz_x_j)][poz_x_i-1]='X';
  119.                                                 poz_x_i--;
  120.                                                 poz_R_i--;
  121.                                         }
  122.                                         break;
  123.                                 case '?':
  124.                                         pomoc();
  125.                                         break;
  126.                                 default:
  127.                                         break;
  128.                         }
  129.                 }
  130.         } while ((poz_x_i!=poz_0_i) or (poz_x_j!=poz_0_j));
  131.         system("cls");
  132.         for (int j=0; j<15; j++){
  133.                 for (int i=0; i<15; i++){
  134.                         cout<<plansza1[j][i];
  135.                 }
  136.                 cout<<endl;
  137.         }
  138.         cout<<"GRATULACJE! WYGRALES!"<<endl<<"Nacisnij backspace zeby wrocic do menu glownego albo esc zeby wyjsc";
  139. }
  140.  
  141. void plansza_1(){
  142.         char plansza1[15][15] = {
  143.                 {' ', ' ', ' ', ' ', ' ', 0xC9, 0xCD, 0xBB, ' ', ' ', ' ', ' '},
  144.                 {' ', ' ', ' ', ' ', ' ', 0xBA, ' ', 0xBA, ' ', ' ', ' ', ' '},
  145.                 {' ', ' ', ' ', 0xC9, 0xCD, 0xBC, ' ', 0xC8, 0xCD, 0xCD, 0xCD, 0xBB},
  146.                 {' ', ' ', ' ', 0xBA, ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0xBA},
  147.                 {0xC9, 0xCD, 0xCD, 0xBC, ' ', ' ', ' ', ' ', ' ', ' ', '0', 0xBA},
  148.                 {0xBA, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0xBA},
  149.                 {0xBA, 'R', ' ', ' ', ' ', ' ', 'x', 0xC9, 0xCD, 0xBB, ' ', 0xBA},
  150.                 {0xBA, ' ', ' ', ' ', ' ', ' ', ' ', 0xBA, ' ', 0xBA, ' ', 0xBA},
  151.                 {0xC8, 0xCD, 0xCD, 0xCD, 0xBB, ' ', ' ', 0xBA, ' ', 0xBA, ' ', 0xBA},
  152.                 {' ', ' ', ' ', ' ', 0xBA, ' ', ' ', 0xBA, ' ', 0xBA, ' ', 0xBA},
  153.                 {' ', ' ', ' ', ' ', 0xBA, ' ', ' ', 0xC8, 0xCD, 0xBC, ' ', 0xBA},
  154.                 {' ', ' ', ' ', ' ', 0xBA, ' ', ' ', ' ', ' ', ' ', ' ', 0xBA},
  155.                 {' ', ' ', ' ', ' ', 0xBA, ' ', ' ', ' ', ' ', ' ', ' ', 0xBA},
  156.                 {' ', ' ', ' ', ' ', 0xC8, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xBC},
  157.         };
  158.         int poz_R_j=6;
  159.         int poz_R_i=1;
  160.         int poz_x_j=6;
  161.         int poz_x_i=6; 
  162.         int poz_0_j=4;
  163.         int poz_0_i=10;
  164.         sterowanie (plansza1, poz_R_j, poz_R_i, poz_x_j, poz_x_i, poz_0_j, poz_0_i);
  165. }
  166.  
  167. int main(){
  168.         do {
  169.                 rysuj_menu_gl();
  170.                 switch (getch()) {
  171.                         case 49:
  172.                                 rysuj_menu_ng();
  173.                                         do {
  174.                                                 switch (getch()) {
  175.                                                         case 49:
  176.                                                                 plansza_1();
  177.                                                                 break;
  178.                                                         case 50:
  179.                                                                 //plansza_2();
  180.                                                                 break;
  181.                                                         case 51:
  182.                                                                 //plansza_3();
  183.                                                                 break;
  184.                                                         default:
  185.                                                                 break;
  186.                                                 }
  187.                                         } while ((getch()!=8) and getch()!=27);
  188.                                 break;
  189.                         case 50:
  190.                                 pomoc();
  191.                                 break;
  192.                         case 51:
  193.                                 return 0;
  194.                                 break;
  195.                         default:
  196.                                 break;
  197.                 }
  198.         } while (getch()!=27);
  199.         return 0;
  200. }