Guest User

Untitled

a guest
Dec 30th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<windows.h>
  6. #include<conio.h>
  7. #include<iterator>
  8. using namespace std;
  9. figures figure;
  10. games game;
  11. class figures {
  12. public:
  13. int height;
  14. int width;
  15. vector<vector<bool>>elements;
  16. };
  17. class games {
  18. private:
  19. void shag_vlevo();
  20. void shag_vpravo();
  21. void padenie();
  22. games();
  23. public:
  24. /*рандомного выбора фигуры
  25. создания фигуры
  26. поворота фигуры
  27. проверки на остановку
  28. перезапись поля
  29. вывод этого всего на экран
  30. */
  31. void show();
  32. void insert_figure_to_field();
  33. char field[20][10];
  34. /*
  35. конструктор:
  36. выодит надпись начать игру, и тд
  37. деструктор:
  38. выводит кол-во очков
  39. и возвращает на конструктор
  40. */
  41. int prev_x;
  42. int prev_y;
  43. void check_keyboard();
  44. };
  45. void square(figures &figure) {
  46. figure.height = 2;
  47. figure.width = 2;
  48. figure.elements.resize(2);
  49. for (int i = 0; i < 2; ++i) {
  50. figure.elements[i].resize(2);
  51. figure.elements[i][0] = 1;
  52. figure.elements[i][1] = 1;
  53. }
  54. }
  55. games::games() {
  56. for (int i = 0; i < 20; ++i) {
  57. for (int j = 0; j < 10; ++j) {
  58. this->field[i][j] = '.';
  59. }
  60. }
  61. show();
  62. insert_figure_to_field();
  63. }
  64. void games::show() {
  65. system("CLS");
  66. for (int i = 0; i < 20; ++i) {
  67. for (int j = 0; j < 10; ++j) {
  68. cout << this->field[i][j];
  69. }
  70. cout << endl;
  71. }
  72. }
  73. void games::shag_vlevo() {
  74. /*операции для проверки возможен ли шаг влево
  75. и при возможности шаге влево
  76. */
  77. int i, j, l;
  78. if (this->prev_x >0) {
  79. this->prev_x--;
  80. i = this->prev_x;
  81. j = this->prev_y;
  82. for (l = 0; l < figure.elements.size(); ++l) {
  83. this->field[j + l][i + figure.elements[l].size()] = '.';
  84. this->field[j + l][i - 1] = 'x';
  85. }
  86. }
  87. show();
  88. }
  89. void games::shag_vpravo() {
  90. /*проверка возможен ли шаг вправо
  91. и при возможности шаге вправо
  92. */
  93. int i, j, l;
  94. if (this->prev_x < 19) {
  95. this->prev_x++;
  96. i = this->prev_x;
  97. j = this->prev_y;
  98. for (l = 0; l < figure.elements.size(); ++l) {
  99. this->field[j+l][i+figure.elements[l].size()] = 'x';
  100. this->field[j+l][i-1] = '.';
  101. }
  102. }
  103. show();
  104. }
  105. void games::padenie() {
  106. /*падение блока
  107. */
  108. show();
  109. }
  110. void games::insert_figure_to_field() {
  111. for (int i = 0; i < figure.elements.size(); ++i) {
  112. for (int j = 0; j < figure.elements[i].size(); ++j) {
  113. this->field[i][j + 4 - 1] = 'x';
  114. }
  115. }
  116.  
  117. }
  118. void games::check_keyboard() {
  119. char a, b;
  120. while (!_kbhit);
  121. b = _getch();
  122. if ((int)b == -32) {
  123. a = _getch();
  124. cout << (int)a;
  125. if ((int)a == 75) {
  126. shag_vlevo();
  127. }
  128. else if ((int)a == 77) {
  129. shag_vpravo();
  130. }
  131. else if ((int)a == 80) {
  132. padenie();
  133. }
  134. }
  135. }
  136.  
  137. int main() {
  138. int a;
  139. game.prev_x = 4;
  140. game.prev_y = 0;
  141. //games();
  142. return 0;
  143. }
Add Comment
Please, Sign In to add comment