Examples.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. smalltalk.addClass('Counter', smalltalk.Widget, ['count', 'header'], 'Examples');
  2. smalltalk.addMethod(
  3. '_initialize',
  4. smalltalk.method({
  5. selector: 'initialize',
  6. category: 'initialization',
  7. fn: function () {
  8. var self = this;
  9. self.klass.superclass.fn.prototype._initialize.apply(self, []);
  10. self['@count'] = 0;
  11. return self;
  12. },
  13. source: unescape('initialize%0A%20%20%20%20super%20initialize.%0A%20%20%20%20count%20%3A%3D%200%0A')}),
  14. smalltalk.Counter);
  15. smalltalk.addMethod(
  16. '_renderOn_',
  17. smalltalk.method({
  18. selector: 'renderOn:',
  19. category: 'rendering',
  20. fn: function (html) {
  21. var self = this;
  22. self['@header'] = function ($rec) {smalltalk.send($rec, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);return smalltalk.send($rec, "_yourself", []);}(smalltalk.send(html, "_h1", []));
  23. (function ($rec) {smalltalk.send($rec, "_with_", [unescape("++")]);return smalltalk.send($rec, "_onClick_", [function () {return smalltalk.send(self, "_increase", []);}]);}(smalltalk.send(html, "_button", [])));
  24. (function ($rec) {smalltalk.send($rec, "_with_", [unescape("--")]);return smalltalk.send($rec, "_onClick_", [function () {return smalltalk.send(self, "_decrease", []);}]);}(smalltalk.send(html, "_button", [])));
  25. return self;
  26. },
  27. source: unescape('renderOn%3A%20html%0A%20%20%20%20header%20%3A%3D%20html%20h1%20%0A%09with%3A%20count%20asString%3B%0A%09yourself.%0A%20%20%20%20html%20button%0A%09with%3A%20%27++%27%3B%0A%09onClick%3A%20%5Bself%20increase%5D.%0A%20%20%20%20html%20button%0A%09with%3A%20%27--%27%3B%0A%09onClick%3A%20%5Bself%20decrease%5D%0A')}),
  28. smalltalk.Counter);
  29. smalltalk.addMethod(
  30. '_increase',
  31. smalltalk.method({
  32. selector: 'increase',
  33. category: 'actions',
  34. fn: function () {
  35. var self = this;
  36. self['@count'] = smalltalk.send(self['@count'], "__plus", [1]);
  37. smalltalk.send(self['@header'], "_contents_", [function (html) {return smalltalk.send(html, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);}]);
  38. return self;
  39. },
  40. source: unescape('increase%0A%20%20%20%20count%20%3A%3D%20count%20+%201.%0A%20%20%20%20header%20contents%3A%20%5B%3Ahtml%20%7C%20html%20with%3A%20count%20asString%5D')}),
  41. smalltalk.Counter);
  42. smalltalk.addMethod(
  43. '_decrease',
  44. smalltalk.method({
  45. selector: 'decrease',
  46. category: 'actions',
  47. fn: function () {
  48. var self = this;
  49. self['@count'] = smalltalk.send(self['@count'], "__minus", [1]);
  50. smalltalk.send(self['@header'], "_contents_", [function (html) {return smalltalk.send(html, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);}]);
  51. return self;
  52. },
  53. source: unescape('decrease%0A%20%20%20%20count%20%3A%3D%20count%20-%201.%0A%20%20%20%20header%20contents%3A%20%5B%3Ahtml%20%7C%20html%20with%3A%20count%20asString%5D')}),
  54. smalltalk.Counter);
  55. smalltalk.addClass('Tetris', smalltalk.Widget, ['renderingContext', 'timer', 'speed', 'score', 'rows', 'movingPiece'], 'Examples');
  56. smalltalk.addMethod(
  57. '_renderOn_',
  58. smalltalk.method({
  59. selector: 'renderOn:',
  60. category: 'rendering',
  61. fn: function (html) {
  62. var self = this;
  63. (function ($rec) {smalltalk.send($rec, "_class_", ["tetris"]);return smalltalk.send($rec, "_with_", [function () {smalltalk.send(smalltalk.send(html, "_h3", []), "_with_", ["Tetris"]);smalltalk.send(self, "_renderCanvasOn_", [html]);return smalltalk.send(self, "_renderButtonsOn_", [html]);}]);}(smalltalk.send(html, "_div", [])));
  64. return self;
  65. },
  66. source: unescape('renderOn%3A%20html%0A%09html%20div%0A%09%09class%3A%20%27tetris%27%3B%0A%09%09with%3A%20%5B%0A%09%09%09html%20h3%20with%3A%20%27Tetris%27.%0A%09%09%09self%20renderCanvasOn%3A%20html.%0A%09%09%09self%20renderButtonsOn%3A%20html%5D')}),
  67. smalltalk.Tetris);
  68. smalltalk.addMethod(
  69. '_renderCanvasOn_',
  70. smalltalk.method({
  71. selector: 'renderCanvasOn:',
  72. category: 'rendering',
  73. fn: function (html) {
  74. var self = this;
  75. var canvas = nil;
  76. canvas = smalltalk.send(html, "_canvas", []);
  77. smalltalk.send(canvas, "_at_put_", ["width", smalltalk.send(smalltalk.send(self, "_width", []), "_asString", [])]);
  78. smalltalk.send(canvas, "_at_put_", ["height", smalltalk.send(smalltalk.send(self, "_height", []), "_asString", [])]);
  79. self['@renderingContext'] = smalltalk.send(smalltalk.CanvasRenderingContext, "_tagBrush_", [canvas]);
  80. smalltalk.send(self, "_redraw", []);
  81. return self;
  82. },
  83. source: unescape('renderCanvasOn%3A%20html%0A%09%7C%20canvas%20%7C%0A%09canvas%20%3A%3D%20html%20canvas.%0A%09canvas%20at%3A%20%27width%27%20put%3A%20self%20width%20asString.%0A%09canvas%20at%3A%20%27height%27%20put%3A%20self%20height%20asString.%0A%09renderingContext%20%3A%3D%20CanvasRenderingContext%20tagBrush%3A%20canvas.%0A%09self%20redraw')}),
  84. smalltalk.Tetris);
  85. smalltalk.addMethod(
  86. '_renderButtonsOn_',
  87. smalltalk.method({
  88. selector: 'renderButtonsOn:',
  89. category: 'rendering',
  90. fn: function (html) {
  91. var self = this;
  92. (function ($rec) {smalltalk.send($rec, "_class_", ["tetris_buttons"]);return smalltalk.send($rec, "_with_", [function () {(function ($rec) {smalltalk.send($rec, "_with_", ["New game"]);return smalltalk.send($rec, "_onClick_", [function () {return smalltalk.send(self, "_startNewGame", []);}]);}(smalltalk.send(html, "_button", [])));return function ($rec) {smalltalk.send($rec, "_with_", [unescape("play/pause")]);return smalltalk.send($rec, "_onClick_", [function () {return smalltalk.send(self, "_update", []);}]);}(smalltalk.send(html, "_button", []));}]);}(smalltalk.send(html, "_div", [])));
  93. return self;
  94. },
  95. source: unescape('renderButtonsOn%3A%20html%0A%09html%20div%20%0A%09%09class%3A%20%27tetris_buttons%27%3B%0A%09%09with%3A%20%5B%0A%09%09%09html%20button%0A%09%09%09%09with%3A%20%27New%20game%27%3B%0A%09%09%09%09onClick%3A%20%5Bself%20startNewGame%5D.%0A%09%09%09html%20button%0A%09%09%09%09with%3A%20%27play/pause%27%3B%0A%09%09%09%09onClick%3A%20%5Bself%20update%5D%5D')}),
  96. smalltalk.Tetris);
  97. smalltalk.addMethod(
  98. '_initialize',
  99. smalltalk.method({
  100. selector: 'initialize',
  101. category: 'initialization',
  102. fn: function () {
  103. var self = this;
  104. self.klass.superclass.fn.prototype._initialize.apply(self, []);
  105. smalltalk.send(self, "_newGame", []);
  106. return self;
  107. },
  108. source: unescape('initialize%0A%09super%20initialize.%0A%09self%20newGame')}),
  109. smalltalk.Tetris);
  110. smalltalk.addMethod(
  111. '_startNewGame',
  112. smalltalk.method({
  113. selector: 'startNewGame',
  114. category: 'actions',
  115. fn: function () {
  116. var self = this;
  117. smalltalk.send(self, "_newGame", []);
  118. smalltalk.send(self['@timer'], "_ifNotNil_", [function () {return smalltalk.send(self['@timer'], "_clearInterval", []);}]);
  119. self['@timer'] = smalltalk.send(function () {return smalltalk.send(self, "_nextStep", []);}, "_valueWithInterval_", [self['@speed']]);
  120. return self;
  121. },
  122. source: unescape('startNewGame%0A%09self%20newGame.%0A%09timer%20ifNotNil%3A%20%5Btimer%20clearInterval%5D.%0A%09timer%20%3A%3D%20%5Bself%20nextStep%5D%20valueWithInterval%3A%20speed')}),
  123. smalltalk.Tetris);
  124. smalltalk.addMethod(
  125. '_width',
  126. smalltalk.method({
  127. selector: 'width',
  128. category: 'accessing',
  129. fn: function () {
  130. var self = this;
  131. return smalltalk.send(smalltalk.send(self, "_class", []), "_width", []);
  132. return self;
  133. },
  134. source: unescape('width%0A%09%5Eself%20class%20width')}),
  135. smalltalk.Tetris);
  136. smalltalk.addMethod(
  137. '_height',
  138. smalltalk.method({
  139. selector: 'height',
  140. category: 'accessing',
  141. fn: function () {
  142. var self = this;
  143. return smalltalk.send(smalltalk.send(self, "_class", []), "_height", []);
  144. return self;
  145. },
  146. source: unescape('height%0A%09%5Eself%20class%20height')}),
  147. smalltalk.Tetris);
  148. smalltalk.addMethod(
  149. '_nextStep',
  150. smalltalk.method({
  151. selector: 'nextStep',
  152. category: 'actions',
  153. fn: function () {
  154. var self = this;
  155. smalltalk.send(self['@movingPiece'], "_ifNil_", [function () {return smalltalk.send(self, "_newPiece", []);}]);
  156. smalltalk.send(smalltalk.send(self['@movingPiece'], "_canMoveIn_", [self]), "_ifTrue_ifFalse_", [function () {return smalltalk.send(self['@movingPiece'], "_position_", [smalltalk.send(smalltalk.send(self['@movingPiece'], "_position", []), "__plus", [smalltalk.send(0, "__at", [1])])]);}, function () {return smalltalk.send(self, "_newPiece", []);}]);
  157. smalltalk.send(self, "_redraw", []);
  158. return self;
  159. },
  160. source: unescape('nextStep%0A%09movingPiece%20ifNil%3A%20%5Bself%20newPiece%5D.%0A%09%28movingPiece%20canMoveIn%3A%20self%29%0A%09%09ifTrue%3A%20%5BmovingPiece%20position%3A%20movingPiece%20position%20+%20%280@1%29%5D%0A%09%09ifFalse%3A%20%5Bself%20newPiece%5D.%0A%09self%20redraw%0A%09')}),
  161. smalltalk.Tetris);
  162. smalltalk.addMethod(
  163. '_redraw',
  164. smalltalk.method({
  165. selector: 'redraw',
  166. category: 'actions',
  167. fn: function () {
  168. var self = this;
  169. smalltalk.send(self['@renderingContext'], "_clearRectFrom_to_", [smalltalk.send(0, "__at", [smalltalk.send(self, "_width", [])]), smalltalk.send(0, "__at", [smalltalk.send(self, "_height", [])])]);
  170. (function ($rec) {smalltalk.send($rec, "_drawMap", []);return smalltalk.send($rec, "_drawPiece", []);}(self));
  171. return self;
  172. },
  173. source: unescape('redraw%0A%09renderingContext%20clearRectFrom%3A%200@%20self%20width%20to%3A%200@%20self%20height.%0A%09self%20%0A%09%09drawMap%3B%0A%09%09drawPiece')}),
  174. smalltalk.Tetris);
  175. smalltalk.addMethod(
  176. '_drawMap',
  177. smalltalk.method({
  178. selector: 'drawMap',
  179. category: 'actions',
  180. fn: function () {
  181. var self = this;
  182. (function ($rec) {smalltalk.send($rec, "_fillStyle_", [unescape("%23fafafa")]);return smalltalk.send($rec, "_fillRectFrom_to_", [smalltalk.send(0, "__at", [0]), smalltalk.send(smalltalk.send(self, "_width", []), "__at", [smalltalk.send(self, "_height", [])])]);}(self['@renderingContext']));
  183. (function ($rec) {smalltalk.send($rec, "_lineWidth_", [0.5]);return smalltalk.send($rec, "_strokeStyle_", [unescape("%23999")]);}(self['@renderingContext']));
  184. smalltalk.send(0, "_to_do_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_squares", []), "_x", []), function (each) {var x = nil;x = smalltalk.send(each, "__star", [smalltalk.send(smalltalk.send(self, "_class", []), "_squareSize", [])]);return smalltalk.send(self, "_drawLineFrom_to_", [smalltalk.send(x, "__at", [0]), smalltalk.send(x, "__at", [smalltalk.send(self, "_height", [])])]);}]);
  185. smalltalk.send(0, "_to_do_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_squares", []), "_y", []), function (each) {var y = nil;y = smalltalk.send(each, "__star", [smalltalk.send(smalltalk.send(self, "_class", []), "_squareSize", [])]);return smalltalk.send(self, "_drawLineFrom_to_", [smalltalk.send(0, "__at", [y]), smalltalk.send(smalltalk.send(self, "_width", []), "__at", [y])]);}]);
  186. return self;
  187. },
  188. source: unescape('drawMap%0A%09renderingContext%20%0A%09%09fillStyle%3A%20%27%23fafafa%27%3B%0A%09%09fillRectFrom%3A%200@0%20to%3A%20self%20width@self%20height.%0A%09renderingContext%20%0A%09%09lineWidth%3A%200.5%3B%0A%09%09strokeStyle%3A%20%27%23999%27.%0A%090%20to%3A%20self%20class%20squares%20x%20do%3A%20%5B%3Aeach%20%7C%20%7C%20x%20%7C%0A%09%09x%20%3A%3D%20each%20*%20self%20class%20squareSize.%0A%09%09self%20drawLineFrom%3A%20x@0%20to%3A%20x@self%20height%5D.%0A%090%20to%3A%20self%20class%20squares%20y%20do%3A%20%5B%3Aeach%20%7C%20%7C%20y%20%7C%0A%09%09y%20%3A%3D%20each%20*%20self%20class%20squareSize.%0A%09%09self%20drawLineFrom%3A%200@y%20to%3A%20self%20width@y%5D.')}),
  189. smalltalk.Tetris);
  190. smalltalk.addMethod(
  191. '_drawLineFrom_to_',
  192. smalltalk.method({
  193. selector: 'drawLineFrom:to:',
  194. category: 'actions',
  195. fn: function (aPoint, anotherPoint) {
  196. var self = this;
  197. (function ($rec) {smalltalk.send($rec, "_beginPath", []);smalltalk.send($rec, "_moveTo_", [aPoint]);smalltalk.send($rec, "_lineTo_", [anotherPoint]);return smalltalk.send($rec, "_stroke", []);}(self['@renderingContext']));
  198. return self;
  199. },
  200. source: unescape('drawLineFrom%3A%20aPoint%20to%3A%20anotherPoint%0A%09renderingContext%20%0A%09%09beginPath%3B%0A%09%09moveTo%3A%20aPoint%3B%0A%09%09lineTo%3A%20anotherPoint%3B%0A%09%09stroke')}),
  201. smalltalk.Tetris);
  202. smalltalk.addMethod(
  203. '_newGame',
  204. smalltalk.method({
  205. selector: 'newGame',
  206. category: 'actions',
  207. fn: function () {
  208. var self = this;
  209. self['@rows'] = [];
  210. self['@movingPiece'] = nil;
  211. self['@speed'] = 200;
  212. self['@score'] = 0;
  213. return self;
  214. },
  215. source: unescape('newGame%0A%09rows%20%3A%3D%20%23%28%29.%0A%09movingPiece%20%3A%3D%20nil.%0A%09speed%20%3A%3D%20200.%0A%09score%20%3A%3D%200')}),
  216. smalltalk.Tetris);
  217. smalltalk.addMethod(
  218. '_newPiece',
  219. smalltalk.method({
  220. selector: 'newPiece',
  221. category: 'actions',
  222. fn: function () {
  223. var self = this;
  224. self['@movingPiece'] = smalltalk.send(smalltalk.TetrisPiece, "_atRandom", []);
  225. return self;
  226. },
  227. source: unescape('newPiece%0A%09movingPiece%20%3A%3D%20TetrisPiece%20atRandom')}),
  228. smalltalk.Tetris);
  229. smalltalk.addMethod(
  230. '_squares',
  231. smalltalk.method({
  232. selector: 'squares',
  233. category: 'accessing',
  234. fn: function () {
  235. var self = this;
  236. return smalltalk.send(smalltalk.send(self, "_class", []), "_squares", []);
  237. return self;
  238. },
  239. source: unescape('squares%0A%09%5Eself%20class%20squares')}),
  240. smalltalk.Tetris);
  241. smalltalk.addMethod(
  242. '_gluePiece_',
  243. smalltalk.method({
  244. selector: 'gluePiece:',
  245. category: 'accessing',
  246. fn: function (aPiece) {
  247. var self = this;
  248. smalltalk.send(aPiece, "_glueOn_", [self]);
  249. return self;
  250. },
  251. source: unescape('gluePiece%3A%20aPiece%0A%09aPiece%20glueOn%3A%20self%0A%09')}),
  252. smalltalk.Tetris);
  253. smalltalk.addMethod(
  254. '_drawRows',
  255. smalltalk.method({
  256. selector: 'drawRows',
  257. category: 'actions',
  258. fn: function () {
  259. var self = this;
  260. smalltalk.send(smalltalk.send(self, "_rows", []), "_do_", [function (each) {return nil;}]);
  261. smalltalk.send(self['@movingPiece'], "_ifNotNil_", [function () {return smalltalk.send(self['@movingPiece'], "_drawOn_", [self['@renderingContext']]);}]);
  262. return self;
  263. },
  264. source: unescape('drawRows%0A%09self%20rows%20do%3A%20%5B%3Aeach%20%7C%5D.%0A%09movingPiece%20ifNotNil%3A%20%5BmovingPiece%20drawOn%3A%20renderingContext%5D')}),
  265. smalltalk.Tetris);
  266. smalltalk.addMethod(
  267. '_drawPiece',
  268. smalltalk.method({
  269. selector: 'drawPiece',
  270. category: 'actions',
  271. fn: function () {
  272. var self = this;
  273. smalltalk.send(self['@movingPiece'], "_ifNotNil_", [function () {return smalltalk.send(self['@movingPiece'], "_drawOn_", [self['@renderingContext']]);}]);
  274. return self;
  275. },
  276. source: unescape('drawPiece%0A%09movingPiece%20ifNotNil%3A%20%5B%0A%09%09movingPiece%20drawOn%3A%20renderingContext%5D')}),
  277. smalltalk.Tetris);
  278. smalltalk.addMethod(
  279. '_rows',
  280. smalltalk.method({
  281. selector: 'rows',
  282. category: 'accessing',
  283. fn: function () {
  284. var self = this;
  285. return self['@rows'];
  286. return self;
  287. },
  288. source: unescape('rows%0A%09%22An%20array%20of%20rows.%20Each%20row%20is%20a%20collection%20of%20points.%22%0A%09%5Erows')}),
  289. smalltalk.Tetris);
  290. smalltalk.addMethod(
  291. '_addRow_',
  292. smalltalk.method({
  293. selector: 'addRow:',
  294. category: 'accessing',
  295. fn: function (aCollection) {
  296. var self = this;
  297. smalltalk.send(smalltalk.send(self, "_rows", []), "_add_", [aCollection]);
  298. return self;
  299. },
  300. source: unescape('addRow%3A%20aCollection%0A%09self%20rows%20add%3A%20aCollection')}),
  301. smalltalk.Tetris);
  302. smalltalk.addMethod(
  303. '_squareSize',
  304. smalltalk.method({
  305. selector: 'squareSize',
  306. category: 'accessing',
  307. fn: function () {
  308. var self = this;
  309. return 22;
  310. return self;
  311. },
  312. source: unescape('squareSize%0A%09%5E22')}),
  313. smalltalk.Tetris.klass);
  314. smalltalk.addMethod(
  315. '_width',
  316. smalltalk.method({
  317. selector: 'width',
  318. category: 'accessing',
  319. fn: function () {
  320. var self = this;
  321. return smalltalk.send(smalltalk.send(self, "_squareSize", []), "__star", [smalltalk.send(smalltalk.send(self, "_squares", []), "_x", [])]);
  322. return self;
  323. },
  324. source: unescape('width%0A%09%5Eself%20squareSize%20*%20%28self%20squares%20x%29')}),
  325. smalltalk.Tetris.klass);
  326. smalltalk.addMethod(
  327. '_height',
  328. smalltalk.method({
  329. selector: 'height',
  330. category: 'accessing',
  331. fn: function () {
  332. var self = this;
  333. return smalltalk.send(smalltalk.send(self, "_squareSize", []), "__star", [smalltalk.send(smalltalk.send(self, "_squares", []), "_y", [])]);
  334. return self;
  335. },
  336. source: unescape('height%0A%09%5Eself%20squareSize%20*%20%28self%20squares%20y%29')}),
  337. smalltalk.Tetris.klass);
  338. smalltalk.addMethod(
  339. '_squares',
  340. smalltalk.method({
  341. selector: 'squares',
  342. category: 'accessing',
  343. fn: function () {
  344. var self = this;
  345. return smalltalk.send(10, "__at", [15]);
  346. return self;
  347. },
  348. source: unescape('squares%0A%09%5E10@15')}),
  349. smalltalk.Tetris.klass);
  350. smalltalk.addClass('TetrisPiece', smalltalk.Widget, ['rotation', 'position'], 'Examples');
  351. smalltalk.addMethod(
  352. '_drawOn_',
  353. smalltalk.method({
  354. selector: 'drawOn:',
  355. category: 'drawing',
  356. fn: function (aRenderingContext) {
  357. var self = this;
  358. smalltalk.send(aRenderingContext, "_fillStyle_", [smalltalk.send(self, "_color", [])]);
  359. smalltalk.send(smalltalk.send(self, "_bounds", []), "_do_", [function (each) {return function ($rec) {smalltalk.send($rec, "_fillRectFrom_to_", [smalltalk.send(smalltalk.send(each, "__plus", [smalltalk.send(self, "_position", [])]), "__star", [smalltalk.send(smalltalk.Tetris, "_squareSize", [])]), smalltalk.send(smalltalk.send(1, "__at", [1]), "__star", [smalltalk.send(smalltalk.Tetris, "_squareSize", [])])]);smalltalk.send($rec, "_strokeStyle_", [unescape("%23999")]);smalltalk.send($rec, "_lineWidth_", [2]);return smalltalk.send($rec, "_strokeRectFrom_to_", [smalltalk.send(smalltalk.send(each, "__plus", [smalltalk.send(self, "_position", [])]), "__star", [smalltalk.send(smalltalk.Tetris, "_squareSize", [])]), smalltalk.send(smalltalk.send(1, "__at", [1]), "__star", [smalltalk.send(smalltalk.Tetris, "_squareSize", [])])]);}(aRenderingContext);}]);
  360. return self;
  361. },
  362. source: unescape('drawOn%3A%20aRenderingContext%0A%09aRenderingContext%20fillStyle%3A%20self%20color.%0A%09self%20bounds%20do%3A%20%5B%3Aeach%20%7C%0A%09%09aRenderingContext%20%0A%09%09%09fillRectFrom%3A%20each%20+%20self%20position*%20Tetris%20squareSize%20to%3A%201@1%20*%20Tetris%20squareSize%3B%0A%09%09%09strokeStyle%3A%20%27%23999%27%3B%0A%09%09%09lineWidth%3A%202%3B%0A%09%09%09strokeRectFrom%3A%20each%20+%20self%20position*%20Tetris%20squareSize%20to%3A%201@1%20*%20Tetris%20squareSize%5D')}),
  363. smalltalk.TetrisPiece);
  364. smalltalk.addMethod(
  365. '_rotation',
  366. smalltalk.method({
  367. selector: 'rotation',
  368. category: 'accessing',
  369. fn: function () {
  370. var self = this;
  371. return smalltalk.send(self['@rotation'], "_ifNil_", [function () {return self['@rotation'] = 1;}]);
  372. return self;
  373. },
  374. source: unescape('rotation%0A%09%5Erotation%20ifNil%3A%20%5Brotation%20%3A%3D%201%5D')}),
  375. smalltalk.TetrisPiece);
  376. smalltalk.addMethod(
  377. '_rotation_',
  378. smalltalk.method({
  379. selector: 'rotation:',
  380. category: 'accessing',
  381. fn: function (aNumber) {
  382. var self = this;
  383. self['@rotation'] = aNumber;
  384. return self;
  385. },
  386. source: unescape('rotation%3A%20aNumber%0A%09rotation%20%3A%3D%20aNumber')}),
  387. smalltalk.TetrisPiece);
  388. smalltalk.addMethod(
  389. '_position',
  390. smalltalk.method({
  391. selector: 'position',
  392. category: 'accessing',
  393. fn: function () {
  394. var self = this;
  395. return smalltalk.send(self['@position'], "_ifNil_", [function () {return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.Tetris, "_squares", []), "_x", []), "__slash", [2]), "__minus", [1]), "__at", [0]);}]);
  396. return self;
  397. },
  398. source: unescape('position%0A%09%5Eposition%20ifNil%3A%20%5B%28Tetris%20squares%20x%20/%202%29%20-1%20@%200%5D')}),
  399. smalltalk.TetrisPiece);
  400. smalltalk.addMethod(
  401. '_position_',
  402. smalltalk.method({
  403. selector: 'position:',
  404. category: 'accessing',
  405. fn: function (aPoint) {
  406. var self = this;
  407. return self['@position'] = aPoint;
  408. return self;
  409. },
  410. source: unescape('position%3A%20aPoint%0A%09%5Eposition%20%3A%3D%20aPoint')}),
  411. smalltalk.TetrisPiece);
  412. smalltalk.addMethod(
  413. '_bounds',
  414. smalltalk.method({
  415. selector: 'bounds',
  416. category: 'accessing',
  417. fn: function () {
  418. var self = this;
  419. smalltalk.send(self, "_subclassResponsibility", []);
  420. return self;
  421. },
  422. source: unescape('bounds%0A%09self%20subclassResponsibility')}),
  423. smalltalk.TetrisPiece);
  424. smalltalk.addMethod(
  425. '_color',
  426. smalltalk.method({
  427. selector: 'color',
  428. category: 'accessing',
  429. fn: function () {
  430. var self = this;
  431. return unescape("%23afa");
  432. return self;
  433. },
  434. source: unescape('color%0A%09%5E%27%23afa%27')}),
  435. smalltalk.TetrisPiece);
  436. smalltalk.addMethod(
  437. '_canMove',
  438. smalltalk.method({
  439. selector: 'canMove',
  440. category: 'testing',
  441. fn: function () {
  442. var self = this;
  443. return smalltalk.send(smalltalk.send(smalltalk.send(self, "_position", []), "_y", []), "__lt", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.Tetris, "_squares", []), "_y", []), "__minus", [smalltalk.send(self, "_height", [])])]);
  444. return self;
  445. },
  446. source: unescape('canMove%0A%09%5Eself%20position%20y%20%3C%20%28Tetris%20squares%20y%20-%20self%20height%29')}),
  447. smalltalk.TetrisPiece);
  448. smalltalk.addMethod(
  449. '_height',
  450. smalltalk.method({
  451. selector: 'height',
  452. category: 'accessing',
  453. fn: function () {
  454. var self = this;
  455. return 2;
  456. return self;
  457. },
  458. source: unescape('height%0A%09%5E2')}),
  459. smalltalk.TetrisPiece);
  460. smalltalk.addMethod(
  461. '_canMoveIn_',
  462. smalltalk.method({
  463. selector: 'canMoveIn:',
  464. category: 'testing',
  465. fn: function (aTetris) {
  466. var self = this;
  467. return smalltalk.send(smalltalk.send(smalltalk.send(self, "_position", []), "_y", []), "__lt", [smalltalk.send(smalltalk.send(smalltalk.send(aTetris, "_squares", []), "_y", []), "__minus", [smalltalk.send(self, "_height", [])])]);
  468. return self;
  469. },
  470. source: unescape('canMoveIn%3A%20aTetris%0A%09%5Eself%20position%20y%20%3C%20%28aTetris%20squares%20y%20-%20self%20height%29')}),
  471. smalltalk.TetrisPiece);
  472. smalltalk.addMethod(
  473. '_atRandom',
  474. smalltalk.method({
  475. selector: 'atRandom',
  476. category: 'instance creation',
  477. fn: function () {
  478. var self = this;
  479. return smalltalk.send(smalltalk.send(smalltalk.send(self, "_subclasses", []), "_at_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_subclasses", []), "_size", []), "_atRandom", [])]), "_new", []);
  480. return self;
  481. },
  482. source: unescape('atRandom%0A%09%5E%28self%20subclasses%20at%3A%20self%20subclasses%20size%20atRandom%29%20new')}),
  483. smalltalk.TetrisPiece.klass);
  484. smalltalk.addClass('TetrisPieceO', smalltalk.TetrisPiece, [], 'Examples');
  485. smalltalk.addMethod(
  486. '_bounds',
  487. smalltalk.method({
  488. selector: 'bounds',
  489. category: 'accessing',
  490. fn: function () {
  491. var self = this;
  492. return function ($rec) {smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [1])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [1])]);return smalltalk.send($rec, "_yourself", []);}(smalltalk.send(smalltalk.Array, "_new", []));
  493. return self;
  494. },
  495. source: unescape('bounds%0A%09%5EArray%20new%0A%09%09add%3A%200@0%3B%0A%09%09add%3A%200@1%3B%0A%09%09add%3A%201@0%3B%0A%09%09add%3A%201@1%3B%0A%09%09yourself')}),
  496. smalltalk.TetrisPieceO);
  497. smalltalk.addClass('TetrisPieceL', smalltalk.TetrisPiece, [], 'Examples');
  498. smalltalk.addMethod(
  499. '_bounds',
  500. smalltalk.method({
  501. selector: 'bounds',
  502. category: 'accessing',
  503. fn: function () {
  504. var self = this;
  505. return function ($rec) {smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [1])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [2])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [2])]);return smalltalk.send($rec, "_yourself", []);}(smalltalk.send(smalltalk.Array, "_new", []));
  506. return self;
  507. },
  508. source: unescape('bounds%0A%09%5EArray%20new%0A%09%09add%3A%200@0%3B%0A%09%09add%3A%200@1%3B%0A%09%09add%3A%200@2%3B%0A%09%09add%3A%201@2%3B%0A%09%09yourself')}),
  509. smalltalk.TetrisPieceL);
  510. smalltalk.addMethod(
  511. '_color',
  512. smalltalk.method({
  513. selector: 'color',
  514. category: 'accessing',
  515. fn: function () {
  516. var self = this;
  517. return unescape("%23ffa");
  518. return self;
  519. },
  520. source: unescape('color%0A%09%5E%27%23ffa%27')}),
  521. smalltalk.TetrisPieceL);
  522. smalltalk.addMethod(
  523. '_height',
  524. smalltalk.method({
  525. selector: 'height',
  526. category: 'accessing',
  527. fn: function () {
  528. var self = this;
  529. return 3;
  530. return self;
  531. },
  532. source: unescape('height%0A%09%5E3')}),
  533. smalltalk.TetrisPieceL);
  534. smalltalk.addClass('TetrisPieceJ', smalltalk.TetrisPiece, [], 'Examples');
  535. smalltalk.addMethod(
  536. '_color',
  537. smalltalk.method({
  538. selector: 'color',
  539. category: 'accessing',
  540. fn: function () {
  541. var self = this;
  542. return unescape("%23aaf");
  543. return self;
  544. },
  545. source: unescape('color%0A%09%5E%27%23aaf%27')}),
  546. smalltalk.TetrisPieceJ);
  547. smalltalk.addMethod(
  548. '_bounds',
  549. smalltalk.method({
  550. selector: 'bounds',
  551. category: 'accessing',
  552. fn: function () {
  553. var self = this;
  554. return function ($rec) {smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [1])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [2])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [2])]);return smalltalk.send($rec, "_yourself", []);}(smalltalk.send(smalltalk.Array, "_new", []));
  555. return self;
  556. },
  557. source: unescape('bounds%0A%09%5EArray%20new%0A%09%09add%3A%201@0%3B%0A%09%09add%3A%201@1%3B%0A%09%09add%3A%201@2%3B%0A%09%09add%3A%200@2%3B%0A%09%09yourself')}),
  558. smalltalk.TetrisPieceJ);
  559. smalltalk.addMethod(
  560. '_height',
  561. smalltalk.method({
  562. selector: 'height',
  563. category: 'accessing',
  564. fn: function () {
  565. var self = this;
  566. return 3;
  567. return self;
  568. },
  569. source: unescape('height%0A%09%5E3')}),
  570. smalltalk.TetrisPieceJ);
  571. smalltalk.addClass('TetrisPieceI', smalltalk.TetrisPiece, [], 'Examples');
  572. smalltalk.addMethod(
  573. '_color',
  574. smalltalk.method({
  575. selector: 'color',
  576. category: 'accessing',
  577. fn: function () {
  578. var self = this;
  579. return unescape("%23faa");
  580. return self;
  581. },
  582. source: unescape('color%0A%09%5E%27%23faa%27')}),
  583. smalltalk.TetrisPieceI);
  584. smalltalk.addMethod(
  585. '_bounds',
  586. smalltalk.method({
  587. selector: 'bounds',
  588. category: 'accessing',
  589. fn: function () {
  590. var self = this;
  591. return function ($rec) {smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [1])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [2])]);smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [3])]);return smalltalk.send($rec, "_yourself", []);}(smalltalk.send(smalltalk.Array, "_new", []));
  592. return self;
  593. },
  594. source: unescape('bounds%0A%09%5EArray%20new%0A%09%09add%3A%200@0%3B%0A%09%09add%3A%200@1%3B%0A%09%09add%3A%200@2%3B%0A%09%09add%3A%200@3%3B%0A%09%09yourself')}),
  595. smalltalk.TetrisPieceI);
  596. smalltalk.addMethod(
  597. '_height',
  598. smalltalk.method({
  599. selector: 'height',
  600. category: 'accessing',
  601. fn: function () {
  602. var self = this;
  603. return 4;
  604. return self;
  605. },
  606. source: unescape('height%0A%09%5E4')}),
  607. smalltalk.TetrisPieceI);
  608. smalltalk.addClass('TetrisPieceT', smalltalk.TetrisPiece, [], 'Examples');
  609. smalltalk.addMethod(
  610. '_bounds',
  611. smalltalk.method({
  612. selector: 'bounds',
  613. category: 'accessing',
  614. fn: function () {
  615. var self = this;
  616. return function ($rec) {smalltalk.send($rec, "_add_", [smalltalk.send(0, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(2, "__at", [0])]);smalltalk.send($rec, "_add_", [smalltalk.send(1, "__at", [1])]);return smalltalk.send($rec, "_yourself", []);}(smalltalk.send(smalltalk.Array, "_new", []));
  617. return self;
  618. },
  619. source: unescape('bounds%0A%09%5EArray%20new%0A%09%09add%3A%200@0%3B%0A%09%09add%3A%201@0%3B%0A%09%09add%3A%202@0%3B%0A%09%09add%3A%201@1%3B%0A%09%09yourself')}),
  620. smalltalk.TetrisPieceT);
  621. smalltalk.addMethod(
  622. '_color',
  623. smalltalk.method({
  624. selector: 'color',
  625. category: 'accessing',
  626. fn: function () {
  627. var self = this;
  628. return unescape("%23aaf");
  629. return self;
  630. },
  631. source: unescape('color%0A%09%5E%27%23aaf%27')}),
  632. smalltalk.TetrisPieceT);