Facebook
From Speedy Bat, 4 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 123
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. char tmp_map[18][32];
  9. char map[18][32] =
  10. {
  11.     "###############################",
  12.     "#                             #",
  13.     "#                             #",
  14.     "#                             #",
  15.     "#      #######                #",
  16.     "#      #     #                #",
  17.     "#      #     #                #",
  18.     "#      #     #                #",
  19.     "#      #     #                #",
  20.     "#      #     #                #",
  21.     "#      #     ###########      #",
  22.     "#      #               #      #",
  23.     "#      #################      #",
  24.     "#                             #",
  25.     "#                             #",
  26.     "#                             #",
  27.     "#                             #",
  28.     "###############################"
  29. };
  30.  
  31. void show_map(short pts)
  32. {
  33.     for(int i = 0; i < 18; i++)
  34.     {
  35.         printf("%s\n",map[i] );
  36.     }
  37.     cout << pts << endl;
  38. }
  39. void gotoxy(short x, short y){
  40.     tmp_map=map;
  41.     tmp_map[x][y]='O'
  42. }
  43.  
  44. int main()
  45. {
  46.     int x = 15;
  47.     int y = 16;
  48.     int pts = 0;
  49.  
  50.  
  51.     system("cls");
  52.     gotoxy( x, y );
  53.  
  54.     while( true )
  55.     {
  56.         show_map();
  57.          
  58.         if ( GetAsyncKeyState( VK_UP ) )
  59.         {
  60.  
  61.             if( map[y-1][x] == ' ' )
  62.             {
  63.                 y--;
  64.                 pts++;
  65.             }
  66.         }
  67.         if ( GetAsyncKeyState( VK_DOWN ) )
  68.         {
  69.  
  70.             if( map[y+1][x] == ' ' )
  71.             {
  72.                 y++;
  73.                 pts++;
  74.             }
  75.         }
  76.         if ( GetAsyncKeyState( VK_LEFT ) )
  77.         {
  78.  
  79.             if( map[y][x-1] == ' ' )
  80.             {
  81.                 x--;
  82.                 pts ++;
  83.             }
  84.         }
  85.         if ( GetAsyncKeyState( VK_RIGHT ) )
  86.         {
  87.  
  88.             if( map[y][x+1] == ' ' )
  89.             {
  90.                 x++;
  91.                 pts++;
  92.             }
  93.         }
  94.         gotoxy( x,y );
  95.         Sleep( 100 );
  96.  
  97.     }
  98.     return 0;
  99. }