Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <cstdlib>
- #include <conio.h>
- using namespace std;
- char mapa[10][10];
- char key;
- int a=4,b=5;
- void RysujMape()
- {
- system("cls");
- for (int i=0;i<10;i++)
- {
- for (int j=0;j<20;j++)
- {
- mapa[i][j]='p';
- }
- }
- cout<<" --------------------"<<endl;
- for (int i=0;i<10;i++)
- {
- cout<<"|";
- for (int j=0;j<20;j++)
- {
- if (mapa[i][j]=='p')
- cout<<" ";
- if (i==a && j==b)
- {
- mapa[a][b]='g';
- cout<<"@";
- }
- }
- cout<<"|"<<endl;
- }
- cout<<" --------------------"<<endl;
- }
- void Ruch()
- {
- switch(key)
- {
- case 'w':
- mapa[a][b]='p';
- a-=1;b=b;
- mapa[a-1][b]='g';
- RysujMape();
- break;
- case 's':
- mapa[a][b]='p';
- a+=1;b=b;
- mapa[a+1][b]='g';
- RysujMape();
- break;
- case 'a':
- mapa[a][b]='p';
- a=a;b-=1;
- mapa[a][b-1]='g';
- RysujMape();
- break;
- case 'd':
- mapa[a][b]='p';
- a=a;b+=1;
- mapa[a][b+1]='g';
- RysujMape();
- break;
- }
- }
- int main()
- {
- RysujMape();
- for(;;)
- {
- key=getch();
- Ruch();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement