{"id":471,"date":"2017-06-17T21:53:05","date_gmt":"2017-06-17T12:53:05","guid":{"rendered":"https:\/\/do-gugan.com\/swift\/?p=471"},"modified":"2017-06-21T02:17:01","modified_gmt":"2017-06-20T17:17:01","slug":"%e9%85%8d%e5%88%97-10-%e3%83%a9%e3%83%b3%e3%83%80%e3%83%a0%e3%81%aa%e5%9c%b0%e5%bd%a2","status":"publish","type":"post","link":"https:\/\/do-gugan.com\/swift\/?p=471","title":{"rendered":"\u914d\u5217 10. \u30e9\u30f3\u30c0\u30e0\u306a\u5730\u5f62"},"content":{"rendered":"<p>\u65b0\u767b\u5834\u8981\u7d20\u306f\u3001\u6bce\u56de\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\uff08\u4e71\u6570\uff09\u3092\u8fd4\u3059randomInt\u95a2\u6570\u3067\u3059\u3002<\/p>\n<pre class=\"lang:swift decode:true \">var randomNumber =\u00a0randomInt(from: 0, to: 12)<\/pre>\n<p>\u306a\u3069\u3068\u3059\u308b\u3068\u3001randomNumber\u5909\u6570\u306b\u30010\u304b\u308912\u307e\u3067\u306e\u3046\u3061\u306e\u3069\u308c\u304b\u306e\u6574\u6570\u304c\u5165\u308a\u307e\u3059\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u5ea6\u306b\u6bce\u56de\u9055\u3063\u305f\u6570\u5b57\u306b\u306a\u308b\u306e\u3067\u3001\u30b5\u30a4\u30b3\u30ed\u3092\u632f\u308b\u306a\u3069\u30b2\u30fc\u30e0\u7684\u306a\u30a2\u30d7\u30ea\u306b\u306f\u6b20\u304b\u305b\u306a\u3044\u95a2\u6570\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30b9\u30c6\u30fc\u30b8\u3067\u306f\u30017\u884c\u76ee\u3067.append\u30e1\u30bd\u30c3\u30c9\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002\u524d\u5f8c\u306efor\u6587\u306720\u56de\u7e70\u308a\u8fd4\u3055\u308c\u308b\u306e\u3067\u30019\u884c\u76ee\u306e\u6642\u70b9\u3067heights\u914d\u5217\u306b\u306f0\u301c12\u306e\u4e2d\u306e\u3069\u308c\u304b\u306e\u6570\u5b57\u304c20\u500b\u5165\u3063\u3066\u3044\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u7d9a\u304f\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u3001\u3053\u308c\u3092\u5148\u982d\u304b\u3089\u53d6\u308a\u51fa\u3057\u3001\u7a4d\u307f\u4e0a\u3052\u308b\u30d6\u30ed\u30c3\u30af\u306e\u9ad8\u3055\u3068\u3057\u3066\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u3002\u524d\u30b9\u30c6\u30fc\u30b8\u540c\u69d8\u3001\u30b3\u30de\u304c20\u500b\u76ee\u4ee5\u964d\u306b\u306a\u308b\u3068index\u304cheights\u914d\u5217\u304c\u3082\u3063\u3066\u3044\u308b\u8981\u7d20\u6570\u3092\u8d85\u3048\u3066\u7bc4\u56f2\u5916\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u300112-14\u884c\u76ee\u306eif\u6587\u30670\u306b\u623b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30c6\u30fc\u30b8\u3068\u3057\u3066\u306f\u3001\u4f55\u304b\u6240\u304b\u3042\u308b\u30b3\u30e1\u30f3\u30c8\u6587\u306e\u4e0b\u306b\u3001\u305d\u306e\u6761\u4ef6\u306b\u5f53\u3066\u306f\u307e\u308b\u30b3\u30de\u306e\u6642\u306b\u306a\u306b\u304b\u3057\u3089\u306e\u51e6\u7406\uff08world.place()\u7684\u306a\u3053\u3068\uff09\u3092\u3057\u308d\u3068\u3042\u308a\u307e\u3059\u3002\u81ea\u5206\u306e\u30bb\u30f3\u30b9\u3067\u597d\u304d\u306a\u51e6\u7406\u3092\u66f8\u304d\u307e\u3057\u3087\u3046\u3002\u307e\u305f40\u884c\u76ee\u306e\u3068\u3053\u308d\u306b\u306f\u3001if\u6587\u306e\u6761\u4ef6\u305d\u306e\u3082\u306e\u3092\u81ea\u5206\u3067\u6c7a\u3081\u3066\u306a\u306b\u304b\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\uff08\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u66f8\u3044\u3066\u3042\u308a\u307e\u305b\u3093\uff09\u3002<\/p>\n<pre class=\"lang:swift decode:true\">let allCoordinates = world.allPossibleCoordinates\r\nvar heights: [Int] = []\r\n\r\n\/\/ Append random numbers to heights.\r\n\/\/ (heights\u914d\u5217\u306b\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\u3092\u8ffd\u52a0\u3057\u306a\u3055\u3044)\r\n    for i in 1 ... 20 {\r\n        heights.append(randomInt(from: 0, to: 12))\r\n    }\r\n\r\nvar index = 0\r\nfor coordinate in allCoordinates {\r\n    if index == heights.count {\r\n        index = 0\r\n    }\r\n    \r\n    \/\/ currentHeight stores the height at the current index.\r\n    \/\/ (currentHeight\u306b\u306fheight\u914d\u5217\u306eindex\u756a\u76ee\u306e\u6570\u5b57\u3092\u4fdd\u6301)\r\n    var currentHeight = heights[index]\r\n    \r\n\r\n    if currentHeight == 0 {\r\n        \/\/ Do something interesting if currentHeight is equal to 0.\r\n        \/\/ (currentHeight\u304c0\u306e\u6642\u3001\u306a\u306b\u304b\u9762\u767d\u3044\u3053\u3068\u3092\u3057\u306a\u3055\u3044)\r\n        world.removeItems(at: coordinate) \/\/\u9678\u5730\u3092\u524a\u9664\r\n        world.place(Water(), at: coordinate) \/\/\u6c34\u3092\u914d\u7f6e\r\n\r\n    } else {\r\n        for i in 1...currentHeight {\r\n            world.place(Block(), at: coordinate) \/\/\u30d6\u30ed\u30c3\u30af\u3092\u914d\u7f6e\r\n        }\r\n        if currentHeight &gt; 10 { \/\/\u9ad8\u3055\u304c10\u4ee5\u4e0a\u306e\u6642\r\n            \/\/ Do something different, such as placing a character.\r\n            \/\/ (\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u7f6e\u304f\u306a\u3069\u3001\u306a\u306b\u304b\u5225\u306e\u3053\u3068\u3092\u3057\u306a\u3055\u3044)\r\n            world.place(Character(), at: coordinate) \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u914d\u7f6e\r\n        } else if coordinate.column &gt;= 3 &amp;&amp; coordinate.column &lt; 6 { \/\/3\u5217\u76ee\u304b\u30895\u5217\u76ee\u306e\u6642\r\n            \/\/ Do something different, such as placing water.\r\n            \/\/ (\u6c34\u3092\u914d\u7f6e\u3059\u308b\u306a\u3069\u3001\u306a\u306b\u304b\u9055\u3046\u3053\u3068\u3092\u3057\u306a\u3055\u3044)\r\n            world.place(Gem(), at: coordinate) \/\/\u5b9d\u77f3\u3092\u914d\u7f6e\r\n        }\r\n        \/\/ Add more rules to customize your world.\r\n        \/\/ (\u3042\u306a\u305f\u306e\u4e16\u754c\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u30eb\u30fc\u30eb\u3092\u3082\u3063\u3068\u8ffd\u52a0\u3057\u306a\u3055\u3044)\r\n\r\n        \r\n    }\r\n    index += 1\r\n    \r\n}<\/pre>\n<p>\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u306e\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u4e71\u6570\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5b9f\u884c\u3059\u308b\u5ea6\u306b\u5404\u30b3\u30de\u306e\u9ad8\u3055\u304c\u5909\u308f\u308a\u3001\u6bce\u56de\u9055\u3063\u305f\u98a8\u666f\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-480 size-large\" src=\"https:\/\/do-gugan.com\/swift\/wp-content\/uploads\/2017\/06\/IMG_0028-971x1024.jpg\" alt=\"\" width=\"525\" height=\"554\" srcset=\"https:\/\/do-gugan.com\/swift\/wp-content\/uploads\/2017\/06\/IMG_0028-971x1024.jpg 971w, https:\/\/do-gugan.com\/swift\/wp-content\/uploads\/2017\/06\/IMG_0028-285x300.jpg 285w, https:\/\/do-gugan.com\/swift\/wp-content\/uploads\/2017\/06\/IMG_0028-768x810.jpg 768w, https:\/\/do-gugan.com\/swift\/wp-content\/uploads\/2017\/06\/IMG_0028.jpg 1083w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/p>\n<script type=\"text\/javascript\">amzn_assoc_ad_type =\"responsive_search_widget\"; amzn_assoc_tracking_id =\"doguganprojec-22\"; amzn_assoc_marketplace =\"amazon\"; amzn_assoc_region =\"JP\"; amzn_assoc_placement =\"\"; amzn_assoc_search_type = \"search_widget\";amzn_assoc_width =\"500\"; amzn_assoc_height =\"400\"; amzn_assoc_default_search_category =\"\"; amzn_assoc_default_search_key =\"iPad\";amzn_assoc_theme =\"light\"; amzn_assoc_bg_color =\"FFFFFF\"; <\/script><script src=\"\/\/z-fe.amazon-adsystem.com\/widgets\/q?ServiceVersion=20070822&Operation=GetScript&ID=OneJS&WS=1&Marketplace=JP\"><\/script>","protected":false},"excerpt":{"rendered":"<p>\u65b0\u767b\u5834\u8981\u7d20\u306f\u3001\u6bce\u56de\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\uff08\u4e71\u6570\uff09\u3092\u8fd4\u3059randomInt\u95a2\u6570\u3067\u3059\u3002 var randomNumber =\u00a0randomInt(from: 0, to: 12) \u306a\u3069\u3068\u3059\u308b\u3068\u3001randomNumber\u5909\u6570\u306b\u30010\u304b\u3089 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/do-gugan.com\/swift\/?p=471\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u914d\u5217 10. \u30e9\u30f3\u30c0\u30e0\u306a\u5730\u5f62&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,17],"tags":[],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-learncode2","category-array"],"_links":{"self":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471"}],"version-history":[{"count":4,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts\/471\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}