View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

OBY27

PREV ------ ● TOP ● ------ NEXTUploaded Image: imager.jpg


オビーに記憶させる

オビーが言葉を覚えられるようにします。
っていってもインスタンス変数に入れるのを覚えさせる。
それを引き出すのを思い出すってことなんすけどね。

■インスタンス変数を追加でごじゃる

Obyクラス
言葉を覚えてもらうインスタンス変数memoryBankでする。
--------------------------------------------
Morph subclass: #Oby
	instanceVariableNames: 'face eye eyes nose lips ears hair hat memoryBank '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'ObyMorph'
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )


■メソッドを修正。

initializeメソッド
Dictionaryコレクションを生成してmemoryBankにしまする。
--------------------------------------------
initialize
	super initialize.

	"土台の設定"
	self extent: 80@80.
	self color: (Color r: 1.0 g: 1.0 b: 1.0 alpha: 0.5).
	self borderWidth: 0.

	"顔の生成"
	face _ ObyFace new.
	self addMorph: face.
	face align: face center with: self center.

	"目の生成"
	eyes _ ObyEyes new.
	self addMorph: eyes.
	eyes align: eyes center with: self center + (0 @ 0).

	"口の生成"
	lips _ ObyLips new.
	self addMorph: lips.
	lips align: lips center with: self center + (0 @ 23).

	"鼻の生成"
	nose _ ObyNose new.
	self addMorph: nose.
	nose align: nose center with: self center + (0 @ 5).

	memoryBank _ Dictionary new.
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )




Obyクラスmomorizeメソッド
at:putでmemoryBankにキーワード、言葉を登録できるようにしまする。
--------------------------------------------
memorize: aKey string: aString
	memoryBank at: aKey put: aString.
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )



Obyクラスrememberメソッド
memoryBankからキーワードで言葉を取り出せるようにします。
言葉はバルーンで表示ね。
キーワードがなかったら「・・・」を表示するっす。
--------------------------------------------
remember: aKey
	(memoryBank at: aKey) ifNil: [ self showBalloon: '. . .'].
	self showBalloon: (memoryBank at: aKey) asString.
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )



Obyクラスfogetメソッド
覚えた言葉を忘れるメソッド。キーワードで指定するのねん。
--------------------------------------------
foget: aKey
	memoryBank at: aKey put: '. . . '.
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )




★インスタンスを出して試してみる

--------------------------------------------
boby _ Oby new openInWorld.
boby memorize: #apple string: 'そりゃリンゴだべ?'.
boby memorize: #grape string: 'ぐらっぺっておぼえただろ?'.
boby remember: #apple.
--------------------------------------------
Alt + d ( Cmd + d )

        Uploaded Image: image.jpg


記憶を消すとこうなりまする。
--------------------------------------------
boby forget: #apple.
boby remember: #apple.
--------------------------------------------
Alt + d ( Cmd + d )

        Uploaded Image: image1.jpg






PREV ------ ● TOP ● ------ NEXT







■ MEMO ■

Links to this Page