Examples.js 26 KB

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