Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.41 KB | None | 0 0
  1. # include "iGraphics.h"
  2. # include <stdio.h>
  3. # include <string.h>
  4. # include <time.h>
  5.  
  6. int f = 0, log1_y = 600, len=0, m3, mm3, stop_dec = 0, log2_y = 800, m1, m2, mm1, mm2, point = 0;
  7. int i, ans_f =0, p, c, s, log3_y = 1000, c3=0, lev=50, type = 0;
  8. char n1[4], nn1[4], c1 = 0, c2 = 0, score[4];
  9. char ch, in_ans[10], in_ans1[10], in_ans2[10], log1_math[4], log2_math[4],signs[4]={'+','-','x','/0'};
  10. char colour[5][50] = {"Red","Green", "Orange", "Blue", "Purple"};
  11. char shape[5][50] = {"Square", "Circle", "Triangle", "Diamond", "Pentagon"};
  12.  
  13.  
  14. void log1_y_dec(void);
  15. void log2_y_dec(void);
  16. void score_in(void);
  17. int intConvert(char in_ans[]);
  18.  
  19. void initialize(){
  20. f = 0;
  21. log1_y = 600, log2_y = 800, log3_y = 1000;
  22. point = 0;
  23. c1=0, c2=0, c3 = 0;
  24. stop_dec = 0;
  25. }
  26.  
  27.  
  28. int intConvert(char in_ans[])
  29. {
  30. /*this function converts a string of numbers to interger number. it's parameter is the string that takes input from the keyboard
  31. it will be cosidered the ans to the math expression.*/
  32. int i, ans, k=0;
  33. ans = in_ans[strlen(in_ans) - 1] - 48;
  34. if(in_ans[0]=='-')k=1;
  35. for (i = strlen(in_ans) - 2; i >= k; i--){
  36. ans = ans + (in_ans[i] - 48)*10;
  37. }
  38. if(k==0)return ans;
  39. else return ans*-1;
  40. }
  41.  
  42. /* void math_sum_exp2(void)
  43. {
  44. /*generates a mathematical expression with a plus sign.
  45. PROBLEM: once compiles it gives the same expresion until it is compiled again*/
  46. //int mm1, mm2;
  47. //srand(time(NULL));
  48. /*mm1 = rand() % 10;
  49. nn1[0] = 48 + mm1;
  50. //nn1[1] = '+';
  51. mm2 = rand() % 10;
  52. nn1[2] = 48 + mm2;
  53. nn1[3] = '=';
  54. //mm3 = mm1 + mm2;
  55. nn1[4] = '\0';
  56. int sign2 = rand() % 3;
  57. nn1[1] = signs[sign2];
  58.  
  59. if(sign2 == 0) mm3 = mm1 + mm2;
  60. else if (sign2 == 1) mm3 = mm1 - mm2;
  61. else mm3 = mm1 * mm2;
  62.  
  63. } */
  64.  
  65. int type_no()
  66. {
  67. type = rand()%3;
  68. return type;
  69. }
  70.  
  71. int colour_exp()
  72. {
  73. c = rand()%5;
  74. return c;
  75. }
  76.  
  77. int shape_exp()
  78. {
  79. s = rand()%5;
  80. return s;
  81. }
  82.  
  83. void math_sum_exp(void)
  84. {
  85. /*generates a mathematical expression with a plus sign.
  86. PROBLEM: once compiles it gives the same expresion until it is compiled again*/
  87. //int m1, m2;
  88. srand(time(NULL));
  89. m1 = rand() % 10;
  90. n1[0] = 48 + m1;
  91. //n1[1] = '+';
  92. m2 = rand() % 10;
  93. n1[2] = 48 + m2;
  94. n1[3] = '=';
  95. //m3 = m1 + m2;
  96. n1[4] = '\0';
  97.  
  98. int sign1 = rand() % 3;
  99. n1[1] = signs[sign1];
  100.  
  101. if(sign1 == 0) m3 = m1 + m2;
  102. else if (sign1 == 1) m3 = m1 - m2;
  103. else m3 = m1 * m2;
  104.  
  105. strcpy(log1_math,n1);
  106. }
  107.  
  108. void log1_y_dec(void)
  109. {
  110. /*decreases the logs y co-ordinate to lower it. if the log crashes with the boat y coordinate is set back to initial*/
  111. if (f == 1)
  112. {
  113. if (stop_dec==0){
  114. log1_y -= 3;
  115. log2_y -= 3;
  116. log3_y -= 3;
  117. }
  118. if (stop_dec==1){
  119. log1_y += 600;
  120. //if(log1_y <600) log1_y = 600;
  121. c1=0;
  122. point += 5;
  123. stop_dec=0;
  124. }
  125.  
  126. if (log1_y <= 128 || log2_y <= 128 || log3_y <= 128){
  127. f = 4;///final screen flag
  128. }
  129. }
  130. }
  131. /*
  132. function iDraw() is called again and again by the system.
  133. */
  134. void iDraw()
  135. {
  136. iClear();
  137. if (f == 0)
  138. {
  139. ///home screen
  140. iShowBMP(0, 0, "home back.bmp");
  141. iSetColor(255, 0, 0);
  142. iRectangle(130, 300, 240, 67);///lower box
  143. iRectangle(130, 367, 240, 67);///middle box
  144. iRectangle(130, 434, 240, 67);///upper box
  145. iText(215, 460, "START", GLUT_BITMAP_TIMES_ROMAN_24);
  146. iText(165, 390, "INSTRUCTIONS", GLUT_BITMAP_TIMES_ROMAN_24);
  147. iText(220, 325, "QUIT", GLUT_BITMAP_TIMES_ROMAN_24);
  148. }
  149.  
  150. if (f == 1)
  151. {
  152. ///main game page
  153. iSetColor(47, 141, 255);
  154. iFilledRectangle(100, 0, 300, 600);
  155.  
  156. iSetColor(0, 0, 0);
  157. iText(290,60,"YOUR ANSWER:");
  158. //iText(320,40,in_ans, GLUT_BITMAP_TIMES_ROMAN_24);
  159.  
  160. //if(stop_dec==0){
  161. //if (intConvert(in_ans2) != m3){
  162. iShowBMP(100, log1_y, "log1.bmp");
  163. if (c1 == 0){
  164. math_sum_exp();
  165. //puts(n1);
  166. c1++;
  167. }
  168.  
  169. iSetColor(255, 255, 255);
  170. iText(240, log1_y + 25, log1_math, GLUT_BITMAP_9_BY_15);
  171.  
  172.  
  173. //}
  174.  
  175. iShowBMP(100,log2_y, "log2.bmp");
  176. if (c2 == 0){
  177. c = colour_exp();
  178. c2++;
  179. }
  180.  
  181. iText(240, log2_y + 25, colour[c], GLUT_BITMAP_9_BY_15);
  182.  
  183. iShowBMP(100, log3_y, "log1.bmp");
  184. if (c3 == 0){
  185. s = shape_exp();
  186. //puts(n1);
  187. c3++;
  188. }
  189.  
  190. iText(240, log3_y + 25, shape[s], GLUT_BITMAP_9_BY_15);
  191.  
  192. iSetColor(0, 0, 0);
  193. iText(320,40,in_ans, GLUT_BITMAP_TIMES_ROMAN_24);
  194.  
  195. if (intConvert(in_ans2) == m3)
  196. stop_dec = 1;
  197.  
  198. //if (intConvert(in_ans2) == mm3)
  199. // stop_dec = 2;
  200. // this portion checks keyboard input string converted to an integer and compares it to the actual answer of the expression
  201. //if they match stops loading the log image
  202. // PROBLEM: Doesn't set the log back, doesn't work for continuos logs.
  203.  
  204. iSetColor(0, 0, 0);
  205. iFilledRectangle(0, 600, 500, 50);
  206. iSetColor(255, 255, 255);
  207. iText(200, 620, "SCORE: ");
  208.  
  209. p = point;
  210. for(i=3;i>=0;i--){
  211. score[i] = p%10 + 48;
  212. p /= 10;
  213. }
  214. score[4]='\0';
  215.  
  216. iSetColor(255, 255, 255);
  217. iText(260,620,score);
  218.  
  219. // scores isn't complete
  220. iText(30, 550, "SHAPES");
  221. iText(430, 550, "COLORS");
  222.  
  223. iSetColor(255, 255, 255);
  224. iShowBMP(218, 0, "boat.bmp");
  225.  
  226. iLine(0, 600, 500, 600);///draws horizontal line
  227.  
  228. ///for shapes buttons
  229. iSetColor(255, 0, 0);///square
  230. iFilledRectangle(0, 0, 100, 100);
  231.  
  232. iSetColor(0, 255, 0);///circle
  233. iFilledRectangle(0, 100, 100, 100);
  234.  
  235. iSetColor(255, 173, 47);///triangle
  236. iFilledRectangle(0, 200, 100, 100);
  237.  
  238. iSetColor(0, 0, 255);///diamond
  239. iFilledRectangle(0, 300, 100, 100);
  240.  
  241. iSetColor(160, 32, 240);///pentagon
  242. iFilledRectangle(0, 400, 100, 100);
  243.  
  244. iSetColor(255, 255, 255);
  245. iFilledRectangle(30, 30, 40, 40);
  246. iFilledCircle(50, 150, 20);
  247. iFilledCircle(50, 250, 20, 3);
  248. iFilledEllipse(50, 350, 20, 30, 4);
  249. iFilledCircle(50, 450, 20, 5);
  250.  
  251. ///for color buttons
  252. iSetColor(255, 0, 0);///red
  253. iFilledRectangle(400, 0, 100, 100);
  254.  
  255. iSetColor(0, 255, 0);///green
  256. iFilledRectangle(400, 100, 100, 100);
  257.  
  258. iSetColor(255, 173, 47);///orange
  259. iFilledRectangle(400, 200, 100, 100);
  260.  
  261. iSetColor(0, 0, 255);///blue
  262. iFilledRectangle(400, 300, 100, 100);
  263.  
  264. iSetColor(160, 32, 240);///purple
  265. iFilledRectangle(400, 400, 100, 100);
  266.  
  267. }
  268. if (f == 2)
  269. {
  270. ///instruction page
  271. iShowBMP(0, 0, "ins.bmp");
  272. iSetColor(255, 255, 200);
  273. iText(10, 10, "GO BACK", GLUT_BITMAP_TIMES_ROMAN_24);
  274.  
  275. }
  276. if (f == 3)
  277. {
  278. ///quit button
  279. exit(1);
  280. }
  281. if (f == 4)
  282. {
  283. ///end screen
  284. iText(180, 500, "GAME OVER", GLUT_BITMAP_TIMES_ROMAN_24);
  285. iText(10, 10, "RETURN HOME", GLUT_BITMAP_9_BY_15);
  286. }
  287.  
  288.  
  289. }
  290. /*
  291. function iMouseMove() is called when the user presses and drags the mouse.
  292. (mx, my) is the position where the mouse pointer is.
  293. */
  294. void iMouseMove(int mx, int my)
  295. {
  296. //place your codes here
  297. }
  298. /*
  299. function iMouse() is called when the user presses/releases the mouse.
  300. (mx, my) is the position where the mouse pointer is.
  301. */
  302. void iMouse(int button, int state, int mx, int my)
  303. {
  304. if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  305. {
  306. //place your codes here
  307. if (mx>130 && my>434 && mx <370 && my<501 && f == 0)
  308. {
  309. f = 1;
  310. }
  311. if (mx>130 && my>367 && mx <370 && my<433 && f == 0)
  312. {
  313. f = 2;
  314. }
  315. if (mx>130 && my>300 && mx <370 && my<366 && f == 0)
  316. {
  317. f = 3;
  318. }
  319. if (mx>10 && my>10 && mx <100 && my<50 && f == 2)
  320. {
  321. f = 0;
  322. }
  323. if (mx>10 && my>10 && mx < 100 && my < 50 && f == 4){
  324. initialize();
  325. }
  326.  
  327. ///colour answer
  328. if(log2_y < 600 && log2_y >= 128)
  329. {
  330. ///red
  331. if(c==0 && mx > 400 && mx < 500 && my > 0 && my < 100)
  332. {
  333. log2_y += 600;
  334. c2 = 0;
  335. point += 5;
  336. }
  337.  
  338. ///green
  339. if(c==1 && mx > 400 && mx < 500 && my > 100 && my < 200)
  340. {
  341. log2_y += 600;
  342. c2 = 0;
  343. point += 5;
  344. }
  345.  
  346. ///orange
  347. if(c==2 && mx > 400 && mx < 500 && my > 200 && my < 300)
  348. {
  349. log2_y += 600;
  350. c2 = 0;
  351. point += 5;
  352. }
  353.  
  354. ///blue
  355. if(c==3 && mx > 400 && mx < 500 && my > 300 && my < 400)
  356. {
  357. log2_y += 600;
  358. c2 = 0;
  359. point += 5;
  360. }
  361.  
  362. ///purple
  363. if(c==4 && mx > 400 && mx < 500 && my > 400 && my < 500)
  364. {
  365. log2_y += 600;
  366. c2 = 0;
  367. point += 5;
  368. }
  369.  
  370. }
  371.  
  372. ///shape answer
  373. if(log3_y < 600 && log3_y >= 128)
  374. {
  375. ///square
  376. if(s==0 && mx > 0 && mx < 100 && my > 0 && my < 100)
  377. {
  378. log3_y += 600;
  379. c3 = 0;
  380. point += 5;
  381. }
  382.  
  383. ///circle
  384. if(s==1 && mx > 0 && mx < 100 && my > 100 && my < 200)
  385. {
  386. log3_y += 600;
  387. c3 = 0;
  388. point += 5;
  389. }
  390.  
  391. ///Triangle
  392. if(s==2 && mx > 0 && mx < 100 && my > 200 && my < 300)
  393. {
  394. log3_y += 600;
  395. c3 = 0;
  396. point += 5;
  397. }
  398.  
  399. ///diamond
  400. if(s==3 && mx > 00 && mx < 100 && my > 300 && my < 400)
  401. {
  402. log3_y += 600;
  403. c3 = 0;
  404. point += 5;
  405. }
  406.  
  407. ///pentagon
  408. if(s==4 && mx > 00 && mx < 100 && my > 400 && my < 500)
  409. {
  410. log3_y += 600;
  411. c3 = 0;
  412. point += 5;
  413. }
  414.  
  415. }
  416.  
  417. }
  418. if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
  419. {
  420. //place your codes here
  421. }
  422. }
  423. /*
  424. function iKeyboard() is called whenever the user hits a key in keyboard.
  425. key- holds the ASCII value of the key pressed.
  426. */
  427. void iKeyboard(unsigned char key)
  428. {
  429. /// takes input from keyboard to a string
  430. int i;
  431. if (f == 1){
  432. if(key == '\r')
  433. {
  434. //it'll set the string to zero
  435.  
  436. in_ans[len] = '\0';
  437.  
  438. strcpy(in_ans2,in_ans);
  439. for(i=0;i<len;i++)
  440. in_ans[i] = 0;
  441.  
  442. len = 0;
  443. }
  444. else
  445. {
  446. in_ans[len] = key;
  447. //puts(in_ans);
  448. len++;
  449. }
  450.  
  451. /*if(pause == 0 && key == ' '){
  452. pause = 1;
  453. }
  454. if(pause == 1 && key == ' '){
  455. pause = 0;
  456. }*/
  457. }
  458.  
  459. //place your codes for other keys here
  460. }
  461. /*
  462. function iSpecialKeyboard() is called whenver user hits special keys likefunction
  463. keys, home, end, pg up, pg down, arraows etc. you have to use
  464. appropriate constants to detect them. A list is:
  465. GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
  466. GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11,
  467. GLUT_KEY_F12, GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN,
  468. GLUT_KEY_PAGE UP, GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END,
  469. GLUT_KEY_INSERT */
  470. void iSpecialKeyboard(unsigned char key)
  471. {
  472. if (key == GLUT_KEY_END)
  473. {
  474. exit(0);
  475. }
  476. //place your codes for other keys here
  477. }
  478.  
  479. void level(){
  480. lev -= 5;
  481.  
  482. }
  483.  
  484. int main()
  485. {
  486. //place your own initialization codes here.
  487. iSetTimer(10,level);
  488. iSetTimer(lev, log1_y_dec);
  489.  
  490. iInitialize(500, 650, "RIVER LEARNING");
  491. return 0;
  492. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement