{"id":3022,"date":"2017-12-20T09:00:22","date_gmt":"2017-12-20T00:00:22","guid":{"rendered":"http:\/\/oohito.com\/nqthm\/?p=3022"},"modified":"2017-12-20T09:00:22","modified_gmt":"2017-12-20T00:00:22","slug":"building-a-memory-game-with-bloc%e3%81%ae%e6%89%8b%e7%bf%92%e3%81%84%ef%bc%88chapter-4%ef%bc%89","status":"publish","type":"post","link":"https:\/\/oohito.com\/nqthm\/archives\/3022","title":{"rendered":"Building a memory game with Bloc\u306e\u624b\u7fd2\u3044\uff08Chapter 4\uff09"},"content":{"rendered":"<blockquote><p>\u3053\u308c\u306f<a href=\"https:\/\/qiita.com\/advent-calendar\/2017\/smalltalk\">Smalltalk Advent Calendar 2017<\/a>\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p><\/blockquote>\n<p>\u524d\u56de\u306b\u5f15\u304d\u7d9a\u3044\u3066\u3001Bloc \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u3042\u308b Building a memory game with Bloc \u306eChapter 4(Adding a board view) \u306e\u5185\u5bb9\u3092\u3084\u3063\u3066\u3044\u304f\u3002<br \/>\n\u5143\u30cd\u30bf\u306f<br \/>\n<a href=\"https:\/\/github.com\/pharo-graphics\/Bloc\">https:\/\/github.com\/pharo-graphics\/Bloc<\/a><br \/>\n\u306e\u4e2d\u306b\u3042\u308b\u3001<br \/>\n<a href=\"http:\/\/files.pharo.org\/books-pdfs\/booklet-Bloc\/2017-11-09-memorygame.pdf\">http:\/\/files.pharo.org\/books-pdfs\/booklet-Bloc\/2017-11-09-memorygame.pdf<\/a><br \/>\n\u3067\u3042\u308b\u3002<br \/>\n<!--more--><br \/>\n3\u7ae0\u3067\u306f\u30ab\u30fc\u30c9\u306e\u63cf\u753b\u3092\u884c\u3063\u305f\u30024\u7ae0\u3067\u306f\u30b2\u30fc\u30e0\u30dc\u30fc\u30c9\u306e\u63cf\u753b\u3092\u5b9f\u88c5\u3059\u308b\u3002\u5177\u4f53\u7684\u306b\u306f\u30b2\u30fc\u30e0\u30dc\u30fc\u30c9\u7528\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u4f5c\u3063\u3066\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<h2>4.1 The GameElement class<\/h2>\n<p>MgdGameElement \u30af\u30e9\u30b9\u3092\u4f5c\u3063\u3066\u30b2\u30fc\u30e0\u30dc\u30fc\u30c9\u306e\u63cf\u753b\u3092\u884c\u3046\u3002 MgdRawCardElement \u30af\u30e9\u30b9\u3068\u540c\u69d8\u306b\u3001 BlElement \u30af\u30e9\u30b9\u306e\u30b5\u30d6\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u3002\u3053\u306e\u30af\u30e9\u30b9\u306f\u30b2\u30fc\u30e0\u30e2\u30c7\u30eb\u3078\u306e\u53c2\u7167\u7528\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u3092\u6301\u3063\u3066\u3044\u308b\u3002<\/p>\n<pre>BlElement subclass: #MgdGameElement\n  instanceVariableNames: 'memoryGame'\n  classVariableNames: ''\n  package: 'Bloc-MemoryGame-Demo-Elements'<\/pre>\n<p>\u6b21\u306b memoryGame \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u306e\u30a2\u30af\u30bb\u30c3\u30b5\u3092\u4f5c\u6210\u3059\u308b\u3002 \u30bb\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308b memoryGame: \u306f\u6b21\u306e\u7bc0\u3067\u3059\u3050\u306b\u4fee\u6b63\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; memoryGame: aMgdGameModel\n  memoryGame := aMgdGameModel.<\/pre>\n<p>\u30b2\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u3082\u5b9a\u7fa9\u3059\u308b\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; memoryGame\n  ^ memoryGame<\/pre>\n<p>\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\u305f\u3081\u306b initialize \u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3059\u308b\u3002\u30b0\u30ea\u30c3\u30c9\uff08\u30de\u30b9\u76ee\uff09\u5f0f\u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u3068\u3057\u3066\u6c34\u5e73\u65b9\u5411\u306b\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; initialize\n  super initialize.\n  self layout: BlGridLayout horizontal.<\/pre>\n<h2>4.2 Creating cards<\/h2>\n<p>\u30b2\u30fc\u30e0\u306e\u30e2\u30c7\u30eb\u304b\u3089\u3001\u30b2\u30fc\u30e0\u76e4\u306e\u6a2a\u65b9\u5411\u306e\u30ab\u30fc\u30c9\u6570\u3068\u3001\u30ab\u30fc\u30c9\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u4f5c\u308b\u305f\u3081\u306e\u30ab\u30fc\u30c9\u306e\u30e2\u30c7\u30eb\u3092\u5f97\u308b\u3002\u30ab\u30fc\u30c9\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u306f\u3001 addChild: \u30e1\u30bd\u30c3\u30c9\u3067\u30b2\u30fc\u30e0\u76e4\u306e\u306e\u5b50\u30a8\u30ec\u30e1\u30f3\u30c8\u306b\u3059\u308b\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; memoryGame: aGameModel\n  memoryGame := aGameModel.\n  memoryGame availableCards\n    do: [ :aCard | self addChild: (self newCardElement card: aCard) ].<\/pre>\n<p>newCardElement \u30e1\u30bd\u30c3\u30c9\u3067\u30ab\u30fc\u30c9\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u4f5c\u308b\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; newCardElement\n  ^ MgdRawCardElement new<\/pre>\n<p>\u3053\u3053\u3067\u3001\u4eca\u307e\u3067\u4f5c\u3063\u305f\u30b2\u30fc\u30e0\u76e4\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8868\u793a\u3055\u305b\u3066\u307f\u308b\u3002<\/p>\n<pre>game := MgdGameModel new initializeForSymbols: '12345678'.\ngrid := MgdGameElement new.\ngrid memoryGame: game.\ngrid.<\/pre>\n<p>\u4e0a\u8a18\u3092 Playground \u306b\u5165\u529b\u3057\u3066 Do it all and go \u3092\u3059\u308b\u3068\u3001\u4e0b\u306e\u753b\u9762\u306e\u3088\u3046\u306b\u306a\u308b\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3027\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_17-48-13-1-300x201.png\" alt=\"\" width=\"300\" height=\"201\" \/><br \/>\n\u4e2d\u9014\u534a\u7aef\u306b\u30ab\u30fc\u30c9\u306e\u4e00\u90e8\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u308f\u304b\u308b\u3002\u3053\u308c\u306f\u30b2\u30fc\u30e0\u76e4\u304c\u5b50\u30a8\u30ec\u30e1\u30f3\u30c8\u306e\u5927\u304d\u3055\u306b\u5408\u308f\u305b\u3066\u8868\u793a\u3057\u3066\u3044\u306a\u3044\u304b\u3089\u3060\u305d\u3046\u306a\u3002<\/p>\n<h2>4.3 Updating the container to its children<\/h2>\n<p>Bloc \u306b\u304a\u3051\u308b\u30ec\u30a4\u30a2\u30a6\u30c8\u306f\u3001\u5b50\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u683c\u7d0d\u3059\u308b\u5165\u308c\u7269\u5185\u3067\u306e\u914d\u7f6e\u3092\u884c\u3046\u306e\u3067\u3042\u3063\u3066\u3001\u5165\u308c\u7269\u305d\u306e\u3082\u306e\u306e\u914d\u7f6e\u306f\u884c\u308f\u306a\u3044\u3002\u305d\u308c\u3092\u3059\u308b\u306b\u306f\u300c\u5236\u7d04\uff08constraints\uff09\u300d\u3092\u4f7f\u3046\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; initialize\n  super initialize.\n  self layout: BlGridLayout horizontal.\n  self constraintsDo: [ :aLayoutConstraints |\n    aLayoutConstraints horizontal fitContent.\n    aLayoutConstraints vertical fitContent ].<\/pre>\n<p>\u518d\u5ea6\u3001 Playground \u3067\u30b2\u30fc\u30e0\u76e4\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8868\u793a\u3055\u305b\u3066\u307f\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u305f\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3028\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_17-59-20-1-300x201.png\" alt=\"\" width=\"300\" height=\"201\" \/><br \/>\n\u30ab\u30fc\u30c9\u306e\u5168\u4f53\u304c\u8868\u793a\u3055\u308c\u305f\u306e\u306f\u826f\u3044\u304c\u3001\u4e00\u5217\u306b\u306a\u3063\u3066\u3057\u307e\u3044 Playground \u304b\u3089\u306f\u307f\u51fa\u3057\u3066\u3044\u308b\u3002<\/p>\n<h2>4.4 Getting all the children displayed<\/h2>\n<p>\u30b0\u30ea\u30c3\u30c9\u3067\u6a2a\u65b9\u5411\u306b\u8868\u793a\u3059\u308b\u30a8\u30ec\u30e1\u30f3\u30c8\u306e\u500b\u6570\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\uff14\u884c\uff14\u5217\u306e\u30ab\u30fc\u30c9\u3092\u8868\u793a\u3055\u305b\u308b\u3002\u30b2\u30fc\u30e0\u306e\u30e2\u30c7\u30eb\u304c\u306a\u3044\u3068\u500b\u6570\u304c\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u3001memoryGame\u306e\u30bb\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre>MgdGameElement &gt;&gt; memoryGame: aGameModel\n  memoryGame := aGameModel.\n  self layout columnCount: memoryGame gridSize.\n  memoryGame availableCards\n    do: [ :aCard | self addChild: (self newCardElement card: aCard) ].<\/pre>\n<p>columnCount: \u3067\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u6570\u306e\u8a2d\u5b9a\u306f\u3001\u5b50\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u305f\u5f8c\u306b\u884c\u3063\u3066\u3082\u554f\u984c\u306a\u3044\u3088\u3046\u3060\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-3029\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_18-07-28-1-700x434.png\" alt=\"\" width=\"700\" height=\"434\" \/><br \/>\n\u3064\u3044\u3067\u306b\u30ab\u30fc\u30c9\u3092\u8868\u306b\u3057\u3066\u8868\u793a\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre>game := MgdGameModel new initializeForSymbols: '12345678'.\ngame availableCards do: #flip.\ngrid := MgdGameElement new.\ngrid memoryGame: game.\ngrid.<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-3031\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_18-20-17-1-700x436.png\" alt=\"\" width=\"700\" height=\"436\" \/><br \/>\n\u3042\u308c\u308c\u3001\u6570\u5b57\u306e\u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\u304c\u5c0f\u3055\u3059\u304e\u308b\u305e\u3002<\/p>\n<h2>4.5 Separating cards<\/h2>\n<p>\u30ab\u30fc\u30c9\u304c\u304f\u3063\u3064\u3044\u3066\u898b\u96e3\u3044\u306e\u3067\u3001cellSpacing: \u3067\u9699\u9593\u3092\u3042\u3051\u308b\u3002\u3064\u3044\u3067\u306b background: \u3067\u30b2\u30fc\u30e0\u76e4\u306e\u80cc\u666f\u8272\u3082\u8a2d\u5b9a\u3059\u308b\u3002\u30ab\u30fc\u30c9\u306e\u30a8\u30ec\u30e1\u30f3\u30c8\u306e\u80cc\u666f\u8272\u306f\u89d2\u4e38\u56db\u89d2\u5f62\u306e\u5916\u5f62\u3068\u3057\u3066\u5857\u308a\u3064\u3076\u3057\u3066\u3044\u305f\u304c\u3001\u30b2\u30fc\u30e0\u76e4\u9762\u306e\u80cc\u666f\u8272\u306f\u6587\u5b57\u901a\u308a\u80cc\u666f\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u3002<br \/>\nbackground: \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5f15\u304d\u6570\u306f Color \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u307e\u307e\u3067\u3082\u3001 BlBackground \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u3082\u826f\u3044\u3089\u3057\u3044\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-3033\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_20-31-16-1-700x429.png\" alt=\"\" width=\"700\" height=\"429\" \/><\/p>\n<h2>\u86c7\u8db3<\/h2>\n<p>\u4ee5\u4e0a\u3067\u30b2\u30fc\u30e0\u76e4\u306e\u63cf\u753b\u306e\u5b9f\u88c5\u306f\u7d42\u308f\u3063\u305f\u3051\u3069\u3001\u6570\u5b57\u306e\u30d5\u30a9\u30f3\u30c8\u304c\u5c0f\u3055\u3044\u306e\u306f\u6c17\u6301\u3061\u60aa\u3044\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-3034\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_20-34-21-1-700x431.png\" alt=\"\" width=\"700\" height=\"431\" \/><br \/>\na\u304b\u3089h\u3092\u8868\u793a\u3055\u305b\u305f\u306e\u304c\u3053\u3061\u3089\u3002a \u3060\u3051\u5927\u304d\u3044\u306a\u3093\u3066\u3072\u3069\u3044\u3058\u3083\u306a\u3044\u304b\u3002<\/p>\n<pre>drawFlippedSideOn: aCanvas\n  | font origin textPainter metrics |\n  font := aCanvas font\n    named: 'TakaoExGothic';\n    size: 50;\n    build.<\/pre>\n<p>\u30d5\u30a9\u30f3\u30c8\u3092 TakaoExGothic \u306b\u5909\u3048\u3066\u307f\u305f\u3089\u554f\u984c\u306a\u304f\u8868\u793a\u3055\u308c\u305f\u306e\u3067\u3053\u3061\u3089\u306b\u3059\u308b\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3035\" src=\"http:\/\/oohito.com\/nqthm\/wp-content\/uploads\/2017\/12\/Screenshot_2017-12-18_20-44-24-1-1.png\" alt=\"\" width=\"446\" height=\"486\" \/><br \/>\n\u3044\u3088\u3044\u3088\u6b21\u306e\u6700\u7d42\u7ae0\u3067\u30b2\u30fc\u30e0\u306e\u64cd\u4f5c\u95a2\u4fc2\u306e\u5b9f\u88c5\u3002\u3053\u308c\u3067\u30b2\u30fc\u30e0\u3063\u307d\u304f\u306a\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u308c\u306fSmalltalk Advent Calendar 2017\u306e\u8a18\u4e8b\u3067\u3059\u3002 \u524d\u56de\u306b\u5f15\u304d\u7d9a\u3044\u3066\u3001Bloc \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u3042\u308b Building a memory game with Bloc \u306eChapter 4(&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-3022","post","type-post","status-publish","format-standard","hentry","category-pharo"],"_links":{"self":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts\/3022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/comments?post=3022"}],"version-history":[{"count":0,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts\/3022\/revisions"}],"wp:attachment":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/media?parent=3022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/categories?post=3022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/tags?post=3022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}