{"id":512110,"student_id":2589,"content":"setBackdrop(\"bg.png\");\nlet nextShape = createSprite('s_0.png', 's_1.png', 's_2.png', 's_3.png', 's_4.png', 's_5.png', 's_6.png');\nlet moving = []; //存放移動的磚塊\nlet fixed = []; //存放固定的磚塊\nlet lines = []; //存放提示燈角色\nlet score = 0; //分數\nlet clock = 0; //紀錄遊戲迴圈執行次數\n\nnextShape.moveTo(175, 175);\n\nfor (let i = 0; i \u003c 10; i++) {\n let l = createSprite('line.png');\n l.x = 50 * i + 375;\n lines.push(l);\n}\n\nlet shapeList = [\n [[0, 0], [0, 1], [0, 2], [0, 3]], //長條形\n [[0, 0], [1, 0], [0, 1], [1, 1]], //正方形\n [[1, 0], [2, 0], [0, 1], [1, 1]], //反Z形\n [[0, 0], [1, 0], [1, 1], [2, 1]], //Z形\n [[0, 0], [1, 0], [2, 0], [2, 1]], //反L形\n [[0, 0], [1, 0], [2, 0], [0, 1]], //L形\n [[0, 0], [1, 0], [2, 0], [1, 1]], //山形\n]\n\non('keydown', 'up', turnRight); //當按上鍵\non('keydown', 'down', moveDownToEnd); //當按下鍵\non('keydown', 'right', moveRight); //當按右鍵\non('keydown', 'left', moveLeft); //當按左鍵\n\nforever(loop); //重複不斷執行遊戲迴圈\nnextShape.costumeId = Math.floor(Math.random() * 7);\nloadBlocks();\n\ncreateSound('bgm.mp3', true);\n\n// 載入磚塊\nfunction loadBlocks () {\n let shape = shapeList[nextShape.costumeId];\n for (let i = 0; i \u003c 4; i++) {\n let b = createSprite('0.png', '1.png', '2.png', '3.png', '4.png', '5.png', '6.png', '7.png');\n b.x = shape[i][0] * 50 + 375 + 150;\n b.y = shape[i][1] * 50 + 25 - 150;\n b.costumeId = nextShape.costumeId;\n moving.push(b); // 存入陣列中\n }\n nextShape.costumeId = Math.floor(Math.random() * 7);\n createSound('drop.mp3');\n}\n\n// 遊戲主迴圈\nfunction loop () {\n drawText(score, 920, 70, '#444', 80); // 顯示分數\n checkGameover(); //檢查遊戲是否結束\n checkLines(); //檢查是否要消除磚塊\n autoMove(); //自動墜落\n for (let i = 0; i \u003c 10; i++) {\n lines[i].opacity = lines[i].touched(moving) ? 0.1: 0.01;\n }\n}\n\n//向下移動\nfunction moveDown () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].y += 50; // 向下移動一格\n }\n // 如果超出範圍或碰到固定的方塊就退回\n if (invalid()) {\n moveUp();\n fixed = fixed.concat(moving);\n moving = [];\n loadBlocks();\n return true;\n }\n return false;\n}\n\n//向上移動\nfunction moveUp () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].y -= 50;\n }\n}\n\n//向右移動\nfunction moveRight () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].x += 50;\n }\n if (invalid()) moveLeft();\n}\n\n//向左移動\nfunction moveLeft () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].x -= 50;\n }\n if (invalid()) moveRight();\n}\n\n//順時針選轉\nfunction turnRight (angle = 90) {\n let center = moving[1]; // 中心點方塊\n for (let i = 0; i \u003c moving.length; i++) {\n let b = moving[i];\n let d = b.distanceTo(center); // 算出要旋轉的方塊與中心之間的距離\n b.toward(center); // 朝向中心方塊\n b.stepForward(d); // 向前移動 d 距離\n b.direction -= angle; // 左轉 90 度\n b.stepForward(d); // 向前移動 d 距離\n b.direction = 90; // 恢復方向\n }\n if (invalid()) turnRight(-90);\n}\n\n// 移動後檢查是否超過範圍或碰到固定方塊\nfunction invalid () {\n for (let i = 0; i \u003c moving.length; i++) {\n let b = moving[i];\n if (b.y \u003e 900 || b.x \u003c 350 || b.x \u003e 850 || b.touched(fixed)) {\n return true; //發現有不合法磚塊\n }\n }\n return false; //檢查沒問題\n}\n\n// 自動墜落\nfunction autoMove() {\n clock++;\n let level = Math.floor(score / 100);\n if (level \u003e 20) level = 20;\n if (clock % (30 - level) == 0) moveDown(); // 自動墜落\n}\n\n//檢查是否佔滿一行\nfunction checkLines () {\n // 紀錄一共 18 層的每一層方塊數量\n let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n let line = 0; //消除的行數\n\n for (let i = 0; i \u003c fixed.length; i++) {\n f = Math.floor(fixed[i].y / 50); // 算出該方塊所在層數\n arr[f] += 1; //將該行磚塊數存入陣列\n }\n\n for (let i = 0; i \u003c 18; i++) {\n //drawText(arr[i], 300, i*50, 'white', 50);\n if (arr[i] == 10) { //如果該行填滿 10 個磚塊\n eraseLine(i); //消除該行\n line += 1; //行數增加\n createSound('score.mp3');\n }\n }\n \n // 根據消除行數增加分數\n if (line == 1) score += 40;\n if (line == 2) score += 100;\n if (line == 3) score += 300;\n if (line == 4) score += 1200;\n}\n\n// 清除一行\nfunction eraseLine (f) {\n for (let i = 0; i \u003c fixed.length; i++) {\n let floor = Math.floor(fixed[i].y / 50); // 取得該方塊所在層\n if (floor == f) fixed[i].y = 1000; // f 層移出遊戲場景外\n if (floor \u003c f) fixed[i].y += 50; // f 層以上向下移動一格\n }\n}\n\n// 檢查遊戲是否結束\nfunction checkGameover () {\n for (let i = 0; i \u003c fixed.length; i++) {\n if (fixed[i].y \u003c 50) gameover(); //如果有磚塊超出上方就結束遊戲\n }\n}\n\n// 遊戲結束特效\nfunction gameover () {\n for (let i = 0; i \u003c fixed.length; i++) {\n fixed[i].costumeId = 7; //將所有磚塊變成深色\n }\n stop();\n}\n\n// 快速向下移動\nfunction moveDownToEnd () {\n for (let i = 0; i \u003c 18; i++) {\n if (moveDown()) break; //如果碰到底部就停止\n }\n}\n","created_at":"2023-03-27T13:06:21.169+08:00","updated_at":"2023-03-29T13:55:13.742+08:00","name":"俄羅斯方塊 - 開始後用滑鼠點擊舞台以啟用按鍵,重整畫面即可重新遊戲。","language":"javascript","screenshot":{"url":null},"parent_id":2,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":59,"hashid":"meys62qgv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":11656928,"file_name":"drop.mp3","project_id":512110,"asset_id":616564,"created_at":"2023-03-27T13:06:30.348+08:00","updated_at":"2023-03-27T13:06:30.348+08:00"},{"id":11656929,"file_name":"bgm.mp3","project_id":512110,"asset_id":616565,"created_at":"2023-03-27T13:06:30.373+08:00","updated_at":"2023-03-27T13:06:30.373+08:00"},{"id":11656930,"file_name":"line.png","project_id":512110,"asset_id":616566,"created_at":"2023-03-27T13:06:30.387+08:00","updated_at":"2023-03-27T13:06:30.387+08:00"},{"id":11656931,"file_name":"score.mp3","project_id":512110,"asset_id":616567,"created_at":"2023-03-27T13:06:30.403+08:00","updated_at":"2023-03-27T13:06:30.403+08:00"},{"id":11656932,"file_name":"s_6.png","project_id":512110,"asset_id":616568,"created_at":"2023-03-27T13:06:30.419+08:00","updated_at":"2023-03-27T13:06:30.419+08:00"},{"id":11656933,"file_name":"s_5.png","project_id":512110,"asset_id":616569,"created_at":"2023-03-27T13:06:30.434+08:00","updated_at":"2023-03-27T13:06:30.434+08:00"},{"id":11656934,"file_name":"s_4.png","project_id":512110,"asset_id":616570,"created_at":"2023-03-27T13:06:30.451+08:00","updated_at":"2023-03-27T13:06:30.451+08:00"},{"id":11656935,"file_name":"s_3.png","project_id":512110,"asset_id":616571,"created_at":"2023-03-27T13:06:30.464+08:00","updated_at":"2023-03-27T13:06:30.464+08:00"},{"id":11656936,"file_name":"s_2.png","project_id":512110,"asset_id":616572,"created_at":"2023-03-27T13:06:30.478+08:00","updated_at":"2023-03-27T13:06:30.478+08:00"},{"id":11656937,"file_name":"s_1.png","project_id":512110,"asset_id":616573,"created_at":"2023-03-27T13:06:30.490+08:00","updated_at":"2023-03-27T13:06:30.490+08:00"},{"id":11656938,"file_name":"s_0.png","project_id":512110,"asset_id":616574,"created_at":"2023-03-27T13:06:30.504+08:00","updated_at":"2023-03-27T13:06:30.504+08:00"},{"id":11656939,"file_name":"gameover.png","project_id":512110,"asset_id":616575,"created_at":"2023-03-27T13:06:30.518+08:00","updated_at":"2023-03-27T13:06:30.518+08:00"},{"id":11656940,"file_name":"bg.png","project_id":512110,"asset_id":616576,"created_at":"2023-03-27T13:06:30.534+08:00","updated_at":"2023-03-27T13:06:30.534+08:00"},{"id":11656941,"file_name":"7.png","project_id":512110,"asset_id":616577,"created_at":"2023-03-27T13:06:30.547+08:00","updated_at":"2023-03-27T13:06:30.547+08:00"},{"id":11656942,"file_name":"6.png","project_id":512110,"asset_id":616578,"created_at":"2023-03-27T13:06:30.557+08:00","updated_at":"2023-03-27T13:06:30.557+08:00"},{"id":11656943,"file_name":"5.png","project_id":512110,"asset_id":616579,"created_at":"2023-03-27T13:06:30.569+08:00","updated_at":"2023-03-27T13:06:30.569+08:00"},{"id":11656944,"file_name":"4.png","project_id":512110,"asset_id":616580,"created_at":"2023-03-27T13:06:30.582+08:00","updated_at":"2023-03-27T13:06:30.582+08:00"},{"id":11656945,"file_name":"3.png","project_id":512110,"asset_id":616581,"created_at":"2023-03-27T13:06:30.590+08:00","updated_at":"2023-03-27T13:06:30.590+08:00"},{"id":11656946,"file_name":"2.png","project_id":512110,"asset_id":616582,"created_at":"2023-03-27T13:06:30.605+08:00","updated_at":"2023-03-27T13:06:30.605+08:00"},{"id":11656947,"file_name":"1.png","project_id":512110,"asset_id":616583,"created_at":"2023-03-27T13:06:30.621+08:00","updated_at":"2023-03-27T13:06:30.621+08:00"},{"id":11656948,"file_name":"0.png","project_id":512110,"asset_id":616584,"created_at":"2023-03-27T13:06:30.635+08:00","updated_at":"2023-03-27T13:06:30.635+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦