[英]How to make a Matrix Class in smalltalk Visual Works?
I am new to smalltalk and trying to make a simple TicTacToe game, I want my model class to be a matrix but I can't find a way to do it on Visual Works. 我是Smalltalk的新手,正在尝试制作一个简单的TicTacToe游戏,我希望我的模型类成为矩阵,但我找不到在Visual Works上做到这一点的方法。 I've been following this tutorial : http://nerdysermons.blogspot.fr/2012/03/tictactoe-game-in-pharo-smalltalk.html , it works just fine with Pharo but I'm having trouble with the Matrix type and also the simplebuttonmorph. 我一直在关注本教程: http : //nerdysermons.blogspot.fr/2012/03/tictactoe-game-in-pharo-smalltalk.html ,它在Pharo上工作正常,但在使用Matrix类型时遇到问题以及simplebuttonmorph。 Can anyone please explain the syntax/packages/libraries between Pharo and VisualWorks? 谁能解释一下Pharo和VisualWorks之间的语法/软件包/库吗? Thank you . 谢谢 。
The following is a suggestion - there are many ways to implement matrices. 以下是一个建议-有很多实现矩阵的方法。
cellNumberAt: row at: column ^(row - 1) * numberOfColumns + column at: row at: column put: value cells at: (self cellNumberAt: row at: column) put: value at: row at: column ^cells at: (self cellNumberAt: row at: column) rowAt: rowNumber | row | row := OrderedCollection new. 1 to: numberOfColumns do: [:columnNumber | row add: (self at: rowNumber at: columnNumber)]. ^row columnAt: columnNumber | column | column := OrderedCollection new. 1 to: numberOfRows do: [:rowNumber | column add: (self at: rowNumber at: columnNumber)]. ^column
I hope that helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.