Advertisement
Guest User

Untitled

a guest
May 17th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. bound = {{2, -1}, {2, 5}, {1, 0}, {3, 0}, {0, 1}, {4, 1}, {0, 2}, {4,
  2. 2}, {-1, 3}, {5, 3}, {-1, 4}, {5, 4}, {-1, 5}, {5, 5}, {0, 6}, {1,
  3. 6}, {3, 6}, {4, 6}}
  4.  
  5. DynamicModule[{pos1 = {x1, y1} = {2, 2}, pos2 = {x2, y2} = {2, 4},
  6. pos3 = {x3, y3} = {2, 0}, message = "Start",
  7. DotT = {a2, b2} = {x2, (y2 - 0.51)},
  8. DotL = {a1, b1} = {x1, (y1 + 0.51)},
  9. DotB = {a3, b3} = {x3, (y3 + 0.51)}, Switch = True, Stick = False},
  10. EventHandler[
  11. Dynamic[Magnify[
  12. Graphics[{Opacity[0.9],
  13. Style[Text[message, {2, 5}], FontFamily -> "Helvetica", Small,
  14. Gray, FontSize -> 15], EdgeForm[Directive[Thick, Magenta]],
  15. Cyan, Disk[{0, 5}, .35], EdgeForm[Directive[Thick, Magenta]],
  16. Cyan, Disk[{0, 4}, .35], EdgeForm[Directive[Thick, Magenta]],
  17. Cyan, Disk[{0, 3}, .35], EdgeForm[Directive[Thick, Magenta]],
  18. Cyan, Disk[{1, 5}, .35], Yellow, Disk[{1, 4}, .35],
  19. EdgeForm[Directive[Thick, Magenta]], Cyan, Disk[{1, 3}, .35],
  20. EdgeForm[Directive[Thick, Magenta]], Cyan, Disk[{3, 5}, .35],
  21. Yellow, Disk[{3, 4}, .35], EdgeForm[Directive[Thick, Magenta]],
  22. Cyan, Disk[{3, 3}, .35], EdgeForm[Directive[Thick, Magenta]],
  23. Cyan, Disk[{4, 5}, .35], EdgeForm[Directive[Thick, Magenta]],
  24. Cyan, Disk[{4, 4}, .35], EdgeForm[Directive[Thick, Magenta]],
  25. Cyan, Disk[{4, 3}, .35], EdgeForm[Directive[Thick, Magenta]],
  26. Cyan, Disk[{1, 1}, .35], EdgeForm[Directive[Thick, Magenta]],
  27. Cyan, Disk[{2, 1}, .35], EdgeForm[Directive[Thick, Magenta]],
  28. Cyan, Disk[{3, 1}, .35], EdgeForm[Directive[Thick, Magenta]],
  29. Cyan, Disk[{1, 2}, .35], EdgeForm[Directive[Thick, Magenta]],
  30. Cyan, Disk[{2, 2}, .35], EdgeForm[Directive[Thick, Magenta]],
  31. Cyan, Disk[{3, 2}, .35], EdgeForm[Directive[Thick, Magenta]],
  32. Cyan, Disk[{2, 0}, .35], EdgeForm[Directive[Thick, Magenta]],
  33. Cyan, Disk[{2, 3}, .35], EdgeForm[Directive[Thick, Magenta]],
  34. Cyan, Disk[{2, 4}, .35], Darker[Green, 0.5],
  35. Style[Text[\[NeutralSmiley], pos1], FontSize -> 36], Blue,
  36. Style[Text[\[FreakedSmiley], pos2], FontSize -> 48], Orange,
  37. Style[Text[\[FreakedSmiley], pos3],
  38. FontSize -> 48]}]]], {"UpArrowKeyDown" :> {message = "",
  39. Switch = True, Stick = False,
  40. If[(**){x1, y1 + 1} == {x2, y2 - 1} || {x1, y1 + 1} == {x2,
  41. y2} || {x1, y1 + 1} == {x3, y3} || {x3, y3 + 1} == {x2,
  42. y2 - 1} || {x3, y3 + 1} == {x2,
  43. y2}, {Which[{x3, y3 + 1} == {x2, y2 - 1}, {pos1 =
  44. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, pos2 = pos2,
  45. pos3 = pos3}, {x3, y3 + 1} == {x2, y2}, {pos1 =
  46. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, pos2 = pos2,
  47. pos3 = pos3}, {x1, y1 + 1} == {x2, y2 - 1}, {pos1 =
  48. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  49. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  50. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  51. message = "Gameover", DotT = {2, (4 - .51)},
  52. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  53. Switch = False}, {x1, y1 + 1} == {x2, y2}, {pos1 =
  54. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  55. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  56. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1,
  57. y1 + 1} == {x3, y3}, {Which[
  58. Intersection[
  59. bound, {{x3, y3 + 1}}] == {{x3, y3 + 1}}, {pos1 =
  60. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  61. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  62. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3,
  63. y3 + 1} == {x2, y2 - 1}, {pos1 =
  64. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  65. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  66. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  67. message = "Gameover", DotT = {2, (4 - .51)},
  68. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  69. Switch = False},
  70. Intersection[
  71. bound, {{x3, y3 + 1}}] != {{x3, y3 + 1}}, {pos1 =
  72. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}},
  73. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}},
  74. pos3 = pos3 /. {{x3, y3} -> {x3 = x3,
  75. y3 = y3 +
  76. 1}}}]}]}, {If[(*Test if next move out of bound.*)
  77. Intersection[bound, {{x1, y1 + 1}}] == {{x1, y1 + 1}}, {pos1 =
  78. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True},
  79. pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}],
  80. If[(*Test if next move out of bound.*)
  81. Intersection[bound, {{x2, y2 - 1}}] == {{x2, y2 - 1}},
  82. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  83. If[Stick == True,
  84. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  85. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}}]],
  86. If[(*Test if next move out of bound.*)
  87. Intersection[bound, {{x3, y3 + 1}}] == {{x3, y3 + 1}},
  88. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  89. If[Stick == True,
  90. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  91. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 + 1}}]]}],
  92. If[Switch == True, {DotT = {a2 = x2, b2 = y2 - .51},
  93. DotL = {a1 = x1, b1 = y1 + .51},
  94. DotB = {a3 = x3, b3 = y3 + .51}}], Switch = True,
  95. If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1,
  96. 4} && {x2, y2} == {3, 4}, message = "Win"]},
  97. "DownArrowKeyDown" :> {message = "", Switch = True, Stick = False,
  98. If[(**){x1, y1 - 1} == {x2, y2 + 1} || {x1, y1 - 1} == {x2,
  99. y2} || {x1, y1 - 1} == {x3, y3} || {x3, y3 - 1} == {x2,
  100. y2 + 1} || {x3, y3 - 1} == {x2,
  101. y2}, {Which[{x3, y3 - 1} == {x2, y2 + 1}, {pos1 =
  102. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, pos2 = pos2,
  103. pos3 = pos3}, {x3, y3 - 1} == {x2, y2}, {pos1 =
  104. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, pos2 = pos2,
  105. pos3 = pos3}, {x1, y1 - 1} == {x2, y2 + 1}, {pos1 =
  106. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  107. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  108. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  109. message = "Gameover", DotT = {2, (4 - .51)},
  110. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  111. Switch = False}, {x1, y1 - 1} == {x2, y2}, {pos1 =
  112. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  113. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  114. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1,
  115. y1 - 1} == {x3, y3}, {Which[
  116. Intersection[
  117. bound, {{x3, y3 - 1}}] == {{x3, y3 - 1}}, {pos1 =
  118. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  119. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  120. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3,
  121. y3 - 1} == {x2, y2 + 1}, {pos1 =
  122. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  123. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  124. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  125. message = "Gameover", DotT = {2, (4 - .51)},
  126. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  127. Switch = False},
  128. Intersection[
  129. bound, {{x3, y3 - 1}}] != {{x3, y3 - 1}}, {pos1 =
  130. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}},
  131. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}},
  132. pos3 = pos3 /. {{x3, y3} -> {x3 = x3,
  133. y3 = y3 -
  134. 1}}}]}]}, {If[(*Test if next move out of bound.*)
  135. Intersection[bound, {{x1, y1 - 1}}] == {{x1, y1 - 1}}, {pos1 =
  136. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True},
  137. pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}],
  138. If[(*Test if next move out of bound.*)
  139. Intersection[bound, {{x2, y2 + 1}}] == {{x2, y2 + 1}},
  140. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  141. If[Stick == True,
  142. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  143. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}}]],
  144. If[(*Test if next move out of bound.*)
  145. Intersection[bound, {{x3, y3 - 1}}] == {{x3, y3 - 1}},
  146. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  147. If[Stick == True,
  148. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  149. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 - 1}}]]}],
  150. If[Switch == True, {DotT = {a2 = x2, b2 = y2 + .51},
  151. DotL = {a1 = x1, b1 = y1 - .51},
  152. DotB = {a3 = x3, b3 = y3 - .51}}], Switch = True,
  153. If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1,
  154. 4} && {x2, y2} == {3, 4}, message = "Win"]},
  155. "LeftArrowKeyDown" :> {message = "", Switch = True, Stick = False,
  156. If[(**){x1 - 1, y1} == {x2 + 1, y2} || {x1 - 1, y1} == {x2,
  157. y2} || {x1 - 1, y1} == {x3, y3} || {x3 - 1, y3} == {x2 + 1,
  158. y2} || {x3 - 1, y3} == {x2,
  159. y2}, {Which[{x3 - 1, y3} == {x2 + 1, y2}, {pos1 =
  160. pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, pos2 = pos2,
  161. pos3 = pos3}, {x3 - 1, y3} == {x2, y2}, {pos1 =
  162. pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, pos2 = pos2,
  163. pos3 = pos3}, {x1 - 1, y1} == {x2 + 1, y2}, {pos1 =
  164. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  165. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  166. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  167. message = "Gameover", DotT = {2, (4 - .51)},
  168. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  169. Switch = False}, {x1 - 1, y1} == {x2, y2}, {pos1 =
  170. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  171. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  172. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1 - 1,
  173. y1} == {x3, y3}, {Which[
  174. Intersection[
  175. bound, {{x3 - 1, y3}}] == {{x3 - 1, y3}}, {pos1 =
  176. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  177. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  178. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3 - 1,
  179. y3} == {x2 + 1, y2}, {pos1 =
  180. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  181. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  182. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  183. message = "Gameover", DotT = {2, (4 - .51)},
  184. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  185. Switch = False},
  186. Intersection[
  187. bound, {{x3 - 1, y3}}] != {{x3 - 1, y3}}, {pos1 =
  188. pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}},
  189. pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}},
  190. pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1,
  191. y3 = y3}}}]}]}, {If[(*Test if next move out of bound.*)
  192. Intersection[bound, {{x1 - 1, y1}}] == {{x1 - 1, y1}}, {pos1 =
  193. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True},
  194. pos1 = pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}],
  195. If[(*Test if next move out of bound.*)
  196. Intersection[bound, {{x2 + 1, y2}}] == {{x2 + 1, y2}},
  197. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  198. If[Stick == True,
  199. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  200. pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}}]],
  201. If[(*Test if next move out of bound.*)
  202. Intersection[bound, {{x3 - 1, y3}}] == {{x3 - 1, y3}},
  203. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  204. If[Stick == True,
  205. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  206. pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1, y3 = y3}}]]}],
  207. If[Switch == True, {DotT = {a2 = x2 + .51, b2 = y2},
  208. DotL = {a1 = x1 - .51, b1 = y1},
  209. DotB = {a3 = x3 - .51, b3 = y3}}], Switch = True,
  210. If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1,
  211. 4} && {x2, y2} == {3, 4}, message = "Win"]},
  212. "RightArrowKeyDown" :> {message = "", Switch = True, Stick = False,
  213. If[(**){x1 + 1, y1} == {x2 - 1, y2} || {x1 + 1, y1} == {x2,
  214. y2} || {x1 + 1, y1} == {x3, y3} || {x3 + 1, y3} == {x2 - 1,
  215. y2} || {x3 + 1, y3} == {x2,
  216. y2}, {Which[{x3 + 1, y3} == {x2 - 1, y2}, {pos1 =
  217. pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, pos2 = pos2,
  218. pos3 = pos3}, {x3 + 1, y3} == {x2, y2}, {pos1 =
  219. pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, pos2 = pos2,
  220. pos3 = pos3}, {x1 + 1, y1} == {x2 - 1, y2}, {pos1 =
  221. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  222. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  223. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  224. message = "Gameover", DotT = {2, (4 - .51)},
  225. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  226. Switch = False}, {x1 + 1, y1} == {x2, y2}, {pos1 =
  227. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  228. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  229. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1 + 1,
  230. y1} == {x3, y3}, {Which[
  231. Intersection[
  232. bound, {{x3 + 1, y3}}] == {{x3 + 1, y3}}, {pos1 =
  233. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
  234. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  235.  
  236. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3 + 1,
  237. y3} == {x2 - 1, y2}, {pos1 =
  238. pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
  239. pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
  240. pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
  241. message = "Gameover", DotT = {2, (4 - .51)},
  242. DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)},
  243. Switch = False},
  244. Intersection[
  245. bound, {{x3 + 1, y3}}] != {{x3 + 1, y3}}, {pos1 =
  246. pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}},
  247. pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}},
  248. pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1,
  249. y3 = y3}}}]}]}, {If[(*Test if next move out of bound.*)
  250. Intersection[bound, {{x1 + 1, y1}}] == {{x1 + 1, y1}}, {pos1 =
  251. pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True},
  252. pos1 = pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}],
  253. If[(*Test if next move out of bound.*)
  254. Intersection[bound, {{x2 - 1, y2}}] == {{x2 - 1, y2}},
  255. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  256. If[Stick == True,
  257. pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
  258. pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}}]],
  259. If[(*Test if next move out of bound.*)
  260. Intersection[bound, {{x3 + 1, y3}}] == {{x3 + 1, y3}},
  261. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  262. If[Stick == True,
  263. pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
  264. pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1, y3 = y3}}]]}],
  265. If[Switch == True, {DotT = {a2 = x2 - .51, b2 = y2},
  266. DotL = {a1 = x1 + .51, b1 = y1},
  267. DotB = {a3 = x3 + .51, b3 = y3}}], Switch = True,
  268. If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1,
  269. 4} && {x2, y2} == {3, 4}, message = "Win"]}}]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement