Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SmalltalkJenga
'From Pharo7.0.0rc1 of 5 December 2018 [Build information: Pharo-7.0.0+rc1.build.19.sha.1fcbcd5170ad832066c54be29dd6b9bd66dc9575 (64 Bit)] on 19 December 2018 at 6:24:50.740241 pm'!
Object subclass: #SmalltalkJenga
instanceVariableNames: 'random classList turn'
classVariableNames: ''
poolDictionaries: ''
category: 'SmalltalkJenga'!
!SmalltalkJenga methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
playAll
[ self play ] doWhileTrue: [ 0 < (self listSize) ].
! !
!SmalltalkJenga methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
play
(0 < self listSize)
ifTrue: [
| target |
self turn: (self turn) + 1.
Transcript cr; show: ('Turn ', (self turn asString), '!!').
target := self classList removeAt: self randomIndex.
Transcript cr; show: ('Delete ', target asString, '!!').
"target removeFromSystem." ]
ifFalse: [
Transcript cr; show: ('Awesome!! All classes are deleted!!') ]! !
!SmalltalkJenga methodsFor: 'initialize' stamp: 'KazunoriUeda 12/19/2018 18:00'!
initialize
random := nil.
classList := nil.
turn := 0.! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
classList
^ classList ifNil: [ classList := Smalltalk globals allClasses reject: [ :each | each = self class ] ]! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
randomIndex
^ self random nextInt: self listSize! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
random: anObject
random := anObject! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
turn: anObject
turn := anObject! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
classList: anObject
classList := anObject! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
turn
^ turn! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
random
^ random ifNil: [ random := Random seed: (DateAndTime now asUnixTime) ]! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
listSize
^ self classList size! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
SmalltalkJenga class
instanceVariableNames: 'default'!
!SmalltalkJenga class methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
playAll
self default playAll! !
!SmalltalkJenga class methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
play
self default play! !
!SmalltalkJenga class methodsFor: 'instance creation' stamp: 'KazunoriUeda 12/19/2018 18:00'!
default
default ifNil: [default := self new].
^default! !
!SmalltalkJenga class methodsFor: 'class initialization' stamp: 'KazunoriUeda 12/19/2018 18:00'!
initialize
default := nil! !
SmalltalkJenga initialize!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.