{"id":191860,"student_id":10,"content":"setBackdrop(\"bg.jpg\");\nlet nextShape = createSprite('s_0.png', 's_1.png', 's_2.png', 's_3.png', 's_4.png', 's_5.png', 's_6.png');\nnextShape.moveTo(1050, 300);\n\nlet moving = []; //存放移動的磚塊\nlet fixed = []; //存放固定的磚塊\nlet score = 0; //分數\nlet clock = 0; //紀錄遊戲迴圈執行次數\nlet level = 0; //等級\nlet next = 0;\nlet lines = [];\n\nlet shapeList = [\n [[1, 0], [1, 1], [1, 2], [1, 3]], //長條形\n [[1, 0], [1, 1], [1, 2], [2, 2]], //L形\n [[1, 0], [1, 1], [1, 2], [0, 2]], //反L形\n [[1, 0], [1, 1], [0, 1], [2, 1]], //山形\n [[1, 0], [1, 1], [0, 0], [2, 1]], //Z形\n [[1, 0], [1, 1], [0, 1], [2, 0]], //反Z形\n [[1, 0], [1, 1], [0, 0], [0, 1]], //正方形\n]\n\non('keydown', 'up', turnRight); //當按上鍵\n// on('keydown', 'down', moveDown); //當按下鍵\non('keydown', 'down', moveToEnd); //當按下鍵\non('keydown', 'right', moveRight); //當按右鍵\non('keydown', 'left', moveLeft); //當按左鍵\n\nloadBlocks(); //載入磚塊\nforever(loop); //重複不斷執行遊戲迴圈\n\nfor (let i = 0; i \u003c 10; i++) {\n let l = createSprite('line.png');\n l.x = 330 + 60 * i;\n lines.push(l);\n}\n\n// 遊戲主迴圈\nfunction loop () {\n drawText(score, 93, 664, 'black', 40);\n drawText(level, 95, 812, 'black', 40);\n\n checkGameover(); //檢查遊戲是否結束\n checkLines(); //檢查是否要消除磚塊\n\n clock++;\n if (clock % 30 == 0) moveDown();\n \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 loadBlocks () {\n let shape = shapeList[next];\n for (let i = 0; i \u003c 4; i++) {\n let b = createSprite('b_0.png', 'b_1.png', 'b_2.png', 'b_3.png', 'b_4.png', 'b_5.png', 'b_6.png')\n b.costumeId = next;\n b.x = shape[i][0] * 60 + 330;\n b.y = shape[i][1] * 60 + 30;\n moving.push(b);\n }\n next = Math.floor(Math.random()*7);\n}\n\n//向上移動\nfunction moveUp () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].y -= 60;\n }\n}\n\n//向下移動\nfunction moveDown () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].y += 60;\n }\n\n if (isOverRange()) {\n moveUp();\n fixed = fixed.concat(moving);\n moving.length = 0;\n loadBlocks();\n return true;\n }\n return false\n}\n\n//向右移動\nfunction moveRight () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].x += 60;\n }\n if (isOverRange()) moveLeft();\n}\n\n//向左移動\nfunction moveLeft () {\n for (let i = 0; i \u003c moving.length; i++) {\n moving[i].x -= 60;\n }\n if (isOverRange()) moveRight();\n}\n\nfunction turnRight () {\n turn(90);\n // if (isOverRange()) turn(-90);\n}\n\n//順時針選轉\nfunction turn (angle) {\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);\n b.direction += angle;\n b.stepForward(d);\n b.direction = 90;\n }\n}\n\nfunction isOverRange () {\n for (let i = 0; i \u003c moving.length; i++) {\n let b = moving[i];\n if (b.touched(fixed) || b.y \u003e 900 || b.x \u003c 300 || b.x \u003e 900) {\n return true;\n }\n }\n return false;\n}\n\n//檢查是否佔滿一行\nfunction checkLines () {\n\n let line = 0;\n let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n\n for (let i = 0; i \u003c fixed.length; i++) {\n f = Math.floor(fixed[i].y / 60)\n arr[f] += 1;\n }\n\n for (let i = 0; i \u003c 15; i++) {\n if (arr[i] == 10) {\n eraseLine(i);\n line++;\n }\n }\n if (line == 1) score += 10;\n if (line == 2) score += 50;\n if (line == 3) score += 100;\n if (line == 4) score += 300;\n\n level = Math.floor(score / 100);\n if (level \u003e 10) level = 10;\n}\n\n// 清除一行\nfunction eraseLine (f) {\n for (let i = 0; i \u003c fixed.length; i++) {\n let floor = Math.floor(fixed[i].y / 60)\n if (floor == f) fixed[i].y = 1000;\n if (floor \u003c f) fixed[i].y += 60;\n }\n}\n\n// 檢查遊戲是否結束\nfunction checkGameover () {\n for (let i = 0; i \u003c fixed.length; i++) {\n if (fixed[i].y \u003c 60) gameover();\n }\n}\n\n// 快速向下移動\nfunction moveToEnd () {\n let isEnd = false;\n while (isEnd == false) {\n isEnd = moveDown()\n }\n}\n\nfunction gameover () {\n for (let i = 0; i \u003c fixed.length; i++) {\n fixed[i].scale = 0.2;\n }\n stop();\n}","created_at":"2020-09-14T10:09:59.584+08:00","updated_at":"2021-12-30T17:04:17.733+08:00","name":"俄羅斯方塊","language":"javascript","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/191860/c09aadeaa4606f14cd32d8a76bbd8c1f.jpg"},"parent_id":2,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":234,"hashid":"meysrjwv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3272698,"file_name":"b_4.png","project_id":191860,"asset_id":262205,"created_at":"2020-09-14T10:10:12.268+08:00","updated_at":"2020-09-14T10:10:12.268+08:00"},{"id":3272699,"file_name":"b_5.png","project_id":191860,"asset_id":262206,"created_at":"2020-09-14T10:10:12.270+08:00","updated_at":"2020-09-14T10:10:12.270+08:00"},{"id":3272694,"file_name":"b_0.png","project_id":191860,"asset_id":262201,"created_at":"2020-09-14T10:10:11.362+08:00","updated_at":"2020-09-14T10:10:11.362+08:00"},{"id":3272695,"file_name":"b_1.png","project_id":191860,"asset_id":262202,"created_at":"2020-09-14T10:10:11.364+08:00","updated_at":"2020-09-14T10:10:11.364+08:00"},{"id":3272706,"file_name":"s_3.png","project_id":191860,"asset_id":262212,"created_at":"2020-09-14T10:10:15.623+08:00","updated_at":"2020-09-14T10:10:15.623+08:00"},{"id":3272707,"file_name":"s_4.png","project_id":191860,"asset_id":262213,"created_at":"2020-09-14T10:10:15.625+08:00","updated_at":"2020-09-14T10:10:15.625+08:00"},{"id":3272708,"file_name":"s_5.png","project_id":191860,"asset_id":262214,"created_at":"2020-09-14T10:10:16.088+08:00","updated_at":"2020-09-14T10:10:16.088+08:00"},{"id":3272709,"file_name":"s_6.png","project_id":191860,"asset_id":262215,"created_at":"2020-09-14T10:10:16.090+08:00","updated_at":"2020-09-14T10:10:16.090+08:00"},{"id":3272696,"file_name":"b_2.png","project_id":191860,"asset_id":262203,"created_at":"2020-09-14T10:10:11.792+08:00","updated_at":"2020-09-14T10:10:11.792+08:00"},{"id":3272697,"file_name":"b_3.png","project_id":191860,"asset_id":262204,"created_at":"2020-09-14T10:10:11.794+08:00","updated_at":"2020-09-14T10:10:11.794+08:00"},{"id":3272700,"file_name":"b_6.png","project_id":191860,"asset_id":262207,"created_at":"2020-09-14T10:10:13.632+08:00","updated_at":"2020-09-14T10:10:13.632+08:00"},{"id":3272701,"file_name":"bg.jpg","project_id":191860,"asset_id":262208,"created_at":"2020-09-14T10:10:13.638+08:00","updated_at":"2020-09-14T10:10:13.638+08:00"},{"id":3272702,"file_name":"gameover.png","project_id":191860,"asset_id":189062,"created_at":"2020-09-14T10:10:14.417+08:00","updated_at":"2020-09-14T10:10:14.417+08:00"},{"id":3272703,"file_name":"s_0.png","project_id":191860,"asset_id":262209,"created_at":"2020-09-14T10:10:14.597+08:00","updated_at":"2020-09-14T10:10:14.597+08:00"},{"id":3272704,"file_name":"s_1.png","project_id":191860,"asset_id":262210,"created_at":"2020-09-14T10:10:15.132+08:00","updated_at":"2020-09-14T10:10:15.132+08:00"},{"id":3272705,"file_name":"s_2.png","project_id":191860,"asset_id":262211,"created_at":"2020-09-14T10:10:15.134+08:00","updated_at":"2020-09-14T10:10:15.134+08:00"},{"id":7043293,"file_name":"line.png","project_id":191860,"asset_id":456381,"created_at":"2021-12-30T15:57:13.064+08:00","updated_at":"2021-12-30T15:57:13.064+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦