Advertisement
Guest User

mandatory

a guest
Oct 30th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int input1, input2, highscore, turn, score, index, xgo, ygo, xfin, yfin, xn, yn ;
  5. char a[12][12], condition[13]={"map/map"},level[1];
  6.  
  7. void baca()
  8. {
  9. printf("ASCII level: %d",level[0]);
  10. condition[7]=level[0];
  11. //printf("%d", level[0]);
  12. FILE *op;
  13. op = fopen(condition,"r");
  14. while(index<10)
  15. {
  16. fscanf(op,"%[^\n]\n",a[index]);
  17. for(int i=0;i<10;i++)
  18. {
  19. if(a[index][i]=='1'){a[index][i]=1;xgo=index;ygo=i;}
  20. if(a[index][i]=='2'){a[index][i]=2;xfin=index;yfin=i;}
  21. }
  22. index+=1;
  23. }
  24.  
  25. fclose(op);
  26. }
  27.  
  28.  
  29.  
  30. void templ()
  31. {
  32. for(int j=0;j<20;j++)
  33. {
  34. printf("\n");
  35. }
  36. printf("High Score : %d\n",highscore);
  37. printf("Level : %c\n",level[0]);
  38. printf("Score : %d\n",score);
  39. printf("Turn : %d\n",turn);
  40. for (int i=0;i<10;i++)
  41. {
  42.  
  43. printf("%s\n",a[i]);
  44. }
  45. //printf("\n\n%d", level[0]);
  46. printf("\n");
  47.  
  48. //baca();
  49. }
  50.  
  51. void menu()
  52. {
  53. puts("Menu");
  54. puts("====");
  55. puts("1. New Game");
  56. puts("2. Continue Saved Game");
  57. puts("3. Exit");
  58. }
  59. //show proses
  60.  
  61. void menu2()
  62. {
  63. printf("\n");
  64.  
  65. printf("1. Up\n");
  66. printf("2. Down\n");
  67. printf("3. Left\n");
  68. printf("4. Right\n");
  69. printf("5. Save And Exit\n");
  70.  
  71. scanf("%d",&input2); fflush(stdin);
  72. }
  73.  
  74. int main()
  75. {//awal
  76. for(int i=0;i<20;i++)
  77. {printf("\n");}
  78.  
  79. printf("Find the way\n");
  80.  
  81. for(int i=0;i<13;i++)
  82. {printf("=");}
  83. for(int i=0;i<3;i++)
  84. {printf("\n");}
  85. menu();
  86. scanf("%d",&input1); fflush(stdin);
  87.  
  88. //system("cls");
  89. //game
  90. if(input1==1)
  91. {//var
  92. highscore=0;
  93. score=0;
  94. turn=0;
  95. index=0;
  96. level[0]=49;
  97. baca();
  98. game:;
  99. templ();
  100. menu2();
  101. if(input2==1)
  102. {
  103. turn++;
  104. xn = 1;
  105. do
  106. {
  107. if(a[xgo-xn][ygo]==' ')
  108. {
  109. a[xgo-xn][ygo]=1;
  110. a[xgo-xn+1][ygo]=' ';
  111. xgo=xgo-xn;
  112. templ();
  113. }
  114.  
  115. }while(a[xgo-xn][ygo]==' ');
  116.  
  117. if(a[xgo-xn][ygo]!=' ')
  118. {
  119. if(a[xgo-xn][ygo]==2)
  120. {
  121. level[0]=level[0]+1;
  122. score = (20-turn)*100;
  123. turn = 0;
  124. baca();
  125. templ();
  126. }
  127. }
  128. goto game;
  129.  
  130. /*do
  131. {
  132. menu2();
  133. counter++;
  134. turn=counter;
  135. }while(a[xgo-xn][ygo]!=2);*/
  136.  
  137.  
  138. }
  139. if(input2==2)
  140. {
  141. turn++;
  142. xn=1;
  143. do
  144. {
  145. if(a[xgo+xn][ygo]==' ')
  146. {
  147. a[xgo+xn][ygo]=1;
  148. a[xgo+xn-1][ygo]=' ';
  149. xgo=xgo+xn;
  150. templ();
  151. }
  152. }while(a[xgo+xn][ygo]==' ');
  153.  
  154. if(a[xgo+xn][ygo]!=' ')
  155. {
  156. if(a[xgo+xn][ygo]==2)
  157. {
  158. level[0]=level[0]+1;
  159. score = (20-turn)*100;
  160. turn = 0;
  161. baca();
  162. templ();
  163. }
  164. }
  165. goto game;
  166. }
  167.  
  168. if(input2==3)
  169. {
  170. turn++;
  171. yn=1;
  172. do
  173. {
  174. if(a[xgo][ygo-yn]==' ')
  175. {
  176. a[xgo][ygo-yn]=1;
  177. a[xgo][ygo-yn+1]=' ';
  178. ygo=ygo-yn;
  179. templ();
  180. }
  181. }while(a[xgo][ygo-yn]==' ');
  182.  
  183. if(a[xgo][ygo-yn]!=' ')
  184. {
  185. if(a[xgo][ygo-yn]==2){
  186. level[0]=level[0]+1;
  187. score = (20-turn)*100;
  188. turn = 0;
  189. baca();
  190. templ();
  191. }
  192. }
  193. goto game;
  194. }
  195.  
  196. if(input2==4)
  197. {
  198. turn++;
  199. yn=1;
  200. do
  201. {
  202. if(a[xgo][ygo+yn]==' ')
  203. {
  204. a[xgo][ygo+yn]=1;
  205. a[xgo][ygo+yn-1]=' ';
  206. ygo=ygo+yn;
  207. templ();
  208.  
  209. }
  210. }while(a[xgo][ygo+yn]==' ');
  211.  
  212. if(a[xgo][ygo+yn]!=' ')
  213. {
  214. if(a[xgo][ygo+yn]==2){
  215. level[0]=level[0]+1;
  216. score = (20-turn)*100;
  217. turn = 0;
  218. baca();
  219. templ();
  220. }
  221. }
  222. goto game;
  223. }
  224.  
  225. }
  226.  
  227.  
  228.  
  229.  
  230. getchar();
  231. return 0;
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement