Advertisement
Guest User

Dinosaur

a guest
Feb 21st, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <conio.h>
  5. #include <windows.h>
  6. using namespace std;
  7.  
  8. struct player{
  9. int x,y;
  10. double rx,ry;
  11. double dx,dy;
  12. };
  13.  
  14. struct ananas{
  15. int x,h,w;
  16. };
  17.  
  18. int a_count = 10; // Кол-во ананасов
  19. ananas a[100]; // Кол-во ананасов
  20.  
  21. player p;
  22.  
  23. int bestscore=0,nowscore=0;
  24. int rr;
  25. int A1;
  26. char g;
  27.  
  28. bool isAnanasHere(int x, int y){
  29. for(int i = 0;i < a_count;i++){
  30. int ax_screen = a[i].x - p.x + 20;
  31. if(x >= ax_screen && y >= 20 - a[i].h && x < ax_screen + a[i].w){
  32. //A1 = x >= ax_screen-30 && y>=20 + 20 - a[i].h && x < ax_screen + a[i].w - 40;
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. void print(){
  39. resett:
  40. rr++;
  41. COORD c = {0, 0};
  42. HANDLE output=GetStdHandle(STD_OUTPUT_HANDLE);
  43. SetConsoleCursorPosition(output,c);
  44. int max_h = 20; // Размер экрана по высоте
  45. int max_w = 50; // Размер экрана по длине
  46. for(int i = 0;i < max_h;i++){
  47. for(int j = 0;j < max_w;j++){
  48. if(i == 5 && j == 3){ // Солнце
  49. cout << " \\ | / " << endl;
  50. cout << " _____" << endl;
  51. cout << " / \\ " << endl;
  52. cout << " _ | | _" << endl;
  53. cout << " | | " << endl;
  54. cout << " \\_____/" << endl << endl;
  55. cout << " / | \\ " << endl;
  56. }
  57. int max_h = 20; // Размер экрана по высоте
  58. int max_w = 50; // Размер экрана по длине
  59. if(isAnanasHere(20, p.y) == true){
  60. cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\tG A M E O V E R";
  61. cout << "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
  62. system("pause");
  63. if(nowscore > bestscore){
  64. bestscore = nowscore;
  65. }
  66. nowscore = 0;
  67. p.y = -1;
  68. goto resett;
  69. }
  70. if(i == 2 && j == 40){
  71. cout << "HI " << bestscore << " " << nowscore;
  72. }
  73. if(i == p.y-1 && j == 20){ // Игрок
  74. cout << "&";
  75. }
  76. if(i == p.y && j == 20){ // Игрок
  77. cout << "&";
  78. }else{
  79. if(isAnanasHere(j, i) == true){
  80. cout << "x";
  81. }else{
  82. cout << " ";
  83. }
  84. }
  85. }
  86. cout << endl;
  87. }
  88. for(int i = 49;i < 50;i++){ // Создание песка
  89. int r = rand()%6;
  90. switch(r){
  91. case 0:
  92. cout << ".";
  93. break;
  94. case 1:
  95. cout << "_";
  96. break;
  97. case 2:
  98. cout << "_";
  99. break;
  100. case 3:
  101. cout << "_";
  102. break;
  103. case 4:
  104. cout << "-";
  105. break;
  106. case 5:
  107. cout << "-";
  108. break;
  109. }
  110. }
  111. }
  112.  
  113. int main(){
  114. reset:
  115. srand(time(NULL));
  116. p.rx = 0;
  117. p.ry = 19;
  118. p.x = (int)p.rx;
  119. p.y = (int)p.ry;
  120. for(int q = 0;q < 10;q++){
  121. a[q].x = 50 + rand()%400; // расстояние до ананасов
  122. a[q].h = 1 + rand()%3;// высота ананасов
  123. a[q].w = 1 + rand()%3;// ширина ананасов
  124. }
  125. for(;;){
  126. p.x = (int)p.rx;
  127. p.y = (int)p.ry;
  128. p.ry = p.ry - p.dy;
  129. p.dy -= 0.3;
  130. if(p.ry > 19){
  131. p.ry = 19;
  132. }
  133. print();
  134. Sleep(1);
  135. p.rx++;
  136. nowscore++;
  137. if(isAnanasHere(20, p.y) != true){
  138. if(_kbhit()){
  139. g = getch();
  140. switch(g){
  141. case 13:
  142. if(nowscore > bestscore){
  143. bestscore = nowscore;
  144. }
  145. nowscore = 0;
  146. goto reset;
  147. break;
  148. case 32:
  149. if(p.y == 19){
  150. p.dy = 1.6;
  151. }
  152. break;
  153. }
  154. }
  155. }
  156. }
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement