Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include "gfx.h"
  7.  
  8. void setTimeout(int milliseconds);
  9. void color(int n);
  10.  
  11. int main()
  12. {
  13. int ysize = 900;
  14. int xsize = 1200;
  15. int xcoor, ycoor;
  16. int delay=2;
  17. char c;
  18. char guess[] = "Number of guesses : ";
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. gfx_open(xsize, ysize, "Example Graphics Program");
  30. /*
  31. //before sleep
  32. gfx_color(255, 255, 255);
  33.  
  34. //first row square
  35. gfx_fillrectangle(150, 250, 150, 150);
  36. gfx_fillrectangle(350, 250, 150, 150);
  37. gfx_fillrectangle(550, 250, 150, 150);
  38. gfx_fillrectangle(750, 250, 150, 150);
  39. gfx_fillrectangle(950, 250, 150, 150);
  40.  
  41. //second row
  42. gfx_fillrectangle(150, 450, 150, 150);
  43. gfx_fillrectangle(350, 450, 150, 150);
  44. gfx_fillrectangle(550, 450, 150, 150);
  45. gfx_fillrectangle(750, 450, 150, 150);
  46. gfx_fillrectangle(950, 450, 150, 150);
  47.  
  48. gfx_color(255, 0, 0);
  49. gfx_fillrectangle(175, 275, 100, 100);
  50. gfx_fillrectangle(375, 275, 100, 100);
  51. gfx_fillrectangle(575, 275, 100, 100);
  52. gfx_fillrectangle(775, 275, 100, 100);
  53. gfx_fillrectangle(975, 275, 100, 100);
  54.  
  55. gfx_fillrectangle(175, 475, 100, 100);
  56. gfx_fillrectangle(375, 475, 100, 100);
  57. gfx_fillrectangle(575, 475, 100, 100);
  58. gfx_fillrectangle(775, 475, 100, 100);
  59. gfx_fillrectangle(975, 475, 100, 100);
  60.  
  61. do{
  62. setTimeout(1000);
  63. delay--;
  64. }while (delay>=0);
  65. gfx_flush();
  66. */
  67.  
  68. gfx_color(255, 255, 255);
  69. gfx_text(guess, 550, 100);
  70. //first row square
  71. gfx_fillrectangle(150, 250, 150, 150);
  72. gfx_fillrectangle(350, 250, 150, 150);
  73. gfx_fillrectangle(550, 250, 150, 150);
  74. gfx_fillrectangle(750, 250, 150, 150);
  75. gfx_fillrectangle(950, 250, 150, 150);
  76.  
  77. //second row
  78. gfx_fillrectangle(150, 450, 150, 150);
  79. gfx_fillrectangle(350, 450, 150, 150);
  80. gfx_fillrectangle(550, 450, 150, 150);
  81. gfx_fillrectangle(750, 450, 150, 150);
  82. gfx_fillrectangle(950, 450, 150, 150);
  83.  
  84.  
  85. while(1){
  86. //first row
  87. c=gfx_wait();
  88. if ((c==0x01 && (gfx_xpos()>=150 && gfx_xpos()<=300) && (gfx_ypos()>=250 && gfx_ypos()<=400)) || c=='1')
  89. {
  90. gfx_color(255, 0, 0);
  91. gfx_fillrectangle(175, 275, 100, 100);
  92. }
  93. else if ((c==0x01 && (gfx_xpos()>=350 && gfx_xpos()<=500) && (gfx_ypos()>=250 && gfx_ypos()<=400)) || c=='2')
  94. {
  95. gfx_color(255, 0, 0);
  96. gfx_fillrectangle(375, 275, 100, 100);
  97. }
  98. else if ((c==0x01 && (gfx_xpos()>=550 && gfx_xpos()<=700) && (gfx_ypos()>=250 && gfx_ypos()<=400)) || c=='3')
  99. {
  100. gfx_color(255, 0, 0);
  101. gfx_fillrectangle(575, 275, 100, 100);
  102. }
  103. else if ((c==0x01 && (gfx_xpos()>=750 && gfx_xpos()<=900) && (gfx_ypos()>=250 && gfx_ypos()<=400)) || c=='4')
  104. {
  105. gfx_color(255, 0, 0);
  106. gfx_fillrectangle(775, 275, 100, 100);
  107. }
  108. else if ((c==0x01 && (gfx_xpos()>=950 && gfx_xpos()<=1100) && (gfx_ypos()>=250 && gfx_ypos()<=400)) || c=='5')
  109. {
  110. gfx_color(255, 0, 0);
  111. gfx_fillrectangle(975, 275, 100, 100);
  112. }
  113. //second row
  114. else if ((c==0x01 && (gfx_xpos()>=150 && gfx_xpos()<=300) && (gfx_ypos()>=450 && gfx_ypos()<=600)) || c=='6')
  115. {
  116. gfx_color(255, 0, 0);
  117. gfx_fillrectangle(175, 475, 100, 100);
  118. }
  119. else if ((c==0x01 && (gfx_xpos()>=350 && gfx_xpos()<=500) && (gfx_ypos()>=450 && gfx_ypos()<=600)) || c=='7')
  120. {
  121. gfx_color(255, 0, 0);
  122. gfx_fillrectangle(375, 475, 100, 100);
  123. }
  124. else if ((c==0x01 && (gfx_xpos()>=550 && gfx_xpos()<=700) && (gfx_ypos()>=450 && gfx_ypos()<=600)) || c=='8')
  125. {
  126. gfx_color(255, 0, 0);
  127. gfx_fillrectangle(575, 475, 100, 100);
  128. }
  129. else if ((c==0x01 && (gfx_xpos()>=750 && gfx_xpos()<=900) && (gfx_ypos()>=450 && gfx_ypos()<=600)) || c=='9')
  130. {
  131. gfx_color(255, 0, 0);
  132. gfx_fillrectangle(775, 475, 100, 100);
  133. }
  134. else if ((c==0x01 && (gfx_xpos()>=950 && gfx_xpos()<=1100) && (gfx_ypos()>=450 && gfx_ypos()<=600)) || c=='0')
  135. {
  136. gfx_color(255, 0, 0);
  137. gfx_fillrectangle(975, 475, 100, 100);
  138. }
  139.  
  140.  
  141. if(c=='q') break;
  142. }
  143.  
  144.  
  145. return 0;
  146. }
  147.  
  148. void setTimeout(int milliseconds)
  149. {
  150. // If milliseconds is less or equal to 0
  151. // will be simple return from function without throw error
  152. if (milliseconds <= 0) {
  153. fprintf(stderr, "Count milliseconds for timeout is less or equal to 0\n");
  154. return;
  155. }
  156.  
  157. // a current time of milliseconds
  158. int milliseconds_since = clock() * 1000 / CLOCKS_PER_SEC;
  159.  
  160. // needed count milliseconds of return from this timeout
  161. int end = milliseconds_since + milliseconds;
  162.  
  163. // wait while until needed time comes
  164. do {
  165. milliseconds_since = clock() * 1000 / CLOCKS_PER_SEC;
  166. } while (milliseconds_since <= end);
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement