Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6. #include <dos.h>
  7. #include <windows.h>
  8. using namespace std;
  9. char polje[30][30];
  10.     char pros='w';
  11.     char a = ' ';
  12.  
  13.  
  14. void popuni()
  15. {
  16.     for(int i=0; i<30; i++)
  17.     {
  18.         for(int j=0; j<30; j++)
  19.         {
  20.             polje[i][j]='.';
  21.         }
  22.     }
  23. }
  24.  
  25. void ispisi()
  26. {
  27.     for(int i=0; i<30; i++)
  28.     {
  29.         for(int j=0; j<30; j++)
  30.             cout<<polje[i][j];
  31.         cout<<endl;
  32.     }
  33. }
  34.  
  35. bool provjera()
  36. {
  37.     int broj=0;
  38.     for(int i=0; i<30; i++)
  39.     {
  40.         for(int j=0; j<30; j++)
  41.             {
  42.                 if(polje[i][j]=='*')
  43.                     broj++;
  44.             }
  45.     }
  46.     if(broj==30*30-1)
  47.         return true;
  48.     else
  49.         return false;
  50. }
  51.  
  52. void promjena()
  53. {
  54.  
  55.  
  56. }
  57.  
  58.  
  59. int main()
  60. {
  61.     popuni();
  62.     int y=15,x=15,prosli=0;
  63.     polje[y][x]='@';
  64.     //ispisi();
  65.     a=_getch();
  66.     pros=a;
  67.     while(true)
  68.     {
  69.         if(kbhit())
  70.         {
  71.          a=_getch();
  72.          pros=a;
  73.         }
  74.         ispisi();
  75.         if(pros=='w' or pros=='W')
  76.         {
  77.             prosli=y;
  78.             y--;
  79.             if(polje[y][x]=='*')
  80.             {
  81.                 cout<<"Game Over"<<endl;
  82.                 return 0;
  83.             }
  84.             polje[prosli][x]='*';
  85.             polje[y][x]='@';
  86.              if(x>29  or y>29 or x<0 or y<0)
  87.             {
  88.                 cout<<"Game Over"<<endl;
  89.                 return 0;
  90.             }
  91.             Sleep(150);
  92.         }
  93.  
  94.          if(pros=='s' or pros=='S')
  95.         {
  96.             prosli=y;
  97.             y++;
  98.             if(polje[y][x]=='*')
  99.             {
  100.                 cout<<"Game Over"<<endl;
  101.                 return 0;
  102.             }
  103.             polje[prosli][x]='*';
  104.             polje[y][x]='@';
  105.              if(x>29  or y>29 or x<0 or y<0)
  106.             {
  107.                 cout<<"Game Over"<<endl;
  108.                 return 0;
  109.             }
  110.             Sleep(150);
  111.         }
  112.  
  113.          if(pros=='a' or pros=='A')
  114.         {
  115.             prosli=x;
  116.             x--;
  117.             if(polje[y][x]=='*')
  118.             {
  119.                 cout<<"Game Over"<<endl;
  120.                 return 0;
  121.             }
  122.             polje[y][prosli]='*';
  123.             polje[y][x]='@';
  124.              if(x>29  or y>29 or x<0 or y<0)
  125.             {
  126.                 cout<<"Game Over"<<endl;
  127.                 return 0;
  128.             }
  129.             Sleep(150);
  130.         }
  131.  
  132.          if(pros=='d' or pros=='D')
  133.         {
  134.             prosli=x;
  135.             x++;
  136.             if(polje[y][x]=='*')
  137.             {
  138.                 cout<<"Game Over"<<endl;
  139.                 return 0;
  140.             }
  141.             polje[y][prosli]='*';
  142.             polje[y][x]='@';
  143.              if(x>29  or y>29 or x<-1 or y<-1)
  144.             {
  145.                 cout<<"Game Over"<<endl;
  146.                 return 0;
  147.             }
  148.             Sleep(150);
  149.         }
  150.  
  151.           system("CLS");
  152.           //promjena();
  153.  
  154.     }
  155.  
  156.  
  157.  
  158.  
  159.         //a=_getch();
  160.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement