Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. #define frame 20
  7. //the size of the gameframe (x * x)
  8.  
  9. #define gamespeed 250
  10. //the amount of time the game will wait (in milliseconds) before drawing the next frame
  11. //if we change this we should probably make the gameclock reflect the change
  12. //but for now it just runs at double time
  13.  
  14. char screen[frame][frame]; //global variables because fuck you
  15. int gameTime = 100;
  16. int score = 0;
  17.  
  18. int main(void);
  19. void drawframe(void);
  20. void newline(void);
  21. void clearScreen(void);
  22. void waitFor(int millisecs);
  23. void checkForRow(void);
  24. void gravity(void);
  25. void generateObject(void);
  26. int gameOver(void);
  27.  
  28. /*
  29. THIS CODE SUCKS MAJOR ASS
  30.  
  31. Known Issues:
  32. gameOver() doesn't actually work
  33. no user input
  34. game clock is directly affected by the game speed (like a nes game lol)
  35. frameDraw is directly affected by the game speed
  36. */
  37.  
  38. int main(void)
  39. {
  40. srand(time(NULL));
  41. //initialze the screen
  42. for (int x = 0; x < frame; x++)
  43. for (int y = 0; y < frame; y++)
  44. screen[x][y] = ' ';
  45. for (int i = 0; i < frame; ++i) {
  46. screen[0][i] = 'x';
  47. screen[frame - 1][i] = 'x';
  48. screen[i][0] = 'x';
  49. screen[i][frame - 1] = 'x';
  50. }
  51.  
  52.  
  53.  
  54. printf("TimeLeft: %d Score: %d\n", gameTime--, score);
  55. generateObject();
  56. drawframe();
  57. while (gameTime > 0 && !gameOver())
  58. {
  59. waitFor(gamespeed);
  60. gravity();
  61. if(gameTime % 9 == 0)
  62. generateObject();
  63. checkForRow();
  64. clearScreen();
  65. printf("TimeLeft: %d Score: %d\n", gameTime--, score);
  66. printf("Game over? %d\n", gameOver());
  67. drawframe();
  68. }
  69. clearScreen();
  70. printf("Game over!\nYou lose idiot!\n");
  71. return 0;
  72. }
  73.  
  74. void drawframe(void)
  75. {
  76. for (int x = 0; x < frame; x++)
  77. {
  78. newline();
  79. for (int y = 0; y < frame; y++)
  80. printf("%c", screen[x][y]);
  81. }
  82. }
  83.  
  84. void newline(void)
  85. {
  86. printf("\n");
  87. }
  88.  
  89. void clearScreen()
  90. {
  91. system("cls");
  92. }
  93.  
  94. void waitFor(int millisecs)
  95. {
  96. Sleep(millisecs);
  97. }
  98.  
  99. void checkForRow(void)
  100. {
  101. for (int x = 1; x < frame - 1; x++)
  102. {
  103. int count = 0;
  104. for (int y = 0; y < frame; y++)
  105. {
  106. if (screen[x][y] != 'x')
  107. break;
  108. count++;
  109. if (count == frame - 1)
  110. {
  111. for (int z = 0; z < frame; z++)
  112. screen[x][z] = ' ';
  113. screen[x][0] = 'x';
  114. screen[x][frame - 1] = 'x';
  115. score += 1000;
  116. }
  117. }
  118. }
  119. }
  120.  
  121. void gravity(void)
  122. {
  123. for (int x = frame - 1 ; x > 0; x--)
  124. {
  125. for (int y = frame - 1; y > 1; y--)
  126. {
  127. if (screen[x][y] == 'x')
  128. {
  129. if (screen[x + 1][y] == ' ')
  130. {
  131. screen[x][y] = ' ';
  132. screen[x + 1][y] = 'x';
  133. }
  134. }
  135. }
  136. }
  137. }
  138.  
  139. void generateObject(void)
  140. {
  141. int r = rand() % 6;
  142. switch (r)
  143. {
  144. //creates a box
  145. case 1:
  146. {
  147. screen[1][frame / 2] = 'x';
  148. screen[1][frame / 2 + 1] = 'x';
  149. screen[2][frame / 2] = 'x';
  150. screen[2][frame / 2 + 1] = 'x';
  151. break;
  152. }
  153. //creates an L
  154. case 2:
  155. {
  156. screen[1][frame / 2] = 'x';
  157. screen[1][frame / 2 + 1] = 'x';
  158. screen[2][frame / 2] = 'x';
  159. screen[3][frame / 2] = 'x';
  160. break;
  161. }
  162. //creates a line
  163. case 3:
  164. {
  165. screen[1][frame / 2] = 'x';
  166. screen[2][frame / 2] = 'x';
  167. screen[3][frame / 2] = 'x';
  168. screen[4][frame / 2] = 'x';
  169. break;
  170. }
  171. //creates a z
  172. case 4:
  173. {
  174. screen[1][frame / 2] = 'x';
  175. screen[2][frame / 2] = 'x';
  176. screen[2][frame / 2 - 1] = 'x';
  177. screen[3][frame / 2 - 1] = 'x';
  178. break;
  179. }
  180. //creates a T
  181. case 5:
  182. {
  183. screen[1][frame / 2] = 'x';
  184. screen[2][frame / 2] = 'x';
  185. screen[2][frame / 2 + 1] = 'x';
  186. screen[2][frame / 2 - 1] = 'x';
  187. break;
  188. }
  189. }
  190. }
  191.  
  192. int gameOver(void)
  193. {
  194. int xfoundcount = 0;
  195. for (int x = 1; x < frame - 1; x++)
  196. {
  197. for (int y = 1; y < frame - 1; y++)
  198. {
  199. if (screen[x][y] == 'x')
  200. {
  201. xfoundcount++;
  202. break;
  203. }
  204. }
  205. }
  206. if (xfoundcount == frame - 1)
  207. return 1;
  208. return 0;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement