From 4e1ea20d3798983ca442783f03adf4486bac5091 Mon Sep 17 00:00:00 2001 From: qrhlhplhp <80515002+qrhlhplhp@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:19:37 +0900 Subject: [PATCH] add reversi --- .vscode/launch.json | 5 +- ultra-super-stylish-reversi/index.html | 22 +++++ ultra-super-stylish-reversi/main.css | 44 ++++++++++ ultra-super-stylish-reversi/main.js | 114 +++++++++++++++++++++++++ ultra-super-stylish-reversi/svru.svg | 52 +++++++++++ ultra-super-stylish-reversi/tools.svg | 86 +++++++++++++++++++ 6 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 ultra-super-stylish-reversi/index.html create mode 100644 ultra-super-stylish-reversi/main.css create mode 100644 ultra-super-stylish-reversi/main.js create mode 100644 ultra-super-stylish-reversi/svru.svg create mode 100644 ultra-super-stylish-reversi/tools.svg diff --git a/.vscode/launch.json b/.vscode/launch.json index b441df8..7ad678e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,10 +5,11 @@ "version": "0.2.0", "configurations": [ { - "type": "pwa-chrome", + "type": "chrome", "request": "launch", "name": "Launch Chrome against localhost", - "url": "http://localhost:8080", + "runtimeExecutable": "xdg-open", + "url": "http://localhost:5500", "webRoot": "${workspaceFolder}" } ] diff --git a/ultra-super-stylish-reversi/index.html b/ultra-super-stylish-reversi/index.html new file mode 100644 index 0000000..d7d793b --- /dev/null +++ b/ultra-super-stylish-reversi/index.html @@ -0,0 +1,22 @@ + + + + + + + + U-S-S-R + + +

Welcome to Ultra Super Stylish Reversi, USSR!!!

+
+
+
+

+ + +
+
+ + + \ No newline at end of file diff --git a/ultra-super-stylish-reversi/main.css b/ultra-super-stylish-reversi/main.css new file mode 100644 index 0000000..c73eed0 --- /dev/null +++ b/ultra-super-stylish-reversi/main.css @@ -0,0 +1,44 @@ +body{ + background-color:#cd0000 +} +#flag{ + background-image:url(svru.svg) +} +h1{ + color:#ffd700; + background-color:#cd0000; +} +#ussr{ + font-size:200%; +} +#table{ + background-color:transparent; + margin-left:30vw; +} +#table td{ + border: 1px solid white; + width:10vmin; height:10vmin; +} +#flex{ + padding-left:1vw; + color:#ffd700; +} +.stone{ + border-radius:100%; + width:100%;height:100% +} +.yellow{ + background-color:#ffd700; +} +.blue{ + background-color:#0091fa; +} +.flag{ + background-image:url(tools.svg); + background-size: cover; + width:100%;height:100% +} +img{ + margin-top: 5vh; + width: 100%; +} \ No newline at end of file diff --git a/ultra-super-stylish-reversi/main.js b/ultra-super-stylish-reversi/main.js new file mode 100644 index 0000000..aedc795 --- /dev/null +++ b/ultra-super-stylish-reversi/main.js @@ -0,0 +1,114 @@ +let table = document.getElementById("table"); +let param = document.getElementById("param"); +const pass = document.getElementById("pass"); +const revo = document.getElementById("revo"); +let sovi = false; +let htable = ""; + +//[left, botleft, bottom, botright, right, topright, top, topleft] +const movec = [[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1]]; + +//0->nill, 1->yellow, 2->blue +let turn = 1 +param.innerText = (turn == 1 ? "yellow" : "blue") + "man's turn" ; + +let stone = new Array(8); +for(let i = 0; i < 8; i++) { + stone[i] = new Array(8).fill(0); +} + +for (let i = 0; i < 8; ++i){ + htable += ``; + for (let j = 0; j < 8; ++j){ + htable += ``; + } + htable += ""; +} +table.innerHTML = htable; + +stone[3][3] = 1; stone[4][4] = 1; +stone[4][3] = 2; stone[3][4] = 2; +document.getElementById("td-3-3").innerHTML = "
"; +document.getElementById("td-4-4").innerHTML = "
"; +document.getElementById("td-4-3").innerHTML = "
"; +document.getElementById("td-3-4").innerHTML = "
"; + +table.addEventListener('click', e =>{ + let coord = document.elementFromPoint(e.clientX, e.clientY); + if(coord.tagName != "TD")return; + + const stonegen = coord.id.split("-"); + //position of the stone to put right now + let x = Number(stonegen[1]); + let y = Number(stonegen[2]); + + if(stone[x][y] == 0/*nill stone*/){ + let canPlace = false; + for(let i = 0; i < 8; i++){ + let moved = 0; + let doFlip = new Array(); + while(true){ + ++moved + //stone[x-position + x-move (<- x-move-amount * x-move-counter)] + const nowX = x + movec[i][0] * moved; + const nowY = y + movec[i][1] * moved; + if(nowX < 0 || nowX > 7 || nowY < 0 || nowY > 7) break;//change vector because there's wall! + let nowStone = stone[nowX][nowY]; + if(nowStone !=turn && nowStone != 0){ + doFlip.push([x + movec[i][0] * moved, y + movec[i][1] * moved]); + }else if(nowStone == turn && moved > 1){ + canPlace = true; + for(let i = 0; i < doFlip.length; i++){ + stone[doFlip[i][0]][doFlip[i][1]] = turn; + const doFlipCell = document.getElementById(`td-${doFlip[i][0]}-${doFlip[i][1]}`).children[0]; + doFlipCell.classList.remove(turn != 1 ? "yellow" : "blue"); + doFlipCell.classList.add(turn == 1 ? "yellow" : "blue"); + } + break; + }else{ + break; + } + } + } + if(!canPlace)return; + stone[x][y] = turn + coord.innerHTML = `
`; + turnchange(); + } +}); + +pass.addEventListener('click', e=>{ + if(sovi){ + leaderchange() + }else{ + turnchange() + } +}); + +function leaderchange(){ + turn = turn==1 ? 2 : 1; + param.innerText = (turn == 1 ? "Starin" : "Lenin") + "'s turn"; +} +function turnchange(){ + turn = turn==1 ? 2 : 1; + param.innerText = (turn == 1 ? "yellow" : "blue") + "man's turn"; +} + +revo.addEventListener('click', e=>{ + if(sovi)return; + sovi = true; + /*stone = stone.map(line=>{ + return line.map(cell=>{ + return 0; + }); + });*/ + for(let i = 0; i < 8; i++){ + for(let j = 0; j < 8; j++){ + stone[i][j] = 0; + document.getElementById(`td-${i}-${j}`).innerHTML = `
`; + turn = 2; + param.innerText = "Lenin's turn"; + } + } + } +); \ No newline at end of file diff --git a/ultra-super-stylish-reversi/svru.svg b/ultra-super-stylish-reversi/svru.svg new file mode 100644 index 0000000..01275c1 --- /dev/null +++ b/ultra-super-stylish-reversi/svru.svg @@ -0,0 +1,52 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/ultra-super-stylish-reversi/tools.svg b/ultra-super-stylish-reversi/tools.svg new file mode 100644 index 0000000..c8ab36a --- /dev/null +++ b/ultra-super-stylish-reversi/tools.svg @@ -0,0 +1,86 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + +