Advertisement
Felanpro

Game Character

Feb 18th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1.     #include <iostream>
  2.     #include <conio.h>
  3.     #include <stdio.h>
  4.  
  5.     using namespace std;
  6.  
  7.     char matrix[11][11];
  8.  
  9.     void initialize()
  10.     {
  11.         for(int d = 0; d < 11; d++)
  12.         {
  13.             for(int q = 0; q < 11; q++)
  14.             {
  15.                 matrix[d][q] = '*';
  16.             }
  17.         }
  18.         matrix[5][5] = 'X';
  19.     }
  20.  
  21.     void draw()
  22.     {
  23.         for(int x = 0; x < 10; x++)
  24.         {
  25.             for(int z = 0; z < 10; z++)
  26.             {
  27.                 cout << matrix[x][z] << " ";
  28.             }
  29.             cout << endl;
  30.         }
  31.     }
  32.  
  33.     void input()
  34.     {
  35.         //77 = right arrow
  36.         //72 = up arrow
  37.         char variable;
  38.         int c = 0;
  39.         int m = 0;
  40.         int breaking = 0;
  41.  
  42.         for(c = 0; c < 10; c++)
  43.         {
  44.             for(m = 0; m < 10; m++)
  45.             {
  46.                 if(matrix[c][m] == 'X')
  47.                 {
  48.                     breaking = 1;
  49.                     break;
  50.                 }
  51.             }
  52.             if(breaking == 1)
  53.                 break;
  54.         }
  55.  
  56.         variable = getch();
  57.  
  58.         if(variable == 77)
  59.         {
  60.             matrix[c][m] = '*';
  61.             matrix[c][m + 1] = 'X';
  62.         }
  63.         else if(variable == 72)
  64.         {
  65.             matrix[c][m] = '*';
  66.             matrix[c - 1][m] = 'X';
  67.         }
  68.         else if(variable == 75)
  69.         {
  70.             matrix[c][m] = '*';
  71.             matrix[c][m - 1] = 'X';
  72.         }
  73.         else if(variable == 80)
  74.         {
  75.             matrix[c][m] = '*';
  76.             matrix[c + 1][m] = 'X';
  77.         }
  78.     }
  79.  
  80.     int main()
  81.     {
  82.         initialize();
  83.         while(1)
  84.         {
  85.             draw();
  86.             input();
  87.             system("cls");
  88.         }
  89.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement