{"id":288322,"student_id":6762,"content":"{\"html\":\"\u003c!DOCTYPE html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n\\t\u003ctitle\u003eDocument\u003c/title\u003e\\n\\t\u003cscript src=\\\"https://code.jquery.com/jquery-3.2.1.min.js\\\"\u003e\u003c/script\u003e\\n\u003c/head\u003e\\n\u003cbody\u003e\\n \u003cdiv id=\\\"cover\\\"\u003e\\n \u003ch1\u003e紅藍大對決\u003c/h1\u003e\\n \u003ch2\u003eonline\u003c/h2\u003e\\n \u003ch3\u003e按下任何鍵來推擠對方\u003c/h3\u003e\\n \u003cbr/\u003e\\n \u003cbutton id=\\\"setId\\\"\u003e創造房間\u003c/button\u003e\\n \u003cbr /\u003e\\n \u003cbutton id=\\\"ready\\\"\u003e加入房間\u003c/button\u003e\\n \u003cbr /\u003e\\n \u003cbutton id=\\\"restart\\\"\u003e重新開始\u003c/button\u003e\\n \u003c/div\u003e\\n\u003c/body\u003e\\n\u003c/html\u003e\",\"css\":\"body {\\n width: 100vw;\\n height: 100vh;\\n background-image: url('bg.jpg');\\n background-size: cover;\\n background-position: center;\\n font-family: Arial;\\n}\\n\\n#cover {\\n width: 100vw;\\n height: 100vh;\\n padding-top: 30px;\\n color: #fff;\\n background-color: #00000099;\\n text-align: center;\\n}\\n\\nh1 {\\n font-size: 45px;\\n}\\nh2 {\\n font-size: 25px;\\n}\\n\\nbutton {\\n padding: 10px;\\n border: 2px solid #ccc;\\n font-size: 16px;\\n box-shadow: 3px 3px 15px white;\\n cursor: pointer;\\n}\\n\\n#restart {\\n display: none;\\n}\",\"js\":\"var id; //房間id\\nvar p1_count = 0; //自己的點擊次數\\nvar p2_count = 0; //對方的點擊次數\\nvar status = 0; //遊戲狀態 0: 等待, 1: 遊戲中, 2: 遊戲結束\\n$('#setId').click(setId);\\n$('#ready').click(ready);\\n$('body').keyup(push);\\n$('#restart').click(restart);\\nsocket.on(\\\"ready\\\", function(data) {\\n if (data == id) {\\n $(\\\"h1\\\").text(\\\"2號玩家已加入\\\");\\n $(\\\"h2\\\").text(\\\"你是紅色\\\");\\n $(\\\"h3\\\").text(\\\"正在布置場地\\\");\\n setTimeout(function() {\\n start();\\n socket.emit(\\\"start\\\", id);\\n }, 2000);\\n }\\n});\\nsocket.on(\\\"start\\\", function(data) {\\n if (data == id) {\\n start();\\n }\\n});\\nsocket.on(\\\"update\\\", function(data) {\\n if (data.id == id) {\\n p2_count = data.count;\\n update();\\n }\\n});\\nsocket.on(\\\"gameover\\\", function(data) {\\n if (id == data) {\\n gameover();\\n }\\n});\\n//產生房間 ID\\nfunction setId () {\\n id = Math.floor(Math.random() * 100000);\\n $(\\\"h1\\\").text(\\\"房間 ID:\\\" + id);\\n $(\\\"h2\\\").text(\\\"正在等待2號玩家加入\\\");\\n $(\\\"button\\\").hide();\\n}\\n//輸入對方 ID\\nfunction ready () {\\n id = prompt(\\\"請輸入房間 ID:\\\");\\n socket.emit(\\\"ready\\\", id);\\n $(\\\"button\\\").hide();\\n $(\\\"h1\\\").text(\\\"房間 ID:\\\" + id);\\n $(\\\"h2\\\").text(\\\"你是紅色\\\");\\n $(\\\"h3\\\").text(\\\"正在布置場地\\\");\\n}\\n//開始遊戲\\nfunction start () {\\n $(\\\"h1\\\").text(\\\"\\\");\\n $(\\\"h2\\\").text(\\\"\\\");\\n $(\\\"h3\\\").text(\\\"推擠對方\\\");\\n $(\\\"#cover\\\").fadeOut();\\n status = 1;\\n p1_count = 0; //自己的點擊次數\\n p2_count = 0;\\n $('body').css('background-image', 'url(\\\"bg.jpg\\\")');\\n update();\\n}\\n//推擠對方\\nfunction push () {\\n if (status == 1) {\\n p1_count += 1;\\n update();\\n socket.emit(\\\"update\\\", {\\n id: id, count: p1_count\\n });\\n }\\n\\n}\\n//更新遊戲畫面\\nfunction update () {\\n var diff = p1_count - p2_count;\\n $(\\\"body\\\").css(\\\"background-position-x\\\", `${diff + 50}%`);\\n if (diff \u003e= 45) {\\n status = 3;\\n gameover();\\n socket.emit(\\\"gameover\\\", id);\\n }\\n}\\n//遊戲結束\\nfunction gameover () {\\n $(\\\"#cover\\\").fadeIn();\\n if (p1_count \u003e p2_count) {\\n $('body').css('background-image', 'url(\\\"bg_win.jpg\\\")');\\n $('h1').text(\\\"YOU WIN✧*。٩(ˊωˋ*)و✧*。 \\\");\\n } else if (p1_count \u003c p2_count) {\\n $('body').css('background-image', 'url(\\\"bg_lose.jpg\\\")');\\n $('h1').text(\\\"YOU LOSE (ಥ_ಥ) \\\");\\n }\\n $(\\\"button\\\").hide();\\n $(\\\"#restart\\\").show();\\n}\\n//重新開始\\nfunction restart () {\\n socket.emit(\\\"ready\\\", id);\\n\\n\\n\\n\\n\\n\\n}\"}","created_at":"2021-08-15T13:29:30.104+08:00","updated_at":"2025-10-25T01:55:19.438+08:00","name":"紅藍連線大 PK 副本","language":"web","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/288322/b57378d035053dde4ad2de98f20a9fb1.jpg"},"parent_id":134129,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":6,"hashid":"882sq34gw","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":5717886,"file_name":"bg_win.jpg","project_id":288322,"asset_id":197884,"created_at":"2021-08-15T13:29:30.110+08:00","updated_at":"2021-08-15T13:29:30.110+08:00"},{"id":5717887,"file_name":"bg_lose.jpg","project_id":288322,"asset_id":197883,"created_at":"2021-08-15T13:29:30.111+08:00","updated_at":"2021-08-15T13:29:30.111+08:00"},{"id":5717888,"file_name":"bg.jpg","project_id":288322,"asset_id":197879,"created_at":"2021-08-15T13:29:30.112+08:00","updated_at":"2021-08-15T13:29:30.112+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
前往網站頁面
繁中
简中
English
日本語
1:1:1
1:1
全寬
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦