{"id":156956,"student_id":2002,"content":"{\"html\":\"\u003c!DOCTYPE html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n \u003ctitle\u003eDocument\u003c/title\u003e\\n \u003cscript src=\\\"https://code.jquery.com/jquery-3.5.1.min.js\\\"\u003e\u003c/script\u003e\\n\u003c/head\u003e\\n\u003cbody\u003e\\n \u003ch1\u003e1A2B 推理遊戲\u003c/h1\u003e\\n \u003ctextarea id=\\\"textarea\\\" disabled autocomplete=\\\"off\\\" autocorrect=\\\"off\\\" autocapitalize=\\\"off\\\" spellcheck=\\\"false\\\"\u003e\\n========== 遊戲規則說明 ==========\\n\\n密碼是由 4 個不同的數字組成\\n每次猜完,電腦會返回 A、B 兩個數字結果\\nA 表示數字猜對 且 位置正確\\nB 表示數字猜對 但 位置錯誤\\n \u003c/textarea\u003e\\n \u003cbr/\u003e\\n \u003cbutton id=\\\"start\\\" class=\\\"green\\\"\u003e開始新的遊戲\u003c/button\u003e\\n \u003cbutton id=\\\"guess\\\" class=\\\"yellow\\\"\u003e猜密碼\u003c/button\u003e\\n \u003cbutton id=\\\"crack\\\" class=\\\"red\\\"\u003e自動破解\u003c/button\u003e\\n\u003c/body\u003e\\n\u003c/html\u003e\",\"css\":\"body {\\n text-align: center;\\n background-color: #25313e;\\n font-family: Arial;\\n}\\n\\nh1 {\\n color: #607489;\\n margin: 20px;\\n}\\n\\ntextarea {\\n width: 350px;\\n height: 350px;\\n padding: 15px;\\n border: 1px solid #aaa;\\n border-radius: 3px;\\n color: #ccc;\\n box-shadow: 0 0.25rem 0.5rem #12181e;\\n background-color: #191919;\\n text-align: center;\\n font-size: 16px;\\n line-height: 20px;\\n font-family: Monospace;\\n}\\n\\nbutton {\\n padding: 10px;\\n color: #eee;\\n margin: 10px 5px;\\n border: 1px solid #aaa;\\n border-radius: 3px;\\n box-shadow: 0 0.25rem 0.5rem #12181e;\\n font-size: 1rem;\\n cursor: pointer;\\n}\\n\\nbutton.red {\\n background-color: #fc4048;\\n}\\n\\nbutton.yellow {\\n background-color: #fd9409;\\n}\\n\\nbutton.green {\\n background-color: #1fc3b2;\\n}\",\"js\":\"$('#start').click(start); //開始遊戲\\n$('#guess').click(function () {\\n var str = prompt('輸入四位不重複數字');\\n guess(str); //將輸入的數字丟進遊戲去猜\\n});\\n$('#crack').click(crack); //破解遊戲\\n\\nvar answer = undefined; //存放解答\\nvar count = 0; //紀錄猜的字數\\n\\nstart(); //預設開始遊戲\\n\\n// 開始新的一局遊戲\\nfunction start () {\\n $('#textarea').append('\\\\n========== 開始新的遊戲 ==========\\\\n\\\\n');\\n count = 0; //歸零紀錄猜的次數\\n var list = getList();\\n var rand = Math.floor(Math.random() * list.length);\\n answer = list[rand];\\n console.log(answer);\\n}\\n\\n// 傳入四位數字的字串 str 並將結果顯示到畫面上\\nfunction guess (str) {\\n var result = diff(str, answer);\\n count++;\\n $(\\\"#textarea\\\").append(`${count} 猜${str} A:${result.a} B:${result.b}\\\\n `);\\n if (result.a == 4) {\\n $(\\\"#textarea\\\").append(`\\\\n猜對了!\\\\n`);\\n }\\n\\n return result;\\n}\\n\\n// 取得所有可能的答案的組合\\nfunction getList () {\\n var list = [];\\n for (var i = 123; i \u003c= 9876; i++) {\\n var tmp = i.toString();\\n if (tmp.length \u003c 4) {\\n tmp = \\\"0\\\" + tmp;\\n }\\n if (tmp[0] != tmp[1] \u0026\u0026 tmp[0] != tmp[2] \u0026\u0026 tmp[0] != tmp[3] \u0026\u0026 tmp[1] != tmp[2] \u0026\u0026 tmp[1] != tmp[3] \u0026\u0026 tmp[2] != tmp[3]) {\\n list.push(tmp);\\n }\\n }\\n // console.log(list);\\n return list;\\n}\\n\\n// 比較 s1, s2 並返回一帶有 a,b 資訊個物件來表示結果\\n// a 表示位置一樣且數字一樣\\n// b 表示數字有出現,但位置不一樣\\nfunction diff (s1, s2) {\\n var aVal = 0;\\n var bVal = 0;\\n for (var i = 0; i \u003c 4; i++) {\\n var index = s1.indexOf(s2[i]);\\n if (index != -1) {\\n if (index == i) {\\n aVal++;\\n } else\\n bVal++;\\n }\\n }\\n\\n return {\\n a: aVal, b: bVal\\n };\\n}\\n\\n// 用程式自動破解 1A2B 遊戲\\nfunction crack () {\\n var list = getList();\\n // noprotect\\n for (var i = 0; i \u003c 5040; i++) {\\n var g = list.pop();\\n var result = guess(g);\\n if (result.a == 4) break;\\n \\n for (var k = 0; k \u003c list.length; k++) {\\n var d = diff(list[k], g);\\n if (d.a != result.a || d.b != result.b) {\\n list.splice(k, 1);\\n k--;\\n }\\n }\\n }\\n\\n}\"}","created_at":"2020-06-07T13:29:47.166+08:00","updated_at":"2023-09-26T21:07:48.828+08:00","name":"破解 1A2B 推理遊戲(預設版)","language":"web","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/156956/bbc8c950ac11ef7bca2a54a12a0d4fc4.jpg"},"parent_id":3,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":45,"hashid":"wdkskdd5","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
前往網站頁面
1:1:1
1:1
full
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦