Advertisement
HyperSensualNarwhal

Display symbol on grid when key pressed

Dec 8th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7.  
  8.  
  9. void main()
  10. {
  11.     setlocale(LC_ALL, "Russian");
  12.  
  13.     char sensor = 0;
  14.     char grid[3][3] = { '*', '*', '*',
  15.                         '*', '*', '*',
  16.                         '*', '*', '*'};
  17.  
  18.  
  19.     while (sensor != 27)
  20.     {
  21.  
  22.         for (int i = 0; i < 3; i++)
  23.         {
  24.             cout << "\t\t\t\t";
  25.             for (int j = 0; j < 3; j++)
  26.             {
  27.                 cout << grid[i][j] << " ";
  28.             }
  29.             cout << endl;
  30.         }
  31.  
  32.  
  33.         for (int i = 0; i < 3; i++)
  34.         {
  35.             for (int j = 0; j < 3; j++)
  36.             {
  37.                 grid[i][j] = '*';
  38.             }
  39.             cout << endl;
  40.         }
  41.  
  42.         sensor = getch();
  43.  
  44.         system("cls");
  45.  
  46.         switch (sensor)
  47.         {
  48.         case 119:
  49.             grid[0][1] = '|';
  50.             break;
  51.         case 87:
  52.             grid[0][1] = '|';
  53.             break;
  54.         case 97:   
  55.             grid[1][0] = '_';
  56.             break;
  57.         case 65:   
  58.             grid[1][0] = '_';
  59.             break;
  60.         case 115:
  61.             grid[2][1] = '|';
  62.             break;
  63.         case 83:   
  64.             grid[2][1] = '|';
  65.             break;
  66.         case 100:  
  67.             grid[1][2] = '_';
  68.             break;
  69.         case 68:
  70.             grid[1][2] = '_';
  71.             break;
  72.         case 32:   
  73.             grid[2][0] = '_';
  74.             grid[2][1] = '_';
  75.             grid[2][2] = '_';
  76.             break;
  77.         }
  78.    
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement