{"id":356,"date":"2024-09-20T23:41:38","date_gmt":"2024-09-20T23:41:38","guid":{"rendered":"https:\/\/xcode15.shimayugu.jp\/?p=356"},"modified":"2024-12-29T06:57:07","modified_gmt":"2024-12-28T21:57:07","slug":"%e6%96%b0swift%e3%81%a7%e8%a1%8c%e3%81%93%e3%81%86-%e7%ac%ac%ef%bc%93%ef%bc%93%e5%9b%9e%e3%80%8c%e3%83%90%e3%83%90%e6%8a%9c%e3%81%8d%ef%bc%92%e3%80%8d%e3%80%80%e7%94%b0%e9%83%a8%e4%ba%95%e4%bf%9d","status":"publish","type":"post","link":"https:\/\/xcode15.shimayugu.jp\/?p=356","title":{"rendered":"\u65b0Swift\u3067\u884c\u3053\u3046&#8230;\u7b2c\uff13\uff13\u56de\u300c\u30d0\u30d0\u629c\u304d\uff12\u300d\u3000\u7530\u90e8\u4e95\u4fdd"},"content":{"rendered":"\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2473\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/xcode15.shimayugu.jp\/?p=803\">\u89e3\u8aac\u7de8<\/a><\/p>\n\n\n\n<p>\u3000\u4eca\u56de\u306f\u3001\u5b9f\u969b\u306b\u30ab\u30fc\u30c9\u3092\u914d\u308d\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u88cf\u306e\u307e\u307e\u3060\u3068\u3001\u3069\u306e\u3088\u3046\u306b\u30ab\u30fc\u30c9\u304c\u914d\u3089\u308c\u305f\u304b\u5224\u3089\u306a\u3044\u306e\u3067\u3001\u4eca\u306f\u8868\u3092\u8868\u793a\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u4ee5\u4e0b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"38-51\" data-show-lang=\"1\"><code>\/\/\n\/\/  ViewController.swift\n\/\/  baba\n\/\/\n\/\/  Created by \u4fdd Tabei on 2024\/09\/15.\n\/\/\n\nimport UIKit\n\nclass ViewController: UIViewController {\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view.\n        put53()\n    }\n\n    var eachCard: [[UILabel]] = [[],[],[],[]]\n    var cardObj:Card = Card(cdCnt: Card.EnumCard.joker)\n    func put53() {\n        for i in 0 ..&lt; 4 {\n            for j in 0 ..&lt; 14 {\n                let lbl = UILabel(frame: CGRectMake(0, 0, 50, 21))\n                lbl.center = CGPointMake(50 + 40 * CGFloat(j % 7), 150 + 120 * CGFloat(i) +\n                                         50 * CGFloat(j \/ 7))\n                lbl.textAlignment = NSTextAlignment.center\n                if i != 0 && j == 13 {\n                    lbl.text = &quot; &quot;\n                } else {\n                    lbl.text = &quot;\u2b1b\ufe0f&quot;\n                }\n                eachCard[i] += [lbl]\n                self.view.addSubview(lbl)\n            }\n        }\n    }\n    \n    @IBAction func btnGoTouch(_ sender: Any) {\n        for i in 0 ..&lt; 4 {\n            for j in 0 ..&lt; 14 {\n                if i != 0 && j == 13 {\n                } else {\n                    var st: String?\n                    var ii: Int\n                    (st, ii) = cardObj.put() \n                    eachCard[i][j].text = st\n                    eachCard[i][j].tag = ii\n                }\n            }\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u3055\u3066\u3001\u3053\u3053\u3067CardClass\u3067\u3059\u304c\u3001put\u95a2\u6570\u3067\u30ab\u30fc\u30c9\u306e\u8868\u793a\u6587\u5b57\u5217\u3068\u30ab\u30fc\u30c9\u756a\u53f7\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u3053\u306f\u30ab\u30fc\u30c9\u756a\u53f7\u3060\u3051\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u3066\u3001\u8868\u793a\u304c\u5fc5\u8981\u306a\u6642\u306f\u3001disp\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3068\u3057\u305f\u65b9\u304c\u826f\u3055\u305d\u3046\u3067\u3059\u3002<br>\u305d\u306e\u3088\u3046\u306b\u6539\u9020\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0bCardClass\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"40,53-58,59\" data-show-lang=\"1\"><code>\/\/\n\/\/  CardClass.swift\n\/\/  Poker\n\/\/\n\/\/  Created by \u4fdd Tabei on 2024\/09\/15.\n\/\/\n\nimport Foundation\n\nclass Card {\n    let mark: [String] = [&quot;\u2663\ufe0f&quot;,&quot;\u2666\ufe0f&quot;,&quot;\u2764\ufe0f&quot;,&quot;\u2660\ufe0f&quot;]\n    let number: [String] = [&quot;A&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;T&quot;,&quot;J&quot;,&quot;Q&quot;,&quot;K&quot;]\n    \n    enum EnumCard: Int {\n        case nonJoker = 52\n        case joker = 53\n    }\n    \n    var cardCount = 0\n    \n    var check: [Bool] = []\n    \n    var count = 0\n    \n    init(cdCnt: EnumCard) {\n        cardCount = cdCnt.rawValue\n        for _ in 0 ..&lt; cardCount {\n            check += [false]\n        }\n        count = cardCount\n    }\n    \n    func reset() {\n        for i in 0 ..&lt; cardCount {\n            check[i] = false\n        }\n        count = cardCount\n    }\n    \n    func put() -&gt; Int {\n        var card = 0\n        let randInt = Int.random(in: 0 ..&lt; count)\n        for i in 0 ... randInt {\n            while check[card] {\n                card += 1\n            }\n            if i &lt; randInt {\n                card += 1\n            }\n        }\n        check[card] = true\n        count -= 1\n        \/\/var strCard: String?\n        \/\/if card == 52 {\n        \/\/    strCard = &quot;JK&quot;\n        \/\/} else {\n        \/\/    strCard = mark[card \/ 13] + number[card % 13]\n        \/\/}\n        return card\n    }\n    \n    func disp(card: Int) -&gt; String {\n        var strCard: String\n        if card == 52 { \n            strCard = &quot;JK&quot;\n        } else {\n            strCard = mark[card \/ 13] + number[card % 13]\n        }\n        return strCard\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u4ee5\u4e0b\u30e1\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"43-44\" data-show-lang=\"1\"><code>\/\/\n\/\/  ViewController.swift\n\/\/  baba\n\/\/\n\/\/  Created by \u4fdd Tabei on 2024\/09\/15.\n\/\/\n\nimport UIKit\n\nclass ViewController: UIViewController {\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view.\n        put53()\n    }\n\n    var eachCard: [[UILabel]] = [[],[],[],[]]\n    var cardObj:Card = Card(cdCnt: Card.EnumCard.joker)\n    func put53() {\n        for i in 0 ..&lt; 4 {\n            for j in 0 ..&lt; 14 {\n                let lbl = UILabel(frame: CGRectMake(0, 0, 50, 21))\n                lbl.center = CGPointMake(50 + 40 * CGFloat(j % 7), 150 + 120 * CGFloat(i) +\n                                         50 * CGFloat(j \/ 7))\n                lbl.textAlignment = NSTextAlignment.center\n                if i != 0 && j == 13 {\n                    lbl.text = &quot; &quot;\n                } else {\n                    lbl.text = &quot;\u2b1b\ufe0f&quot;\n                }\n                eachCard[i] += [lbl]\n                self.view.addSubview(lbl)\n            }\n        }\n    }\n    \n    @IBAction func btnGoTouch(_ sender: Any) {\n        for i in 0 ..&lt; 4 {\n            for j in 0 ..&lt; 14 {\n                if i != 0 && j == 13 {\n                } else {\n                    eachCard[i][j].tag = cardObj.put()\n                    eachCard[i][j].text = cardObj.disp(card: eachCard[i][j].tag)\n                }\n            }\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u3055\u3066\u3001\u30ab\u30fc\u30c9\u304c\u91cd\u8907\u7121\u304f\u914d\u3089\u308c\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\uff1f<br>\u3000\u6b21\u56de\u306f\u3001\u30d0\u30d0\u629c\u304d\u3067\u3059\u306e\u3067\u3001\u30da\u30a2\u306b\u306a\u3063\u305f\u30ab\u30fc\u30c9\u3092\u9664\u304f\u3068\u3044\u3046\u51e6\u7406\u3092\u52a0\u3048\u3066\u307f\u307e\u3059\u3002\u7686\u3055\u3093\u3082\u8003\u3048\u3066\u307f\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2473\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/xcode15.shimayugu.jp\/?p=803\">\u89e3\u8aac\u7de8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21\u3000\u89e3\u8aac\u7de8 \u3000\u4eca\u56de\u306f\u3001\u5b9f\u969b\u306b\u30ab\u30fc\u30c9\u3092\u914d\u308d\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u88cf\u306e\u307e\u307e\u3060\u3068\u3001\u3069\u306e\u3088\u3046\u306b\u30ab\u30fc\u30c9\u304c\u914d\u3089\u308c\u305f\u304b\u5224\u3089\u306a\u3044\u306e\u3067\u3001\u4eca\u306f\u8868\u3092\u8868\u793a\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002 \u3000\u4ee5\u4e0b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3059\u3002 \u3000\u3055\u3066\u3001\u3053\u3053\u3067CardClass\u3067\u3059\u304c\u3001pu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":11,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":1028,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/1028"}],"wp:attachment":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}