Skip to content

Commit

Permalink
Synched tutorial with bloc
Browse files Browse the repository at this point in the history
  • Loading branch information
syrel committed Sep 7, 2017
1 parent ec05655 commit 5a592ed
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Is sent by ==MgdCardModel== after the card is removed from the ==MgdGameModel==
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "",
"commentStamp" : "AliakseiSyrel 9/7/2017 10:43",
"super" : "Announcement",
"category" : "Bloc-MemoryGame-Demo-Events",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
I am a visual card modelled by ==MgdCardModel==

A model should be attached by sending #card: to the card element.
Card element reacts on model events such as MgdCardFlippedAnnouncement and MgdCardDisappearAnnouncement after card is flipped or disappeared.

By default I do not have a visual representations of the face and back
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
accessing
card: aMgCard
card := aMgCard.
card announcer when: MgCardFlippedAnnouncement send: #onFlipped to: self.
card announcer when: MgCardDisappearAnnouncement send: #onDisappear to: self
card announcer when: MgdCardFlippedAnnouncement send: #onFlipped to: self.
card announcer when: MgdCardDisappearAnnouncement send: #onDisappear to: self
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
visual properties
cornerRadius
"Return a number representing a corner radius"
<return: #Number>

^ 12
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
announcement - handling
onFlipped
self card flipped
self card isFlipped
ifTrue: [ self onFlippedFace ]
ifFalse: [ self onFlippedBack ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "",
"commentStamp" : "AliakseiSyrel 9/7/2017 11:23",
"super" : "BlElement",
"category" : "Bloc-MemoryGame-Demo-Elements",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Is sent by ==MgdCardModel== after the card is flipped
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "",
"commentStamp" : "AliakseiSyrel 9/7/2017 10:43",
"super" : "Announcement",
"category" : "Bloc-MemoryGame-Demo-Events",
"classinstvars" : [ ],
Expand Down
11 changes: 10 additions & 1 deletion src/Bloc-MemoryGame-Demo.package/MgdCardModel.class/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
I am a card model that can be flipped or not.
When card is flipped player should see a symbol that is used to compare two cards.
When card is flipped player should see a symbol that is used to compare two cards.

!! Examples:

[[[
| cardModel |
cardModel := MgdCardModel new symbol: $a.
cardModel flip.
cardModel disappear
]]]
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
testing
isFlipped
"Return true if card is flipped and its face (symbol) is visible, false otherwise"
<return: #Number>

^ flipped
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
notifying
notifyDisappear
"Notify all observers that I disappeared from the game"
self announcer announce: MgCardDisappearAnnouncement new
self announcer announce: MgdCardDisappearAnnouncement new
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
notifying
notifyFlipped
"Notify all observers that my flipped state was changed (from flipped to not or the other way around)"
self announcer announce: MgCardFlippedAnnouncement new
self announcer announce: MgdCardFlippedAnnouncement new
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
accessing
symbol: aCharacter
"Initialize the card with a given symbol as a character"
self
assert: [ aCharacter isNotNil ]
description: [ 'Character must not be nil' ].

symbol := aCharacter
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
accessing
symbol
"Return a symbol that should be displayed when card is flipped and face is visible"
<return: #Character>

^ symbol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "AndreiChis 5/28/2017 20:08",
"commentStamp" : "AliakseiSyrel 9/7/2017 10:51",
"super" : "Object",
"category" : "Bloc-MemoryGame-Demo-Model",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SystemOrganization addCategory: #'Bloc-MemoryGame-Demo'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Demo-Elements'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Demo-Events'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Demo-Model'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Demo-Elements'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Demo-Events'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Demo-Model'!
11 changes: 10 additions & 1 deletion src/Bloc-MemoryGame.package/MgCardModel.class/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
I am a card model that can be flipped or not.
When card is flipped player should see a symbol that is used to compare two cards.
When card is flipped player should see a symbol that is used to compare two cards.

!! Examples:

[[[
| cardModel |
cardModel := MgCardModel new symbol: $a.
cardModel flip.
cardModel disappear
]]]
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
testing
isFlipped
"Return true if card is flipped and its face (symbol) is visible, false otherwise"
<return: #Number>

^ flipped
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
accessing
symbol: aCharacter
"Initialize the card with a given symbol as a character"
self
assert: [ aCharacter isNotNil ]
description: [ 'Character must not be nil' ].

symbol := aCharacter
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
accessing
symbol
"Return a symbol that should be displayed when card is flipped and face is visible"
<return: #Character>

^ symbol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "AliakseiSyrel 5/17/2017 15:02",
"commentStamp" : "AliakseiSyrel 9/7/2017 10:52",
"super" : "Object",
"category" : "Bloc-MemoryGame-Model",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ initialize
c frame horizontal alignCenter.
c frame vertical alignCenter ].
face visibility: BlVisibility hidden.

back := BlElement new
constraintsDo: [ :c |
c horizontal matchParent.
c vertical matchParent ];
addChild: (BlLineElement new
border: (BlBorder paint: Color paleBlue width: 1);
fromAnchor: (BlGeometryStaticAnchor position: 0 @ 0);
toAnchor: (BlGeometryStaticAnchor position: 80 @ 80);
fromAnchor: (BlAbsolutePositionAnchor position: 0 @ 0);
toAnchor: (BlAbsolutePositionAnchor position: 80 @ 80);
yourself);
addChild: (BlLineElement new
border: (BlBorder paint: Color paleBlue width: 1);
fromAnchor: (BlGeometryStaticAnchor position: 80 @ 0);
toAnchor: (BlGeometryStaticAnchor position: 0 @ 80);
fromAnchor: (BlAbsolutePositionAnchor position: 80 @ 0);
toAnchor: (BlAbsolutePositionAnchor position: 0 @ 80);
yourself).

self addChild: face.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cardsFor: aMgGameModel

^ ((1 to: aMgGameModel cardsCount / aMgGameModel matchesCount) collect: [ :index |
| symbols |
symbols := '为从公家里地个时来心'.
symbols := '12345678'.
(1 to: aMgGameModel matchesCount)
collect: [ :i | MgCardModel new symbol: (symbols at: index) ]
]) flattened shuffled
8 changes: 4 additions & 4 deletions src/Bloc-MemoryGame.package/monticello.meta/categories.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SystemOrganization addCategory: #'Bloc-MemoryGame'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Elements'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Events'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Examples'!
SystemOrganization addCategory: 'Bloc-MemoryGame-Model'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Elements'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Events'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Examples'!
SystemOrganization addCategory: #'Bloc-MemoryGame-Model'!

0 comments on commit 5a592ed

Please sign in to comment.