Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <time.h>
  5. #include <windows.h>
  6.  
  7. void generate(short int* map)
  8. {
  9. for (short int i = 0; i != 100; i++)
  10. {
  11. int randomiser = rand()%4;
  12. if (randomiser == 0) map[i] = 1;
  13. if (randomiser != 0) map[i] = 0;
  14. }
  15. map[94] = 2;
  16. map[84] = 0;
  17. }
  18.  
  19. void output(short int* map, int score)
  20. {
  21. system("cls");
  22. short int string = 0;
  23. for (short int i = 0; i != 100; i++)
  24. {
  25. if (i / 10 > string)
  26. {
  27. string++;
  28. printf("\n");
  29. }
  30. if (map[i] == 0) printf(" ");
  31. if (map[i] == 1) printf("Z");
  32. if (map[i] == 2) printf("X");
  33. if (i == 49)
  34. {
  35. printf(" Score: %d", score);
  36. }
  37. }
  38. //printf("\n\n\n\n");
  39. }
  40.  
  41. int lose(short int* map)
  42. {
  43. for (short int i = 99; i != 89; i--)
  44. {
  45. if (map[i] == 2 && map[i-10] == 1)
  46. {
  47. return 1;
  48. }
  49. }
  50. return 0;
  51. }
  52.  
  53. int keyPressed(int key)
  54. {
  55. return (GetAsyncKeyState(key) && 0x8000 != 0);
  56. }
  57.  
  58. int move(short int* map, int score)
  59. {
  60. int alreadyMoved = 0;
  61. if (keyPressed(VK_LEFT))
  62. {
  63. for (short int i = 99; i != 89; i--)
  64. {
  65. if (map[i] == 2 && map[i-1] != 1 && i % 10 != 0 && alreadyMoved == 0)
  66. {
  67. map[i]=0;
  68. map[i-1]=2;
  69. alreadyMoved = 1;
  70. }
  71. }
  72. output(map, score);
  73. return 0;
  74. }
  75. if (keyPressed(VK_RIGHT))
  76. {
  77. for (short int i = 99; i != 89; i--)
  78. {
  79. if (map[i] == 2 && map[i+1] != 1 && i % 10 != 9 && alreadyMoved == 0)
  80. {
  81. map[i]=0;
  82. map[i+1]=2;
  83. alreadyMoved = 1;
  84. }
  85. }
  86. score = score + score / 100 + 10;
  87. output(map, score);
  88. return 0;
  89. }
  90. if (keyPressed(VK_UP))
  91. {
  92. return 1;
  93. }
  94. }
  95.  
  96. void tick(short int* map)
  97. {
  98. int position;
  99. for (short int i = 99; i != 89; i--)
  100. {
  101. if (map[i] == 2)
  102. {
  103. position = i;
  104. }
  105. }
  106. for (short int i = 99; i != 9; i--)
  107. {
  108. map[i] = map[i-10];
  109. }
  110. for(short int i = 0; i != 10; i++)
  111. {
  112. int randomiser = rand()%4;
  113. if (randomiser == 0) map[i] = 1;
  114. else map[i] = 0;
  115. }
  116. map[position] = 2;
  117. }
  118.  
  119. int main() {
  120. short int lost = 0;
  121. short int map[100];
  122. int score = 0;
  123. generate(map);
  124. output(map, score);
  125. srand(time(NULL));
  126. do
  127. {
  128. int clockStart, clockEnd, doTick;
  129. clockStart=clock();
  130. clockEnd = clockStart + 500;
  131. do
  132. {
  133. clockStart=clock();
  134. move(map, score);
  135. } while(clockStart < clockEnd);
  136. score = score + score / 100 + 10;
  137. lost=lose(map);
  138. tick(map);
  139. output(map, score);
  140. } while (lost == 0);
  141. system("cls");
  142. printf("YOU LOST");
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement