Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <string>
  7. using namespace std;
  8. bool gameOver;
  9. int x, y, FruitX, FruitY, score;
  10. enum Prebirovka{STOP = 0, LEFT, RIGHT, UP, DOWN};
  11. Prebirovka zip;
  12. const int wight = 30;
  13. const int hight = 30;
  14. void Parametr()
  15. {
  16. gameOver = false;
  17. zip = STOP;
  18. x = wight / 2;
  19. y = hight / 2;
  20. FruitX = rand() % wight;
  21. FruitY = rand() % hight;
  22. score = 0;
  23. }
  24. void mapPrint()
  25. {
  26. system("cls");
  27. for (int i = 0; i < wight + 1; i++)
  28. cout << "*";
  29. cout << endl;
  30.  
  31. for (int i = 0; i < wight; i++)
  32. {
  33. for (int j = 0; j < hight; j++)
  34. {
  35. if (j == 0 || j == wight - 1)
  36. cout << "*";
  37. if (i == x && j == y)
  38. cout << "0";
  39. else if (i == FruitX && j == FruitY)
  40. cout << "F";
  41. else
  42. cout << " ";
  43. }
  44. cout << endl;
  45. }
  46.  
  47. for (int i = 0; i < wight + 1; i++)
  48. cout << "*";
  49. cout << endl;
  50. cout << "Score : " << score << endl;
  51. }
  52. void Ypravl()
  53. {
  54. if (_kbhit())
  55. {
  56. switch (_getch())
  57. {
  58. case 'a':
  59. zip = LEFT;
  60. break;
  61. case 'd':
  62. zip = RIGHT;
  63. break;
  64. case 'w':
  65. zip = UP;
  66. break;
  67. case 's':
  68. zip = DOWN;
  69. break;
  70. case 'x':
  71. gameOver = true;
  72. break;
  73. }
  74. }
  75. }
  76. void Logik()
  77. {
  78. switch (zip)
  79. {
  80. case LEFT:
  81. x--;
  82. break;
  83. case RIGHT:
  84. x++;
  85. break;
  86. case UP:
  87. y--;
  88. break;
  89. case DOWN:
  90. y++;
  91. break;
  92. }
  93. if (x = rand() % wight || y = rand() % hight)
  94. {
  95. gameOver = false;
  96. }
  97. else if (x > wight || x < wight || y > hight || y < hight)
  98. {
  99. gameOver = true;
  100. }
  101. if (x == FruitX && y == FruitY)
  102. {
  103. score += 5;
  104. FruitX = rand() % wight;
  105. FruitY = rand() % hight;
  106. }
  107.  
  108. }
  109.  
  110. int main()
  111. {
  112. while (!gameOver)
  113. {
  114. Parametr();
  115. mapPrint();
  116. Ypravl();
  117. Logik();
  118. }
  119.  
  120.  
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement