{"id":221,"date":"2024-09-18T07:47:53","date_gmt":"2024-09-18T07:47:53","guid":{"rendered":"https:\/\/xcode15.shimayugu.jp\/?p=221"},"modified":"2024-12-29T06:44:39","modified_gmt":"2024-12-28T21:44:39","slug":"%e6%96%b0swift%e3%81%a7%e8%a1%8c%e3%81%93%e3%81%86-%e7%ac%ac%ef%bc%92%ef%bc%90%e5%9b%9e%e3%80%8c%e3%83%9d%e3%83%bc%e3%82%ab%e3%83%bc%ef%bc%95%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=221","title":{"rendered":"\u65b0Swift\u3067\u884c\u3053\u3046&#8230;\u7b2c\uff12\uff10\u56de\u300c\u30dd\u30fc\u30ab\u30fc\uff15\u300d\u3000\u7530\u90e8\u4e95\u4fdd"},"content":{"rendered":"\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2298\"><\/a><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2473\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/xcode15.shimayugu.jp\/?p=688\">\u89e3\u8aac\u7de8<\/a><\/p>\n\n\n\n<p>\u3000\u524d\u56de\u306e\u554f\u984c\u306f\u3001\u30da\u30a2\u3092\u5224\u5225\u3059\u308b\u3068\u3044\u3046\u4e8b\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u524d\u56de\u306e\u554f\u984c\u306e\u7b54\u3048\u306e\u4e00\u3064\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"104-120\" data-show-lang=\"1\"><code>\/\/\n\/\/  ViewController.swift\n\/\/  Poker\n\/\/\n\/\/  Created by \u4fdd Tabei on 2024\/09\/09.\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        for i in 0 ..&lt; 5 {\n            let lbl = UILabel(frame: CGRectMake(0, 0, 50, 21))\n            lbl.center = CGPointMake(100 + 50 * CGFloat(i), 250)\n            lbl.textAlignment = NSTextAlignment.center\n            lbl.text = &quot;\u2b1b\ufe0f&quot;\n            eachCard += [lbl]\n            self.view.addSubview(lbl)\n            \n            let btn = UIButton(frame: CGRectMake(0, 0, 50, 21)) as UIButton\n            btn.center = CGPointMake(100 + 50 * CGFloat(i), 300)\n            btn.setTitle(&quot;off&quot;, for: .normal)\n            btn.setTitleColor(UIColor.systemGray, for: .normal)\n            btn.addTarget(self, action: #selector(btnTapped), for: .touchUpInside)\n            btn.tag = i\n            eachButton += [btn]\n            self.view.addSubview(btn)\n        }\n    }\n\n    @objc func btnTapped(sender: UIButton) {\n        if sender.currentTitle == &quot;off&quot; {\n            sender.setTitle(&quot;on&quot;, for: .normal)\n            eachCard[sender.tag].text = &quot;\u2b1b\ufe0f&quot;\n        } else {\n            sender.setTitle(&quot;off&quot;, for: .normal)\n            let card = eachCard[sender.tag].tag\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            eachCard[sender.tag].text = strCard\n        }\n    }\n    \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 {\n        static let Count = 52\n    }\n    \n    var check: [Bool] = [Bool](repeating: false, count: EnumCard.Count)\n    \n    var count = EnumCard.Count\n\n    var eachCard: [UILabel] = []\n    \n    var eachButton: [UIButton] = []\n\n    func put(i: 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        eachCard[i].text = strCard\n        eachCard[i].tag = card\n    }\n\n    func flush() {\n        var chk = true\n        let mark: Int = eachCard[0].tag \/ 13\n        for i in 1 ..&lt; 5 {\n            if mark != eachCard[i].tag \/ 13 { \n                chk = false\n                break\n            }\n        }\n        if chk {\n            let alert = UIAlertController()\n            alert.title = &quot;\u30d5\u30e9\u30c3\u30b7\u30e5&quot;\n            alert.message = &quot;\u30d5\u30e9\u30c3\u30b7\u30e5\u3067\u3059&quot;\n            alert.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default))\n            present(alert, animated: true, completion: nil)\n        } else {\n            var ck = false\n            for i in 0 ..&lt; 5 {\n                for j in i + 1 ..&lt; 5 {\n                    if eachCard[i].tag % 13 == eachCard[j].tag % 13 {\n                        ck = true\n                    }\n                }\n            }\n            if ck {\n                let alert = UIAlertController()\n                alert.title = &quot;\u30da\u30a2&quot;\n                alert.message = &quot;\u30da\u30a2\u304c\u3042\u308a\u307e\u3059&quot;\n                alert.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default))\n                present(alert, animated: true, completion: nil)\n            }\n        }\n    }\n\n    @IBAction func btnGoTouch(_ sender: Any) {\n        for i in 0 ..&lt; EnumCard.Count {\n            check[i] = false\n        }\n        count = EnumCard.Count\n        for i in 0 ..&lt; 5 {\n            put(i: i)\n        }\n        flush()\n    }\n    \n    @IBAction func btnReTouch(_ sender: Any) {\n        for i in 0 ..&lt; 5 {\n            if eachButton[i].currentTitle == &quot;on&quot; {\n                put(i: i)\n                eachButton[i].setTitle(&quot;off&quot;, for: .normal)\n            }\n        }\n        flush()\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u3055\u3066\u3001\u4eca\u56de\u8ffd\u52a0\u3057\u305f\u30da\u30a2\u306e\u5224\u5b9a\u90e8\u5206\u3001<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"1-8\" data-show-lang=\"1\"><code>            var ck = false\n            for i in 0 ..&lt; 5 {\n                for j in i + 1 ..&lt; 5 {\n                    if eachCard[i].tag % 13 == eachCard[j].tag % 13 {\n                        ck = true\n                    }\n                }\n            }\n            if ck {\n                let alert = UIAlertController()\n                alert.title = &quot;\u30da\u30a2&quot;\n                alert.message = &quot;\u30da\u30a2\u304c\u3042\u308a\u307e\u3059&quot;\n                alert.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default))\n                present(alert, animated: true, completion: nil)\n            }\n<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u5f8c\u534a\u90e8\u5206\u306f\u3001\u5358\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u51fa\u3059\u90e8\u5206\u306a\u306e\u3067\u3001\u524d\u534a\u90e8\u5206\u304c\u809d\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u30ab\u30fc\u30c9\u3092\u5168\u30d1\u30bf\u30fc\u30f3\u6bd4\u8f03\u3057\u3066\u3001\u540c\u3058\u756a\u53f7\u306e\u3082\u306e\u304c\u3042\u308b\u304b\u5224\u5225\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5c11\u3057\u5909\u66f4\u3059\u308b\u4e8b\u3067\u3001\u30ef\u30f3\u30da\u30a2\u3001\u30c4\u30fc\u30da\u30a2\u3001\u30b9\u30ea\u30fc\u30ab\u30fc\u30c9\u3001\u30d5\u30eb\u30cf\u30a6\u30b9\u3001\u30d5\u30a9\u30fc\u30ab\u30fc\u30c9\u306e\u533a\u5225\u304c\u51fa\u6765\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2298\"><\/a><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2473\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/xcode15.shimayugu.jp\/?p=688\">\u89e3\u8aac\u7de8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21\u3000\u89e3\u8aac\u7de8 \u3000\u524d\u56de\u306e\u554f\u984c\u306f\u3001\u30da\u30a2\u3092\u5224\u5225\u3059\u308b\u3068\u3044\u3046\u4e8b\u3067\u3057\u305f\u3002 \u3000\u524d\u56de\u306e\u554f\u984c\u306e\u7b54\u3048\u306e\u4e00\u3064\u3067\u3059\u3002 \u3000\u3055\u3066\u3001\u4eca\u56de\u8ffd\u52a0\u3057\u305f\u30da\u30a2\u306e\u5224\u5b9a\u90e8\u5206\u3001 \u3000\u5f8c\u534a\u90e8\u5206\u306f\u3001\u5358\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u51fa\u3059\u90e8\u5206\u306a\u306e\u3067\u3001\u524d\u534a\u90e8\u5206\u304c\u809d\u3068\u306a\u308a\u307e\u3059\u3002 \u3000\u30ab\u30fc\u30c9\u3092\u5168\u30d1\u30bf [&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-221","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/221","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=221"}],"version-history":[{"count":7,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":1013,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/221\/revisions\/1013"}],"wp:attachment":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}