aboutsummaryrefslogtreecommitdiff
path: root/pharo-mooc/redo/src/Dice/Die.class.st
diff options
context:
space:
mode:
Diffstat (limited to 'pharo-mooc/redo/src/Dice/Die.class.st')
-rw-r--r--pharo-mooc/redo/src/Dice/Die.class.st47
1 files changed, 47 insertions, 0 deletions
diff --git a/pharo-mooc/redo/src/Dice/Die.class.st b/pharo-mooc/redo/src/Dice/Die.class.st
new file mode 100644
index 0000000..07b844a
--- /dev/null
+++ b/pharo-mooc/redo/src/Dice/Die.class.st
@@ -0,0 +1,47 @@
+Class {
+ #name : #Die,
+ #superclass : #Object,
+ #instVars : [
+ 'faces'
+ ],
+ #category : #Dice
+}
+
+{ #category : #'instance creation' }
+Die class >> withFaces: anInteger [
+
+ | d |
+ d := Die new.
+ d faces: anInteger.
+ ^ d
+]
+
+{ #category : #accessing }
+Die >> faces [
+ ^ faces
+]
+
+{ #category : #accessing }
+Die >> faces: anInteger [
+ faces := anInteger
+]
+
+{ #category : #initialization }
+Die >> initialize [
+
+ super initialize.
+ faces := 6
+]
+
+{ #category : #initialization }
+Die >> printOn: aStream [
+
+ super printOn: aStream.
+ aStream nextPutAll: ' (', faces printString, ')'
+]
+
+{ #category : #accessing }
+Die >> roll [
+
+ ^ faces atRandom
+]