{"id":128834,"student_id":1998,"content":"var order1 = createGroup(vendor1);\nvar order2 = createGroup(vendor2);\nvar order3 = createGroup(vendor3);\n\n// First-Come First-Served\nforever(function () {\n if (order1.length \u003e 0) {\n order1[0].number -= 1;\n if (order1[0].number \u003c= 0) {\n order1.shift();\n }\n };\n});\n\n// Shortest Job First\nforever(function () {\n order2.sort(function(a, b) {\n return a.number - b.number;\n })\n if (order1.length \u003e 0) {\n order1[0].number -= 1;\n if (order1[0].number \u003c= 0) {\n order1.shift();\n }\n };\n});\nvar count = 0;\nforever(function () {\n if (order3.length \u003e 0)\n console.log(order3[count]);\n if (order3[count].number \u003c= 0) {\n order3.splice(count, 1);\n }\n\n count++\n if (count \u003e= order3.length) {\n count = 0;\n }\n\n}","created_at":"2020-02-22T16:37:10.090+08:00","updated_at":"2020-03-06T22:03:46.292+08:00","name":"Schedule 排程 副本","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/128834/89edcce60b8890776f43b51e69f48ea4.jpg"},"parent_id":31715,"plugin":"var vendor1 = createSprite('vendor_1.png');\nvendor1.scale = 0.2;\nvendor1.x -= 150;\nvendor1.y -= 120;\nvar vendor2 = createSprite('vendor_2.png');\nvendor2.scale = 0.2;\nvendor2.x -= 150;\nvendor2.y += 10;\nvar vendor3 = createSprite('vendor_3.png');\nvendor3.scale = 0.2;\nvendor3.x -= 150;\nvendor3.y += 140;\n\nvar groups = []; // 存放攤販對應的客人群\n\n// 攤販對應的客人群\nfunction createGroup (vendor) {\n var arr = [];\n arr.vendor = vendor;\n arr.count = 0; // 總客人數量\n arr.time = 0; // 所有的客人累積的等待時間\n setInterval(()=\u003e { arr.time += arr.length*100 }, 100);\n forever(()=\u003e {\n var t = Math.floor(arr.time/arr.count/10)/100\n print(`平均等待時間 ${t} 秒`, vendor.x - 50, vendor.y + 50, 'black');\n });\n groups.push(arr);\n return arr;\n}\n\n// 產生一個客人\nfunction createUnit (value, group) {\n\n var unit = createSprite([\"P-01.png\", \"P-02.png\", \"P-03.png\", \"P-04.png\", \"P-05.png\", \"P-06.png\", \"P-07.png\", \"P-08.png\", \"P-09.png\", \"P-10.png\"]);\n unit.x = 600;\n unit.y = group.vendor.y + 25;\n unit.scale = 0.15;\n unit.costumeId = Math.floor(Math.random() * 10);\n unit.number = value;\n\n unit.forever(function () {\n var idx = group.indexOf(unit);\n // 如果被移除的客人則將移動目標設為 -100\n if (idx == -1) {\n var target = -50;\n } else {\n var target = group.vendor.x + 80 + idx*30;\n }\n if (target \u003e unit.x) unit.x++;\n if (target \u003c unit.x) unit.x--;\n if (unit.x \u003c -50) unit.destroy();\n });\n\n group.push(unit);\n}\n\nforever(function () {\n\n //總人數上限為攤販車的個數乘上 10\n var total = 0;\n for (var i=0; i\u003cgroups.length; i++) total += groups[i].length;\n \n // 每秒鐘隨機產生一個客人\n if (Math.random()*60 \u003c 1 \u0026\u0026 total \u003c groups.length*10) {\n var value = Math.floor(Math.random()*150);\n groups.forEach((g) =\u003e {\n createUnit(value, g);\n g.count++;\n });\n }\n \n // 印出陣列內所有數值\n groups.forEach((g, idx) =\u003e {\n var arr = [];\n g.forEach((s)=\u003earr.push(s.number));\n print(`[ ${arr} ]`, 10, 10 + idx*20);\n });\n});\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":36,"hashid":"ej9syn9j","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2213883,"file_name":"P-10.png","project_id":128834,"asset_id":71811,"created_at":"2020-02-22T16:37:10.097+08:00","updated_at":"2020-02-22T16:37:10.097+08:00"},{"id":2213884,"file_name":"P-09.png","project_id":128834,"asset_id":71810,"created_at":"2020-02-22T16:37:10.098+08:00","updated_at":"2020-02-22T16:37:10.098+08:00"},{"id":2213885,"file_name":"P-08.png","project_id":128834,"asset_id":71809,"created_at":"2020-02-22T16:37:10.099+08:00","updated_at":"2020-02-22T16:37:10.099+08:00"},{"id":2213886,"file_name":"P-07.png","project_id":128834,"asset_id":71808,"created_at":"2020-02-22T16:37:10.100+08:00","updated_at":"2020-02-22T16:37:10.100+08:00"},{"id":2213887,"file_name":"P-06.png","project_id":128834,"asset_id":71807,"created_at":"2020-02-22T16:37:10.101+08:00","updated_at":"2020-02-22T16:37:10.101+08:00"},{"id":2213888,"file_name":"P-05.png","project_id":128834,"asset_id":71806,"created_at":"2020-02-22T16:37:10.102+08:00","updated_at":"2020-02-22T16:37:10.102+08:00"},{"id":2213889,"file_name":"P-04.png","project_id":128834,"asset_id":71805,"created_at":"2020-02-22T16:37:10.103+08:00","updated_at":"2020-02-22T16:37:10.103+08:00"},{"id":2213890,"file_name":"P-03.png","project_id":128834,"asset_id":71804,"created_at":"2020-02-22T16:37:10.104+08:00","updated_at":"2020-02-22T16:37:10.104+08:00"},{"id":2213891,"file_name":"P-02.png","project_id":128834,"asset_id":71803,"created_at":"2020-02-22T16:37:10.105+08:00","updated_at":"2020-02-22T16:37:10.105+08:00"},{"id":2213892,"file_name":"P-01.png","project_id":128834,"asset_id":71802,"created_at":"2020-02-22T16:37:10.106+08:00","updated_at":"2020-02-22T16:37:10.106+08:00"},{"id":2213893,"file_name":"vendor_1.png","project_id":128834,"asset_id":71801,"created_at":"2020-02-22T16:37:10.107+08:00","updated_at":"2020-02-22T16:37:10.107+08:00"},{"id":2213894,"file_name":"vendor_2.png","project_id":128834,"asset_id":71800,"created_at":"2020-02-22T16:37:10.108+08:00","updated_at":"2020-02-22T16:37:10.108+08:00"},{"id":2213895,"file_name":"vendor_3.png","project_id":128834,"asset_id":71799,"created_at":"2020-02-22T16:37:10.110+08:00","updated_at":"2020-02-22T16:37:10.110+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦