Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- const char kolumny = 20, wiersze = 20;
- unsigned char player = {88};
- unsigned char klawisz;
- void wypiszLabirynt(char lab[kolumny][wiersze], int n, int m)
- {
- system("cls");
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- cout << lab[i][j];
- }
- cout << endl;
- }
- }
- char menu()
- {
- system("cls");
- cout << "Nacisnij:" << endl
- << "1 - labirynt 1" << endl
- << "2 - labirynt 2" << endl
- << "3 - labirynt 3" << endl
- << "? - aby uzyskac pomoc" << endl;
- char wybor;
- cin >> wybor;
- return wybor;
- }
- void pomoc()
- {
- system("CLS");
- cout << "Dostepne klawisze: " << endl
- << "w - ruch w gore" << endl
- << "s - ruch w dol" << endl
- << "a - ruch w lewo" << endl
- << "d - ruch w prawo" << endl
- << "q - zamkniecie programu" << endl
- << "? - otwarcie pomocy" << endl;
- }
- void poziom(char lab[kolumny][wiersze], int n, int m)
- {
- int Wx;
- int Wy;
- for(int i =0; i< n; i++)
- {
- for(int j=0; j<m; j++)
- {
- if(lab[i][j] == 'W')
- {
- Wx=i;
- Wy=j;
- }
- }
- }
- int k=1;
- while (k)
- {
- wypiszLabirynt(lab, n, m);
- int Xx;
- int Xy;
- for(int i=0; i < n; i++)
- {
- for(int j=0; j<m; j++)
- {
- if(lab[i][j] == 'X')
- {
- Xx=i;
- Xy=j;
- }
- }
- }
- char klawisz;
- cin>>klawisz;
- switch(klawisz)
- {
- case 'a':
- if (Xy>0 && (lab[Xx][Xy-1] == 32 || lab[Xx][Xy-1] == 'W'))
- {
- lab[Xx][Xy] = 32;
- lab[Xx][Xy-1] = 88;
- }
- break;
- case 'w':
- if (Xx>0 && (lab[Xx-1][Xy] == 32 || lab[Xx-1][Xy] == 'W'))
- {
- lab[Xx][Xy] = 32;
- lab[Xx-1][Xy] = 88;
- }
- break;
- case 'd':
- if (Xy<m && ( lab[Xx][Xy+1] == 32 || lab[Xx][Xy+1] == 'W' ) )
- {
- lab[Xx][Xy] = 32;
- lab[Xx][Xy+1] = 88;
- }
- break;
- case 's':
- if (Xx<n && (lab[Xx+1][Xy] == 32 || lab[Xx+1][Xy] == 'W'))
- {
- lab[Xx][Xy] = 32;
- lab[Xx+1][Xy] = 88;
- }
- break;
- case 'q':
- k=0;
- system("pause");
- break;
- default:
- k=0;
- cout << "Zly klawisz" << endl;
- break;
- }
- if(Wx == Xx && Wy == Xy)
- k=0;
- cout << "koniec";
- }
- }
- int main()
- {
- char lab1[][wiersze] ={
- {201,205,205,205,187,32,32,32,32,32}, //0
- {186,88,32,32,186,32,201,205,187,32}, //1
- {186,32,32,32,186,32,186,32,186,32}, //2
- {186,32,32,32,200,205,188,32,186,32}, //3
- {186,32,32,32,32,32,32,32,186,32}, //4
- {186,32,32,32,32,201,187,32,186,32}, //5
- {186,32,32,32,32,200,188,32,186,32}, //6
- {200,205,205,187,32,32,32,32,186,32}, //7
- {32,32,32,186,32,32,32,32,186,32}, //8
- {32,32,32,200,205,205,87,205,188,32} //9
- };
- char lab2[][wiersze] ={
- {32,32,32,32,32,32,32,32,32,32,201,87,187}, // 0
- {32,32,32,32,201,205,203,205,187,32,186,32,186}, //1
- {32,32,201,205,188,32,186,32,186,32,186,32,186}, //2
- {32,32,186,32,32,32,186,32,200,205,188,32,186}, //3
- {201,205,188,32,201,187,32,32,32,32,32,32,186}, //4
- {186,32,32,32,200,188,32,32,32,201,205,205,188}, //5
- {186,32,32,32,32,32,32,32,32,186,32,32,32}, //6
- {200,205,187,32,201,187,32,32,201,188,32,32,32}, //7
- {32,32,186,32,186,200,187,32,186,32,32,32,32}, //8
- {32,32,186,32,186,32,186,32,200,205,205,205,187}, //9
- {32,32,186,32,186,201,188,32,32,32,32,32,186}, //10
- {32,32,186,88,186,186,32,32,32,32,32,32,186}, //11
- {32,32,200,205,188,200,205,205,205,205,205,205,188}, //12
- };
- char lab3[kolumny][wiersze] ={
- {201,205,205,205,205,205,205,187,32,32,32,32,32,201,205,187}, //0
- {186,32,32,32,32,32,32,186,32,32,32,32,32,186,32,186}, //1
- {186,32,32,32,32,32,32,186,201,205,205,205,205,188,32,186}, //2
- {186,32,32,201,205,205,205,188,186,32,32,32,32,32,32,186}, //3
- {186,32,32,186,32,32,32,32,186,32,201,205,205,187,32,186}, //4
- {186,32,32,200,205,205,205,205,188,32,200,187,32,186,32,186}, //5
- {186,32,32,32,32,32,32,32,32,32,32,186,32,186,32,186}, //6
- {186,32,32,201,205,205,205,205,205,205,205,188,32,186,32,186}, //7
- {186,32,32,186,32,32,32,32,32,32,32,32,32,186,32,186}, //8
- {186,32,32,200,205,205,205,205,205,205,205,187,32,186,32,186}, //9
- {186,32,32,32,32,32,32,32,32,88,32,186,32,186,32,186}, //10
- {186,32,32,201,205,205,205,205,205,205,205,188,201,188,32,186}, //11
- {186,32,32,186,32,32,32,32,32,32,32,32,186,32,32,186}, //12
- {186,32,32,200,205,205,205,205,205,205,205,187,186,32,32,186}, //13
- {186,32,32,32,32,32,32,32,32,32,32,186,204,205,32,87}, //14
- {200,205,205,205,205,205,205,205,205,205,205,188,200,205,205,188} //15
- };
- {
- int i=1;
- while(i)
- switch(menu())
- {
- case '1':
- poziom(lab1, 10, 10);
- break;
- case '2':
- poziom(lab2, 13, 13);
- break;
- case '3':
- poziom(lab3, 16, 16);
- break;
- case 'q':
- i=0;
- return 0;
- break;
- case '?':
- i=0;
- pomoc();
- break;
- default:
- cout << "Zly klawisz" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement