home *** CD-ROM | disk | FTP | other *** search
/ Super Games / visualcdgame.iso / dosgames / fiddle / fiddle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-12  |  20.1 KB  |  601 lines

  1.  
  2. /* F I D D L E  by Doug Beeferman.  V1.0; January 12, 1992 */
  3.  
  4.  
  5. #include <graphics.h>
  6. #include <ctype.h>
  7. #include <stdio.h>
  8. #include <time.h>
  9. #include <stdlib.h>
  10.  
  11. #define LEVELNUM 28  /* Includes title and congrats screen */
  12.  
  13. void grstart(void);               /* Start gr., draw permanent elements */
  14. void levelstart(void);              /* Start up particular level */
  15. void MakeSquare(char,char);         /* Draw square at loc x,y of the grid */
  16. int MakeShape(int,char,char,char);  /* Draw piece */
  17. void Translate(char,char,char);     /* Slide piece */
  18. char Illegal(char,char);            /* Determine whether position x,y
  19.                        is illegal or occupied */
  20. void LegendSelect(char,char);       /* Highlight legend entry */
  21. void Rotate(char,char);             /* Rotate piece */
  22. void BorderFlash(void);             /* Flash border for illegal move */
  23. char BeginGame(void);               /* Selection screen */
  24. char CheckWin(void);                /* Determine whether square completed */
  25. void Message(char);                 /* Draw blinking message of praise */
  26. void WriteDone(char);               /* Update levels bar entry w/"DONE" */
  27. void WriteBonus(char);              /* Update bonus points remaining */
  28. void Congrats(void);                /* Congrats screen */
  29. void CongratSquare(char,char);      /* Like MakeSquare but for Congrats */
  30.  
  31. char sayings[52][20]=
  32.     {"Well done!\0","Incredible!\0","Way to go!\0","Great!\0",
  33.     "Excellent!\0","Good work!\0","Teriffic!\0","Amazing!\0",
  34.     "Wonderful!\0","Stupendous!\0","Awesome!\0","Extraordinary!\0",
  35.     "Beautiful!\0","Spectacular!\0","Fantastic!\0","Outstanding!\0",
  36.     "Superb!\0","Tremendous!\0","Fine job!\0","Masterfully done!\0",
  37.     "Fabulous!\0","Stunning!\0","Formidable!\0","Ingenious!\0",
  38.         "Astounding!\0","Unbelievable!\0",
  39.     "Orientation\0","Basic four\0","Jigsaw I\0","Tribute to Tetris\0",
  40.     "Jagged edge\0","UIUC\0","Jigsaw II\0","Truism\0",
  41.     "Trident\0","Arrows\0","Clockwise\0","Tight squeeze\0","One good turn\0",
  42.     "Magic\0","Have a good one!\0","The windmill\0","Be happy!\0",
  43.     "SuperCactus\0","Cuts both ways\0","Spacemaker\0",
  44.     "Misplaced\0","Think negative!\0","Holey Piece\0","Overturn\0",
  45.     "Revenge of Jigsaw\0","Nightmare\0"},
  46.  
  47. clrs[11]={0,4,1,2,14,3,12,13,9,10},
  48.      levelinfo[53]=
  49. {0,15,20,20,25,30,30,30,30,35,35,35,35,35,40,40,40,45,45,45,45,50,50,50,50,50,75,
  50. 6,8,8,6,11,8,10,7,7,10,6,7,8,8,7,11,8,10,11,9,10,9,15,9,9,10},
  51.      status[56],
  52.      z[40][30],
  53.      zz[LEVELNUM][255]={
  54.  
  55. /*TITLE SCREEN*/
  56. {7,17,2,2,2,1,1,1,1,4,4,4,1,1,1,1,2,2,2,0,
  57. 15,17,4,4,4,1,1,1,1,2,2,2,3,3,4,4,0,
  58. 17,17,1,1,1,1,1,1,1,1,0,
  59. 22,17,4,4,4,1,1,1,1,2,2,2,3,3,4,4,0,
  60. 27,17,4,4,4,1,1,1,1,2,2,2,0,
  61. 29,17,1,1,1,1,1,1,4,4,2,2,2,2,4,4,1,1,1,0,
  62. 20,22,4,4,4,4,4,1,1,3,3,3,3,1,4,1,1,3,4,0,-1},
  63.  
  64. /*A*/
  65. {12,10,3,3,4,1,1,4,1,2,2,2,2,2,3,4,4,0,
  66. 26,10,3,4,1,1,2,2,2,3,4,3,3,0,
  67. 20,21,1,4,4,2,2,2,3,3,3,0,-1},
  68.  
  69. /*B*/
  70. {11,14,1,1,4,3,3,2,2,2,3,4,4,4,3,3,2,1,0,
  71. 30,13,1,1,1,2,3,3,3,3,4,4,4,3,2,2,2,0,
  72. 23,21,4,4,3,3,4,1,1,1,2,2,2,2,2,2,2,3,4,4,4,0,
  73. 20,10,4,4,3,2,2,2,1,1,1,4,3,0,-1},
  74.  
  75. /*C*/
  76. {10,9,1,1,2,3,3,3,3,1,4,4,1,3,3,0,
  77. 20,14,2,1,3,2,4,3,4,4,1,1,2,1,1,0,
  78. 30,8,1,2,3,3,3,3,1,4,1,4,1,1,4,4,0,
  79. 10,20,1,2,3,3,3,4,1,4,4,1,2,1,0,
  80. 30,20,1,1,1,2,3,2,4,3,3,4,3,3,4,1,0,-1},
  81.  
  82. /*D*/
  83. {11,10,1,1,1,0,
  84. 15,10,4,2,1,2,0,
  85. 19,9,1,3,3,2,0,
  86. 23,8,2,4,3,3,0,
  87. 27,9,3,2,1,0,
  88. 17,17,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0,-1},
  89.  
  90. /*E*/
  91. {9,14,1,1,2,1,2,2,4,4,4,4,3,3,3,2,2,2,2,4,3,4,4,3,2,0,
  92. 28,21,1,1,4,1,3,3,3,4,2,2,2,3,3,4,1,0,
  93. 17,6,3,3,3,3,2,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,4,4,3,3,2,1,0,
  94. 22,15,1,2,2,1,3,2,3,4,4,4,4,4,4,4,3,3,2,1,2,2,2,0,
  95. 29,9,4,1,4,4,1,2,2,2,2,3,4,2,3,3,2,3,3,3,1,4,1,4,1,4,0,
  96. 15,24,3,2,3,3,4,1,4,3,1,1,1,1,2,1,4,1,1,1,0,-1},
  97.  
  98. /*F*/
  99. {12,8,3,3,3,2,2,2,1,1,1,0,
  100. 17,8,3,3,3,0,
  101. 19,8,3,3,3,2,2,2,1,1,1,0,
  102. 27,8,4,4,4,3,3,3,2,2,2,0,
  103. 19,15,2,2,1,4,4,4,3,0,
  104. 14,14,2,2,2,3,4,4,4,1,4,4,4,0,
  105. 24,14,4,4,3,2,2,2,1,2,2,2,0,-1},
  106.  
  107. /*G*/
  108. {18,3,2,2,3,3,3,3,3,4,4,2,1,1,1,1,4,0,
  109. 10,7,3,3,3,4,4,1,1,1,2,3,3,0,
  110. 28,24,1,1,4,1,1,2,1,2,2,2,1,1,0,
  111. 9,19,2,2,1,1,2,2,3,3,3,3,4,4,4,4,1,2,2,2,1,1,0,
  112. 19,25,1,1,2,3,3,2,1,1,3,3,2,1,1,1,1,4,4,0,
  113. 19,16,2,1,4,1,2,2,2,2,4,1,0,
  114. 34,7,4,4,4,4,4,4,3,3,3,2,1,1,0,-1},
  115.  
  116. /*L*/
  117. {27,14,1,1,4,2,3,3,3,3,4,2,2,0,
  118. 14,14,4,2,2,0,
  119. 18,14,4,2,2,1,1,4,4,2,2,3,3,3,3,4,4,0,
  120. 10,14,4,1,1,3,3,2,2,1,1,3,3,3,3,0,
  121. 22,13,4,2,2,2,0,
  122. 22,15,4,2,2,2,0,
  123. 27,18,2,2,3,4,4,4,4,1,2,0,-1},
  124.  
  125. /*H*/
  126. {14,6,1,3,2,4,3,3,2,0,
  127. 25,7,3,1,1,2,3,0,
  128. 10,16,4,4,2,2,1,1,2,3,0,
  129. 31,16,2,1,4,4,3,1,4,1,0,
  130. 14,25,4,4,2,2,2,1,1,4,0,
  131. 25,24,1,3,2,3,4,4,0,
  132. 20,15,4,4,1,3,2,2,1,3,3,3,1,1,2,2,1,0,-1},
  133.  
  134. /*T*/
  135. {8,12,1,1,3,2,3,2,4,3,4,3,1,1,4,4,3,0,
  136. 14,12,1,1,3,4,3,4,2,3,2,3,1,1,2,2,3,0,
  137. 8,18,1,1,3,2,3,2,4,3,4,3,1,1,4,4,1,0,
  138. 14,18,1,1,3,4,3,4,2,3,2,3,1,1,2,2,1,0,
  139. 25,11,2,2,1,4,4,4,3,3,3,3,2,1,1,0,
  140. 32,11,3,3,1,2,1,1,4,4,3,4,4,2,1,0,
  141. 25,19,1,1,4,3,3,3,2,2,1,2,3,1,2,0,
  142. 32,19,4,4,2,3,2,2,1,1,1,1,4,3,3,0,-1},
  143.  
  144. /*I*/
  145. {17,10,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,4,4,4,0,
  146. 26,12,3,3,0,
  147. 29,14,1,1,0,
  148. 18,19,2,2,2,1,0,
  149. 19,22,2,2,3,0,
  150. 13,13,2,0,-1},
  151.  
  152. /*J*/
  153. {14,14,3,3,3,2,2,1,1,1,3,3,3,2,2,1,1,1,1,1,1,4,3,4,1,4,3,4,1,4,3,4,1,
  154.     3,3,3,3,3,3,0,
  155. 22,15,3,3,0,
  156. 24,15,3,3,0,
  157. 26,14,3,3,3,0,
  158. 28,13,3,3,3,3,0,-1},
  159.  
  160. /*K*/
  161. {13,4,4,4,4,2,2,2,3,3,3,4,4,1,4,4,0,
  162. 28,6,2,2,1,1,3,3,4,4,4,4,3,1,1,1,0,
  163. 19,16,4,4,1,1,1,3,3,3,2,2,2,1,1,2,2,3,3,3,3,4,0,
  164. 11,25,3,2,1,1,4,4,3,3,4,1,1,1,1,1,1,0,
  165. 28,26,2,2,4,4,1,1,1,3,3,3,4,4,4,4,0,-1},
  166.  
  167. /*M*/
  168. {10,19,2,2,2,2,2,2,2,1,1,1,1,1,1,1,4,4,4,4,4,4,4,3,3,3,3,3,3,0,
  169. 12,17,2,2,2,1,1,1,4,4,4,3,3,0,
  170. 25,18,2,2,2,2,2,1,1,1,1,1,4,4,4,4,4,3,3,3,3,0,
  171. 27,16,2,1,4,0,-1},
  172.  
  173. /*N*/
  174. {18,12,4,4,4,3,3,2,4,1,1,2,2,2,3,3,3,3,3,4,4,4,0,
  175. 20,15,3,3,2,2,2,4,4,4,1,1,2,2,2,1,1,1,4,4,3,0,
  176. 12,10,2,3,3,3,0,
  177. 25,13,1,1,3,3,3,3,0,
  178. 25,18,1,0,
  179. 19,19,4,4,4,2,2,2,2,2,2,0,-1},
  180.  
  181. /*O*/
  182. {14,16,2,1,4,3,3,4,1,0,
  183. 24,16,4,1,2,3,3,2,1,0,
  184. 14,20,4,3,2,4,4,1,4,4,4,4,1,2,2,2,2,2,2,2,2,2,2,3,4,4,4,3,2,2,2,0,
  185. 24,20,2,3,4,2,2,1,2,2,2,2,1,4,4,4,4,4,4,4,4,4,4,3,2,2,2,3,4,4,4,0,
  186. 19,10,4,4,4,3,1,2,2,2,2,2,2,3,1,4,4,4,1,1,1,2,4,4,2,3,3,3,3,3,3,2,4,4,0,
  187. 19,14,4,4,1,1,1,2,3,4,3,3,3,3,3,2,1,1,2,3,3,2,2,1,4,1,2,1,4,2,1,1,1,4,3,0,-1},
  188.  
  189. /*P*/
  190. {13,12,4,2,1,0,
  191. 16,12,2,4,1,0,
  192. 14,15,4,4,3,1,2,2,2,2,2,3,0,
  193. 22,11,3,2,3,3,3,3,3,2,1,1,1,1,1,2,3,3,2,2,3,4,4,3,3,0,
  194. 16,10,4,4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,1,1,1,1,1,1,0,-1},
  195.  
  196. /*Q*/
  197. {13,9,2,2,4,4,4,4,4,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,4,0,
  198. 13,7,4,4,1,2,2,2,2,3,4,2,3,4,4,4,4,0,
  199. 29,15,4,2,2,2,2,2,2,3,3,3,4,4,4,4,4,4,4,4,1,1,1,0,
  200. 30,17,4,4,4,2,2,2,2,2,2,0,
  201. 10,24,2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,4,4,4,4,1,
  202.     2,2,3,2,2,3,3,3,3,3,2,2,1,1,1,1,1,1,0,-1},
  203.  
  204. /*R*/
  205. {9,11,4,3,1,2,2,3,0,
  206. 9,13,4,4,1,1,1,1,2,4,3,3,3,3,2,2,2,2,1,1,1,1,4,0,
  207. 9,17,4,1,3,2,2,1,0,
  208. 9,15,4,4,3,3,3,3,2,4,1,1,1,1,2,2,2,2,3,3,3,3,4,0,
  209. 19,14,4,4,4,4,4,2,2,3,3,3,1,2,4,4,2,1,1,2,2,2,1,1,1,1,1,3,3,3,3,3,
  210.     3,3,3,3,3,1,1,1,1,1,2,2,2,2,2,4,4,1,1,1,3,4,2,2,0,
  211. 29,11,3,3,4,4,1,1,1,1,2,2,2,2,3,3,3,3,4,1,1,1,4,4,3,3,0,
  212. 29,17,3,3,4,4,1,1,1,1,2,2,2,2,3,3,3,3,4,1,1,1,4,4,3,3,0,-1},
  213.  
  214. /*S*/
  215. {12,14,2,1,4,1,0,
  216. 16,14,1,3,4,2,2,0,
  217. 17,18,1,3,4,4,0,
  218. 12,18,4,1,3,2,2,1,0,
  219. 29,11,4,3,3,3,3,3,3,3,4,1,1,1,1,1,1,4,3,3,3,3,3,3,0,
  220. 14,15,4,4,4,4,1,1,3,3,3,3,3,3,2,2,2,2,1,1,1,3,3,3,2,2,2,2,1,1,1,1,4,4,4,
  221.     2,2,2,1,1,1,1,4,4,4,4,4,4,4,0,-1},
  222.  
  223. /*U*/
  224. {13,14,2,2,2,2,2,1,3,4,4,4,4,4,1,1,1,1,2,2,2,2,2,3,0,
  225. 15,12,4,1,3,3,0,
  226. 16,12,1,4,2,2,3,3,4,4,0,
  227. 19,10,3,1,2,2,3,3,3,3,4,4,1,0,
  228. 19,12,4,2,2,0,
  229. 13,15,2,2,2,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,4,1,1,1,0,
  230. 17,17,4,4,2,1,2,2,2,3,4,2,3,4,4,4,0,
  231. 26,14,4,2,3,2,2,2,4,4,4,1,1,2,2,2,0,
  232. 22,15,1,1,1,1,1,3,3,3,3,3,3,3,3,3,0,-1},
  233.  
  234. /*V*/
  235. {13,15,3,4,4,4,4,3,3,3,2,1,2,3,2,1,2,2,4,3,2,2,2,1,3,2,1,1,1,4,1,
  236.     2,1,1,1,1,4,4,4,4,3,3,3,3,2,2,4,3,4,3,0,
  237. 23,13,4,1,2,2,3,3,4,4,0,
  238. 27,17,4,2,2,0,
  239. 23,17,3,1,1,3,4,2,2,4,0,
  240. 27,13,1,1,4,3,3,3,3,2,1,2,3,2,1,1,4,1,2,1,4,4,0,-1},
  241.  
  242. /*W*/
  243. {9,13,1,1,1,1,4,3,4,1,1,2,1,4,1,2,2,2,3,2,1,3,3,3,3,4,3,3,2,1,2,3,2,1,2,3,
  244.     2,1,2,3,3,3,3,4,1,3,4,4,4,1,1,2,4,4,4,3,2,3,4,3,2,3,4,3,2,3,3,4,1,3,
  245.     4,4,1,4,3,1,1,1,1,2,2,3,1,1,1,4,3,4,1,1,1,1,2,3,3,0,
  246. 31,13,4,4,1,1,1,4,4,4,4,4,1,2,2,2,2,2,2,2,1,4,4,4,4,4,4,4,1,1,
  247.     2,3,2,1,2,3,2,1,2,3,2,1,2,2,2,3,3,3,3,4,4,4,3,2,2,2,3,3,3,3,3,3,
  248.     4,4,4,4,3,2,2,2,2,3,3,4,1,4,3,4,1,4,3,4,4,4,4,4,1,1,2,1,4,1,2,2,
  249.     3,2,3,2,3,1,1,1,4,2,2,2,2,2,1,4,4,4,1,2,2,2,1,1,4,4,0,
  250. 10,25,1,3,2,3,0,
  251. 15,25,3,1,1,4,0,
  252. 19,25,1,3,2,3,0,
  253. 24,26,1,3,4,2,2,0,
  254. 28,25,1,3,2,3,0,-1},
  255.  
  256. /*X*/
  257. {10,14,1,2,0,
  258. 16,14,1,4,0,
  259. 11,17,1,4,2,2,0,
  260. 15,17,1,4,2,2,0,
  261. 11,18,4,1,3,2,2,1,0,
  262. 15,18,4,1,3,2,2,1,0,
  263. 26,19,4,4,4,4,2,2,2,2,2,2,2,2,4,4,4,4,1,1,1,1,1,1,1,2,2,2,4,3,4,3,4,4,1,
  264.     1,4,4,2,3,0,
  265. 12,12,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,4,4,4,0,-1},
  266.  
  267. /*Y*/
  268. {9,7,4,3,1,1,2,2,1,3,3,3,0,
  269. 19,7,1,2,3,3,4,1,4,0,
  270. 29,7,2,3,4,4,3,1,1,1,2,0,
  271. 9,15,3,4,1,1,2,2,3,2,0,
  272. 19,15,4,1,3,2,2,1,3,3,2,4,4,0,
  273. 29,15,3,2,4,4,1,1,4,2,2,1,3,2,0,
  274. 9,23,3,2,2,4,1,1,2,4,4,2,1,0,
  275. 19,23,4,4,2,3,2,2,2,4,1,1,4,4,1,0,
  276. 29,23,4,4,2,3,1,1,2,3,2,3,0,-1},
  277.  
  278. /*Z*/
  279. {3,12,2,2,2,4,4,4,1,1,1,1,1,2,2,1,1,4,0,
  280. 9,8,2,2,2,3,2,2,2,2,1,3,3,1,4,4,3,3,3,4,1,1,4,3,3,1,4,1,3,4,4,1,1,0,
  281. 19,9,3,3,3,1,1,1,1,1,1,2,2,1,3,3,0,
  282. 24,8,3,3,3,3,2,2,4,4,1,1,1,1,1,1,1,1,1,2,2,3,3,1,4,0,
  283. 29,10,3,3,2,2,1,3,4,4,1,1,1,2,2,2,0,
  284. 35,12,4,2,2,4,1,0,
  285. 20,27,4,1,4,1,1,1,2,4,3,3,3,2,3,2,2,1,2,1,1,1,4,0,
  286. 20,25,2,4,3,0,-1},
  287.  
  288.  
  289. /*"CONGRATS" screen*/
  290. {4,12,4,4,3,3,3,3,2,2,0,
  291. 9,12,4,4,4,3,3,3,3,2,2,2,1,1,1,1,0,
  292. 15,12,3,3,3,3,4,4,1,1,1,1,4,4,3,3,3,3,0,
  293. 20,12,4,4,4,3,3,3,3,2,2,2,1,1,4,0,
  294. 25,16,1,1,4,1,1,4,4,3,3,2,4,3,3,0,
  295. 29,16,1,1,1,1,4,4,3,3,2,4,3,3,0,
  296. 32,12,4,2,2,4,3,3,3,3,0,
  297. 37,12,4,4,3,3,2,2,3,3,4,4,0,-1}
  298.  
  299.  
  300.  
  301. },
  302.    level,selshape,levelsdone=0,index[255],TurnOffFlash,login[8],*filename="";
  303.    int indexptr[11],flashc,score;
  304.  
  305. void main(void) {char a,i,flash=1; int x,y,timer; FILE *fptr; time_t sec1;
  306.  
  307. clrscr(); textcolor(14); highvideo();
  308. gotoxy(1,19); cprintf("F I D D L E    ");
  309. textcolor(4); cprintf("A game of visualization and logic by Doug Beeferman");
  310. printf("\n\nPlease log-in by entering your first name.\n\n\> ");
  311. scanf("%s",login);
  312. sprintf(filename,"%s.fid",login);
  313.  
  314. /**/ 
  315.    fptr=fopen(filename,"r");
  316.    if (fptr) for (i=1; i<53; i++) status[i]=getc(fptr)-50;
  317.    else for (i=27; i<53; i++) status[i]=levelinfo[i-26];
  318.    fclose(fptr);
  319. /**/
  320.  
  321. grstart();
  322. for (i=1; i<27; i++) if (status[i]) WriteDone(i);
  323.  
  324. while (BeginGame())
  325. {setcolor(15); MakeShape(0,15,1,1); sec1=time(NULL); timer=1; flashc=0;
  326.     do
  327.     {
  328.     while(!kbhit()) {if (flash)
  329.             {flashc++; if (flashc==600) MakeShape(indexptr[selshape],clrs[selshape],1,1);
  330.             if (flashc==800) {MakeShape(indexptr[selshape],15,1,1); flashc=0;}}
  331.  
  332.             if ((((time(NULL)-sec1)/12)>=timer)&&(status[level+26]))
  333.             {timer++; if (level!=1) status[level+26]--; WriteBonus(level);}}
  334.  
  335.     a=getch();
  336. if ((a>48)&&(a<(49+indexptr[0]))) {
  337.     MakeShape(indexptr[selshape],clrs[selshape],1,1);
  338.     setcolor(0); LegendSelect(selshape,clrs[selshape]);
  339.     selshape=a-48; MakeShape(indexptr[selshape],15,1,1);
  340.     setcolor(15); LegendSelect(selshape,15); flashc=0;}
  341. if (a==48) {flash=(flash)?0:1; MakeShape(indexptr[selshape],15,1,1);}
  342. if (a==0) {a=getch(); switch(a) {
  343.     case 72: case -104:
  344.     for (i=1; i<((a==72)?2:4); i++) Translate(selshape,0,-1); break;
  345.     case 80: case -96:
  346.     for (i=1; i<((a==80)?2:4); i++) Translate(selshape,0,1); break;
  347.     case 75: case -101:
  348.     for (i=1; i<((a==75)?2:4); i++) Translate(selshape,-1,0); break;
  349.     case 77: case -99:
  350.     for (i=1; i<((a==77)?2:4); i++) Translate(selshape,1,0); break;
  351.     case 79: Rotate(selshape,-1); break;
  352.     case 81: Rotate(selshape,1); break; }}
  353. else switch (a) {
  354.     case 90: case 122: Rotate(selshape,-1); break;
  355.     case 88: case 120: Rotate(selshape,1); }
  356.                   
  357. if (CheckWin()) {MakeShape(indexptr[selshape],clrs[selshape],1,1); Message(level-1); status[level]=1; WriteDone(level); break;}
  358. if (a==27) {for (x=0; index[x]!=-1; x++) zz[level][x]=index[x]; break;}
  359. }
  360. while (1);
  361. {setcolor(0); x=101+13*(level-1); rectangle(3,x,53,x+14);}
  362.     }
  363. closegraph();
  364. textcolor(14);
  365.  
  366. if (levelsdone<26)
  367.  
  368. {cprintf("S c o r e   r e p o r t");
  369. x=0; for (i=1; i<27; i++) x+=status[i]*levelinfo[i]*2;
  370. printf("\n\nLevels completed...  %i   Points earned...  %i/%i\n\nYou have ",levelsdone,score,x);
  371. if (levelsdone==25) printf("only one level"); else printf("%i levels",26-levelsdone);
  372. printf(" yet to complete.  Good luck!\n\n\n");}
  373.  
  374. else {cprintf("C o n g r a t u l a t i o n s !");
  375. printf("\n\n\nYour final score/rating...  %i/",score);
  376. if (score>1599) printf("EXCELLENT"); else {if (score>1299) printf("GOOD");
  377. else printf("FAIR");}
  378. printf("\n\n\nIf you enjoyed the game and would like Cyberbox, source code, and more (see\nthe end of FIDDLE.DOC for details), send $5 to\n\n\t\tDoug Beeferman\n\t\t904 W. Green #215\n\t\tUrbana, IL  61801");
  379. printf("\n\nPlease report your final score code in any feedback: %i-%i-%i\n\n\n",score,score%92,score%73);}
  380.  
  381.  
  382. /**/
  383. fptr=fopen(filename,"w");
  384. for(i=1; i<53; i++) putc(status[i]+50,fptr);
  385. fclose(fptr);
  386.  
  387. }
  388.  
  389. char BeginGame(void) {int i; char a,str[4];
  390.     score=0; for (i=1; i<27; i++) score+=(status[i]*(status[i+26]+levelinfo[i]));
  391.     itoa(score,str,10); setfillstyle(1,0); bar(57,448,156,477);
  392.     setcolor(4); outtextxy(80,460,str);
  393.     if (levelsdone>25) {Congrats(); return 0;}
  394.     level=0; TurnOffFlash=1; levelstart();
  395.     Translate(7,0,0); setcolor(15);
  396.     outtextxy(210,440,"Choose a level by hitting a letter from A to Z,");
  397.     outtextxy(242,450,"or hit ESC to quit and save your score.");
  398.     while (1) {
  399.         if (kbhit()) {a=toupper(getch());
  400.             if (((a>64)&&(a<64+LEVELNUM))&&(!status[a-64])) {level=a-64; TurnOffFlash--; levelstart(); return 1;}
  401.             else if (a==27) return 0;}
  402.  
  403.         i++; if (i==400) {if (index[indexptr[7]]>12) Translate(7,-1,0);
  404.                 else Translate(7,20,0); i=0;}}
  405.  
  406.      }
  407.  
  408. void grstart(void)
  409. {int i,j; char str[2]=" ",str2[3]="  ";
  410.    int gdriver = DETECT, gmode, errorcode;
  411.    initgraph(&gdriver, &gmode, "");
  412.    _setcursortype(0);
  413.    setcolor(7);
  414.    rectangle(0,0,639,479); rectangle(1,1,638,478);
  415.    line(2,70,637,70); line(157,2,157,477);
  416.    setcolor(14);
  417.    line(11,40,21,10); line(21,10,41,10); line(16,25,26,25);
  418.    line(51,10,41,40);
  419.    line(51,40,61,10); line(61,10,71,25); line(71,25,51,50);
  420.    line(71,40,81,10); line(81,10,91,25); line(91,25,71,50);
  421.    line(101,10,91,40); line(91,40,111,40);
  422.    line(136,40,116,40); line(116,40,126,10); line(126,10,146,10); line(121,25,131,25);
  423.    setcolor(4);
  424.    outtextxy(11,55,"by Doug Beeferman");
  425.    setcolor(8); line(56,71,56,477); line(120,71,120,447); line(2,447,156,447);
  426.    setcolor(7); outtextxy(300,7,"- Select a piece.  0 to toggle flash");
  427.         outtextxy(300,17,"- Slide the selected piece");
  428.         outtextxy(300,27,"- Rotate the selected piece clockwise");
  429.         outtextxy(300,37,"- Rotate counter-clockwise");
  430.         outtextxy(300,47,"- Hold down to slide more quickly");
  431.         outtextxy(300,57,"- Give up and select another level");
  432.    for (i=65; i<91; i++) {
  433.       strset(str,i); outtextxy(26,105+13*(i-65),str);
  434.       itoa(levelinfo[i-64],str2,10); outtextxy(62,105+13*(i-65),str2);
  435.       outtextxy(80,105+13*(i-65),"+"); WriteBonus(i-64);}
  436.    setcolor(15); outtextxy(9,460,"SCORE"); outtextxy(8,85,"Level  Points");
  437.    outtextxy(200,7,"Number keys"); outtextxy(208,17,"Arrow keys");
  438.    outtextxy(200,27,"PageDn or X"); outtextxy(224,37,"End or Z");
  439.    outtextxy(264,47,"Alt"); outtextxy(264,57,"Esc");
  440.  
  441.    }
  442.  
  443. void levelstart(void)
  444. {int i,j; char shape=0,x,y,dir1,dir2,str[2];
  445.  
  446.    char Lev_Dim [45];
  447.    setfillstyle(1,0);
  448.    bar(195,71,605,477);
  449.    if (!TurnOffFlash) {
  450.    setcolor(7);
  451.    sprintf(Lev_Dim,"Level: %c   `%s'   Dimensions: %ix%i",
  452.    level+64,sayings[level+25],levelinfo[level+26],levelinfo[level+26]    );
  453.    outtextxy(401-4*strlen(Lev_Dim),85,Lev_Dim);
  454.    setcolor(1); i=101+13*(level-1); rectangle(3,i,53,i+14);}
  455.    setcolor(8);
  456.    for (i=200; i<601; i+=10) line(i,105,i,405);
  457.    for (j=105; j<406; j+=10) line(200,j,600,j);
  458.    for (i=0; i<40; i++) for (j=0; j<30; j++) z[i][j]=0;
  459.    for (i=0; i<11; i++) indexptr[i]=0;
  460.    i=-1; do {i++; index[i]=zz[level][i];} while (index[i]!=-1);
  461.    i=0;
  462.    while (index[i]!=-1) {
  463.      shape++;
  464.      indexptr[shape]=i;
  465.      i=MakeShape(i,clrs[shape],1,1);}
  466.    indexptr[0]=shape;
  467.    selshape=1;
  468.    if (!TurnOffFlash) {setcolor(15);
  469.    for (i=1; i<shape+1; i++) {setfillstyle(1,clrs[i]); bar(160+i*40,425,180+i*40,444);
  470.    setcolor(7); rectangle(160+i*40,425,180+i*40,444); itoa(i,str,10); outtextxy(167+i*40,455,str);
  471.    }  LegendSelect(1,15);}
  472.  
  473.    }
  474.  
  475.  
  476. void LegendSelect(char i,char color) {
  477.      rectangle(157+40*i,420,183+40*i,469);
  478.      setfillstyle(1,color); bar(164+40*i,429,176+40*i,440);}
  479.  
  480. int MakeShape(int i,char color,char change,char changeto) {char dir1=0,dir2=0,
  481.             x=index[i],y=index[1+i];
  482.     setfillstyle(1,color);
  483.     i+=2;
  484.     while (index[i]!=0) {switch(index[i])
  485.             {case 1: dir2--; break;
  486.             case 2: dir1++; break;
  487.             case 3: dir2++; break;
  488.             case 4: dir1--; break;}
  489.         ++i; if (change) {MakeSquare(x+dir1,y+dir2);
  490.                 z[x+dir1][y+dir2]=changeto;} else if (Illegal(x+dir1,y+dir2)) return 0;}
  491. if (change) {MakeSquare(x,y);
  492. setcolor(0); line(202+10*x,107+10*y,208+10*x,113+10*y);
  493. line(208+10*x,107+10*y,202+10*x,113+10*y);
  494. z[x][y]=changeto;}
  495. else if (Illegal(x,y)) return 0;
  496.  
  497.         i++; if (change) return i; else return 1;
  498. }
  499.  
  500. char Illegal(char x,char y) {
  501.     if ((((x<0)||(x>39))||((y<0)||(y>29))) || (z[x][y])) return 1; else return 0;}
  502.  
  503. void MakeSquare(char x,char y) {
  504.    bar(202+10*x,107+10*y,208+10*x,113+10*y); }
  505.  
  506. void Translate(char selshape,char dir1,char dir2) {int i=indexptr[selshape]; char flash=0,affected[10];
  507.    MakeShape(i,0,1,0); flashc=-300;
  508.    index[i]+=dir1; index[i+1]+=dir2;
  509.    if (!MakeShape(i,0,0,0))
  510.    {index[i]-=dir1; index[i+1]-=dir2; flash++;}
  511.    MakeShape(i,15,1,1); if (flash) BorderFlash(); }
  512.  
  513. void Rotate(char selshape,char dir1) {int i=indexptr[selshape],j; char flash=0;
  514.    MakeShape(i,0,1,0);
  515.    j=i+1; flashc=-300;
  516.    while (index[j+1]!=0) {j++;
  517.     index[j]+=dir1;
  518.     if (index[j]==5) index[j]=1;
  519.     if (index[j]==0) index[j]=4;}
  520.    if (!MakeShape(i,0,0,0)) {j=i+1;
  521.             while (index[j+1]!=0) {j++;
  522.             index[j]-=dir1;
  523.             if (index[j]==5) index[j]=1;
  524.             if (index[j]==0) index[j]=4;}
  525.             flash++;}
  526.    MakeShape(i,15,1,1); if (flash) BorderFlash(); }
  527.  
  528. void BorderFlash(void) {char i,j,k;
  529.    if (!TurnOffFlash) {setcolor(4); rectangle(0,0,639,479);
  530.    rectangle(1,1,638,478);
  531.    delay(50);
  532.    setcolor(7); rectangle(0,0,639,479); rectangle(1,1,638,478);} }
  533.  
  534. char CheckWin(void) {char i,j,a,b,k;
  535.    for (i=0; i<40; i++) for (j=0; j<30; j++) if (z[i][j]) goto Cont;
  536.    Cont:
  537.    k=levelinfo[level+26];
  538.    for (a=i; a<i+k; a++) for (b=j; b<j+k; b++) if (!z[a][b]) return 0;
  539.    return 1;}
  540.  
  541. void Message(char mnum) {int i,j=999;
  542.    setfillstyle(1,0);
  543.    j=999;
  544.    bar(190,410,600,472);
  545.    Goback:
  546.    while (!kbhit()) {j++;
  547.    if (j==1000) {
  548.    setcolor(15); rectangle(300,420,500,462);
  549.    i=399-(strlen(sayings[mnum])*4); setcolor(14);
  550.    outtextxy(i,430,sayings[mnum]); setcolor(7);
  551.    outtextxy(354,444,"-Hit Enter-");}
  552.  
  553.    if (j==2500) {bar(300,420,500,462); j=0;}
  554.    }
  555.    if (getch()!=13) goto Goback;}
  556.  
  557. void WriteDone(char i) {
  558.    setcolor(4);
  559.    outtextxy(123,105+13*(i-1),"DONE");
  560.    levelsdone++;
  561.    moveto(110,107+13*(i-1));
  562.    linerel(3,5); linerel(4,-8);
  563.    }
  564.  
  565. void WriteBonus(char i) {char str2[3]="  ";
  566.    setfillstyle(1,0); bar(92,105+13*(i-1),109,113+13*(i-1));
  567.    setcolor(7);
  568.    itoa(status[i+26],str2,10);
  569.    outtextxy(92,105+13*(i-1),str2);}
  570.  
  571. void Congrats(void) {char h,v,a,count=0,str[20]; int i;
  572. level=LEVELNUM-1; TurnOffFlash=1; levelstart();
  573. setcolor(15);
  574. outtextxy(183,435,"You have completed every level of Fiddle!  Hit any key.");
  575. while (!kbhit())
  576. {h=random(26)+7; v=random(24)+3;
  577. if ((count%4)==0) {
  578.     setfillstyle(1,0); bar(320,85,480,96);
  579.     sprintf(str,"%s",sayings[count/4]);
  580.     outtextxy(401-4*(strlen(str)),85,str);}
  581. for (a=2; a<40; a++)
  582.     {
  583.      selshape=1;
  584.      CongratSquare(h,v+a); CongratSquare(h,v-a);
  585.      CongratSquare(h+a,v); CongratSquare(h-a,v);
  586.      CongratSquare(h+a,v+a); CongratSquare(h-a,v-a);
  587.      CongratSquare(h+a,v-a); CongratSquare(h-a,v+a);
  588.  
  589.      selshape=0; setfillstyle(1,0);
  590.      CongratSquare(h,v+a-4); CongratSquare(h,v-a+4);
  591.      CongratSquare(h+a-4,v); CongratSquare(h-a+4,v);
  592.      CongratSquare(h+a-4,v+a-4); CongratSquare(h-a+4,v-a+4);
  593.      CongratSquare(h+a-4,v-a+4); CongratSquare(h-a+4,v+a-4);
  594.  
  595.       delay(15);}
  596. count++; if (count==104) count=0;}
  597. a=getch();
  598.  
  599. }
  600. void CongratSquare(char x,char y)  {if (!Illegal(x,y))
  601.     {if (selshape) setfillstyle(1,4+10*(random(2))); MakeSquare(x,y);}}