diff --git a/index.html b/index.html index ecd6b124..79ad2358 100644 --- a/index.html +++ b/index.html @@ -524,7 +524,13 @@
GAME
+
`
+ image.style.cursor = 'pointer'
+
+ }
+
+ else {
+
+ image.innerHTML = `${image.innerText}
`
+ image.style.cursor = 'pointer'
+ }
+ }
+ })
+}
+insertImage()
+
+
+
+//Coloring
+
+function coloring() {
+ const color = document.querySelectorAll('.box')
+
+ color.forEach(color => {
+
+ getId = color.id
+ arr = Array.from(getId)
+ arr.shift()
+ aside = eval(arr.pop())
+ aup = eval(arr.shift())
+ a = aside + aup
+
+ if (a % 2 == 0) {
+ color.style.backgroundColor = 'rgb(240, 201, 150)'
+ }
+ if (a % 2 !== 0) {
+ color.style.backgroundColor = 'rgb(100, 75, 43)'
+ }
+
+ })
+}
+coloring()
+
+
+
+
+//function to not remove the same team element
+
+function reddish() {
+ document.querySelectorAll('.box').forEach(i1 => {
+ if (i1.style.backgroundColor == 'pink') {
+
+ document.querySelectorAll('.box').forEach(i2 => {
+
+ if (i2.style.backgroundColor == 'green' && i2.innerText.length !== 0) {
+
+
+ greenText = i2.innerText
+
+ pinkText = i1.innerText
+
+ pinkColor = ((Array.from(pinkText)).shift()).toString()
+ greenColor = ((Array.from(greenText)).shift()).toString()
+
+ getId = i2.id
+ arr = Array.from(getId)
+ arr.shift()
+ aside = eval(arr.pop())
+ aup = eval(arr.shift())
+ a = aside + aup
+
+ if (a % 2 == 0 && pinkColor == greenColor) {
+ i2.style.backgroundColor = 'rgb(240, 201, 150)'
+ }
+ if (a % 2 !== 0 && pinkColor == greenColor) {
+ i2.style.backgroundColor = 'rgb(100, 75, 43)'
+ }
+
+ // if (pinkColor == greenColor) {
+ // i2.style.backgroundColor = 'rgb(253, 60, 60)'
+ // }
+ }
+ })
+ }
+ })
+}
+
+
+
+
+
+
+
+
+
+
+tog = 1
+
+document.querySelectorAll('.box').forEach(item => {
+
+
+
+ item.addEventListener('click', function () {
+
+ // To delete the opposite element
+
+ if (item.style.backgroundColor == 'green' && item.innerText.length == 0) {
+ tog = tog + 1
+ }
+
+ else if (item.style.backgroundColor == 'green' && item.innerText.length !== 0) {
+
+ document.querySelectorAll('.box').forEach(i => {
+ if (i.style.backgroundColor == 'pink') {
+ pinkId = i.id
+ pinkText = i.innerText
+
+ document.getElementById(pinkId).innerText = ''
+ item.innerText = pinkText
+ coloring()
+ insertImage()
+ tog = tog + 1
+
+ }
+ })
+ }
+
+
+
+ getId = item.id
+ arr = Array.from(getId)
+ arr.shift()
+ aside = eval(arr.pop())
+ arr.push('0')
+ aup = eval(arr.join(''))
+ a = aside + aup
+
+
+
+ // Function to display the available paths for all pieces
+
+ function whosTurn(toggle) {
+
+ // PAWN
+
+ if (item.innerText == `${toggle}pawn`) {
+ item.style.backgroundColor = 'pink'
+
+ if (tog % 2 !== 0 && aup < 800) {
+
+ if (document.getElementById(`b${a + 100}`).innerText.length == 0) {
+ document.getElementById(`b${a + 100}`).style.backgroundColor = 'green'
+ }
+
+ if (aside < 8 && document.getElementById(`b${a + 100 + 1}`).innerText.length !== 0) {
+ document.getElementById(`b${a + 100 + 1}`).style.backgroundColor = 'green'
+ }
+
+ if (aside > 1 && document.getElementById(`b${a + 100 - 1}`).innerText.length !== 0) {
+ document.getElementById(`b${a + 100 - 1}`).style.backgroundColor = 'green'
+
+ }
+ }
+
+ if (tog % 2 == 0 && aup > 100) {
+
+ if (document.getElementById(`b${a - 100}`).innerText.length == 0) {
+ document.getElementById(`b${a - 100}`).style.backgroundColor = 'green'
+ }
+ if (aside < 8 && document.getElementById(`b${a - 100 + 1}`).innerText.length !== 0) {
+ document.getElementById(`b${a - 100 + 1}`).style.backgroundColor = 'green'
+ }
+ if (aside > 1 && document.getElementById(`b${a - 100 - 1}`).innerText.length !== 0) {
+ document.getElementById(`b${a - 100 - 1}`).style.backgroundColor = 'green'
+
+ }
+ }
+
+
+ }
+
+ // KING
+
+ if (item.innerText == `${toggle}king`) {
+
+
+ if (aside < 8) {
+ document.getElementById(`b${a + 1}`).style.backgroundColor = 'green'
+
+ }
+ if (aside > 1) {
+
+ document.getElementById(`b${a - 1}`).style.backgroundColor = 'green'
+ }
+ if (aup < 800) {
+
+ document.getElementById(`b${a + 100}`).style.backgroundColor = 'green'
+ }
+ if (aup > 100) {
+
+ document.getElementById(`b${a - 100}`).style.backgroundColor = 'green'
+ }
+
+ if (aup > 100 && aside < 8) {
+
+ document.getElementById(`b${a - 100 + 1}`).style.backgroundColor = 'green'
+ }
+ if (aup > 100 && aside > 1) {
+
+ document.getElementById(`b${a - 100 - 1}`).style.backgroundColor = 'green'
+ }
+ if (aup < 800 && aside < 8) {
+
+ document.getElementById(`b${a + 100 + 1}`).style.backgroundColor = 'green'
+ }
+ if (aup < 800 && aside > 1) {
+
+ document.getElementById(`b${a + 100 - 1}`).style.backgroundColor = 'green'
+ }
+
+ item.style.backgroundColor = 'pink'
+
+ }
+
+
+ // ROOK
+
+ if (item.innerText == `${toggle}rook`) {
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a + i * 100) < 900 && document.getElementById(`b${a + i * 100}`).innerText == 0) {
+ document.getElementById(`b${a + i * 100}`).style.backgroundColor = 'green'
+ }
+ else if ((a + i * 100) < 900 && document.getElementById(`b${a + i * 100}`).innerText !== 0) {
+ document.getElementById(`b${a + i * 100}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a - i * 100) > 100 && document.getElementById(`b${a - i * 100}`).innerText == 0) {
+ document.getElementById(`b${a - i * 100}`).style.backgroundColor = 'green'
+ }
+ else if ((a - i * 100) > 100 && document.getElementById(`b${a - i * 100}`).innerText !== 0) {
+ document.getElementById(`b${a - i * 100}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a + i) < (aup + 9) && document.getElementById(`b${a + i}`).innerText == 0) {
+ document.getElementById(`b${a + i}`).style.backgroundColor = 'green'
+ }
+ else if ((a + i) < (aup + 9) && document.getElementById(`b${a + i}`).innerText !== 0) {
+ document.getElementById(`b${a + i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a - i) > (aup) && document.getElementById(`b${a - i}`).innerText == 0) {
+ document.getElementById(`b${a - i}`).style.backgroundColor = 'green'
+ }
+ else if ((a - i) > (aup) && document.getElementById(`b${a - i}`).innerText !== 0) {
+ document.getElementById(`b${a - i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ item.style.backgroundColor = 'pink'
+ }
+
+
+
+ // BISHOP
+
+ if (item.innerText == `${toggle}bishop`) {
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < (900 - aup) / 100 && i < 9 - aside && document.getElementById(`b${a + i * 100 + i}`).innerText.length == 0) {
+ document.getElementById(`b${a + i * 100 + i}`).style.backgroundColor = 'green'
+ }
+ else if (i < (900 - aup) / 100 && i < 9 - aside && document.getElementById(`b${a + i * 100 + i}`).innerText.length !== 0) {
+ document.getElementById(`b${a + i * 100 + i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < aup / 100 && i < 9 - aside && document.getElementById(`b${a - i * 100 + i}`).innerText.length == 0) {
+ document.getElementById(`b${a - i * 100 + i}`).style.backgroundColor = 'green'
+ }
+ else if (i < aup / 100 && i < 9 - aside && document.getElementById(`b${a - i * 100 + i}`).innerText.length !== 0) {
+ document.getElementById(`b${a - i * 100 + i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < (900 - aup) / 100 && i < aside && document.getElementById(`b${a + i * 100 - i}`).innerText.length == 0) {
+ document.getElementById(`b${a + i * 100 - i}`).style.backgroundColor = 'green'
+ }
+ else if (i < (900 - aup) / 100 && i < aside && document.getElementById(`b${a + i * 100 - i}`).innerText.length !== 0) {
+ document.getElementById(`b${a + i * 100 - i}`).style.backgroundColor = 'green'
+ break
+ }
+
+ }
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < aup / 100 && i < aside && document.getElementById(`b${a - i * 100 - i}`).innerText.length == 0) {
+ document.getElementById(`b${a - i * 100 - i}`).style.backgroundColor = 'green'
+ }
+ else if (i < aup / 100 && i < aside && document.getElementById(`b${a - i * 100 - i}`).innerText.length !== 0) {
+ document.getElementById(`b${a - i * 100 - i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+
+ item.style.backgroundColor = 'pink'
+
+ }
+
+
+
+ // QUEEN
+
+ if (item.innerText == `${toggle}queen`) {
+
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a + i * 100) < 900 && document.getElementById(`b${a + i * 100}`).innerText == 0) {
+ document.getElementById(`b${a + i * 100}`).style.backgroundColor = 'green'
+ }
+ else if ((a + i * 100) < 900 && document.getElementById(`b${a + i * 100}`).innerText !== 0) {
+ document.getElementById(`b${a + i * 100}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a - i * 100) > 100 && document.getElementById(`b${a - i * 100}`).innerText == 0) {
+ document.getElementById(`b${a - i * 100}`).style.backgroundColor = 'green'
+ }
+ else if ((a - i * 100) > 100 && document.getElementById(`b${a - i * 100}`).innerText !== 0) {
+ document.getElementById(`b${a - i * 100}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a + i) < (aup + 9) && document.getElementById(`b${a + i}`).innerText == 0) {
+ document.getElementById(`b${a + i}`).style.backgroundColor = 'green'
+ }
+ else if ((a + i) < (aup + 9) && document.getElementById(`b${a + i}`).innerText !== 0) {
+ document.getElementById(`b${a + i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+ for (let i = 1; i < 9; i++) {
+
+ if ((a - i) > (aup) && document.getElementById(`b${a - i}`).innerText == 0) {
+ document.getElementById(`b${a - i}`).style.backgroundColor = 'green'
+ }
+ else if ((a - i) > (aup) && document.getElementById(`b${a - i}`).innerText !== 0) {
+ document.getElementById(`b${a - i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < (900 - aup) / 100 && i < 9 - aside && document.getElementById(`b${a + i * 100 + i}`).innerText.length == 0) {
+ document.getElementById(`b${a + i * 100 + i}`).style.backgroundColor = 'green'
+ }
+ else if (i < (900 - aup) / 100 && i < 9 - aside && document.getElementById(`b${a + i * 100 + i}`).innerText.length !== 0) {
+ document.getElementById(`b${a + i * 100 + i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < aup / 100 && i < 9 - aside && document.getElementById(`b${a - i * 100 + i}`).innerText.length == 0) {
+ document.getElementById(`b${a - i * 100 + i}`).style.backgroundColor = 'green'
+ }
+ else if (i < aup / 100 && i < 9 - aside && document.getElementById(`b${a - i * 100 + i}`).innerText.length !== 0) {
+ document.getElementById(`b${a - i * 100 + i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < (900 - aup) / 100 && i < aside && document.getElementById(`b${a + i * 100 - i}`).innerText.length == 0) {
+ document.getElementById(`b${a + i * 100 - i}`).style.backgroundColor = 'green'
+ }
+ else if (i < (900 - aup) / 100 && i < aside && document.getElementById(`b${a + i * 100 - i}`).innerText.length !== 0) {
+ document.getElementById(`b${a + i * 100 - i}`).style.backgroundColor = 'green'
+ break
+ }
+
+ }
+
+
+ for (let i = 1; i < 9; i++) {
+ if (i < aup / 100 && i < aside && document.getElementById(`b${a - i * 100 - i}`).innerText.length == 0) {
+ document.getElementById(`b${a - i * 100 - i}`).style.backgroundColor = 'green'
+ }
+ else if (i < aup / 100 && i < aside && document.getElementById(`b${a - i * 100 - i}`).innerText.length !== 0) {
+ document.getElementById(`b${a - i * 100 - i}`).style.backgroundColor = 'green'
+ break
+ }
+ }
+
+
+
+ item.style.backgroundColor = 'pink'
+
+ }
+
+ // KNIGHT
+
+ if (item.innerText == `${toggle}knight`) {
+
+
+ if (aside < 7 && aup < 800) {
+ document.getElementById(`b${a + 100 + 2}`).style.backgroundColor = 'green'
+ }
+ if (aside < 7 && aup > 200) {
+ document.getElementById(`b${a - 100 + 2}`).style.backgroundColor = 'green'
+ }
+ if (aside < 8 && aup < 700) {
+ document.getElementById(`b${a + 200 + 1}`).style.backgroundColor = 'green'
+ }
+ if (aside > 1 && aup < 700) {
+ document.getElementById(`b${a + 200 - 1}`).style.backgroundColor = 'green'
+ }
+ if (aside > 2 && aup < 800) {
+ document.getElementById(`b${a - 2 + 100}`).style.backgroundColor = 'green'
+ }
+ if (aside > 2 && aup > 100) {
+ document.getElementById(`b${a - 2 - 100}`).style.backgroundColor = 'green'
+ }
+ if (aside < 8 && aup > 200) {
+ document.getElementById(`b${a - 200 + 1}`).style.backgroundColor = 'green'
+ }
+ if (aside > 1 && aup > 200) {
+ document.getElementById(`b${a - 200 - 1}`).style.backgroundColor = 'green'
+ }
+
+ item.style.backgroundColor = 'pink'
+
+ }
+ }
+
+
+ // Toggling the turn
+
+ if (tog % 2 !== 0) {
+ document.getElementById('tog').innerText = "White's Turn"
+ whosTurn('W')
+ }
+ if (tog % 2 == 0) {
+ document.getElementById('tog').innerText = "Black's Turn"
+ whosTurn('B')
+ }
+
+ reddish()
+
+
+
+ // winning()
+
+ numOfKings = 0
+
+
+ document.querySelectorAll('.box').forEach(win => {
+ if (win.innerText == 'Wking' || win.innerText == 'Bking') {
+ numOfKings += 1
+ }
+
+ })
+
+ if (numOfKings == 1) {
+ setTimeout(() => {
+ // console.log(`${toggle}`)
+ if (tog % 2 == 0) {
+ alert('White Wins !!')
+ location.reload()
+ }
+ else if (tog % 2 !== 0) {
+ alert('Black Wins !!')
+ location.reload()
+ }
+ }, 100)
+ }
+
+
+
+ })
+
+})
+
+
+
+
+
+// Moving the element
+document.querySelectorAll('.box').forEach(hathiTest => {
+
+ hathiTest.addEventListener('click', function () {
+
+ if (hathiTest.style.backgroundColor == 'pink') {
+
+ pinkId = hathiTest.id
+ pinkText = hathiTest.innerText
+
+ document.querySelectorAll('.box').forEach(hathiTest2 => {
+
+ hathiTest2.addEventListener('click', function () {
+ if (hathiTest2.style.backgroundColor == 'green' && hathiTest2.innerText.length == 0) {
+ document.getElementById(pinkId).innerText = ''
+ hathiTest2.innerText = pinkText
+ coloring()
+ insertImage()
+
+ }
+
+ })
+ })
+
+ }
+
+ })
+
+})
+
+
+
+
+
+
+// Prvents from selecting multiple elements
+z = 0
+document.querySelectorAll('.box').forEach(ee => {
+ ee.addEventListener('click', function () {
+ z = z + 1
+ if (z % 2 == 0 && ee.style.backgroundColor !== 'green') {
+ coloring()
+ }
+ })
+})
\ No newline at end of file
diff --git a/projects/Chess/Screenshot 2023-08-09 200006.png b/projects/Chess/Screenshot 2023-08-09 200006.png
new file mode 100644
index 00000000..c2fa6f4f
Binary files /dev/null and b/projects/Chess/Screenshot 2023-08-09 200006.png differ
diff --git a/projects/Chess/Wbishop.png b/projects/Chess/Wbishop.png
new file mode 100644
index 00000000..ef377220
Binary files /dev/null and b/projects/Chess/Wbishop.png differ
diff --git a/projects/Chess/Wking.png b/projects/Chess/Wking.png
new file mode 100644
index 00000000..7d067221
Binary files /dev/null and b/projects/Chess/Wking.png differ
diff --git a/projects/Chess/Wknight.png b/projects/Chess/Wknight.png
new file mode 100644
index 00000000..8b97b7fb
Binary files /dev/null and b/projects/Chess/Wknight.png differ
diff --git a/projects/Chess/Wpawn.png b/projects/Chess/Wpawn.png
new file mode 100644
index 00000000..eab2a53c
Binary files /dev/null and b/projects/Chess/Wpawn.png differ
diff --git a/projects/Chess/Wqueen.png b/projects/Chess/Wqueen.png
new file mode 100644
index 00000000..2de60cbc
Binary files /dev/null and b/projects/Chess/Wqueen.png differ
diff --git a/projects/Chess/Wrook.png b/projects/Chess/Wrook.png
new file mode 100644
index 00000000..8648b95c
Binary files /dev/null and b/projects/Chess/Wrook.png differ
diff --git a/projects/Chess/index.html b/projects/Chess/index.html
new file mode 100644
index 00000000..3c4b4651
--- /dev/null
+++ b/projects/Chess/index.html
@@ -0,0 +1,116 @@
+
+
+
+
+
+
+
+
+
+