diff --git a/netizen/rickyzakariap/assets/batu.png b/netizen/rickyzakariap/assets/batu.png new file mode 100644 index 0000000..bd3b701 Binary files /dev/null and b/netizen/rickyzakariap/assets/batu.png differ diff --git a/netizen/rickyzakariap/assets/gunting.png b/netizen/rickyzakariap/assets/gunting.png new file mode 100644 index 0000000..b30077b Binary files /dev/null and b/netizen/rickyzakariap/assets/gunting.png differ diff --git a/netizen/rickyzakariap/assets/kertas.png b/netizen/rickyzakariap/assets/kertas.png new file mode 100644 index 0000000..9050fd8 Binary files /dev/null and b/netizen/rickyzakariap/assets/kertas.png differ diff --git a/netizen/rickyzakariap/assets/logo.png b/netizen/rickyzakariap/assets/logo.png new file mode 100644 index 0000000..b7fccb0 Binary files /dev/null and b/netizen/rickyzakariap/assets/logo.png differ diff --git a/netizen/rickyzakariap/assets/refresh.png b/netizen/rickyzakariap/assets/refresh.png new file mode 100644 index 0000000..220dab9 Binary files /dev/null and b/netizen/rickyzakariap/assets/refresh.png differ diff --git a/netizen/rickyzakariap/game.js b/netizen/rickyzakariap/game.js new file mode 100644 index 0000000..4fa7c96 --- /dev/null +++ b/netizen/rickyzakariap/game.js @@ -0,0 +1,147 @@ +// Menangkap pilihan dari komputer +function getcompuChoice() { + const compu = Math.random(); + if (compu < 1 / 3) return 'rock'; + if (compu >= 1 / 3 && compu < 2 / 3) return 'paper'; + return 'scissor'; +} + +// Rules permainan +let result = null; +function getResult(compu, player) { + if (player == compu) return (result = 'DRAW'); + if (player == 'rock') return compu == 'scissor' ? (result = 'PLAYER 1 WIN') : (result = 'COM WIN'); + if (player == 'paper') return compu == 'rock' ? (result = 'PLAYER 1 WIN') : (result = 'COM WIN'); + if (player == 'scissor') return compu == 'paper' ? (result = 'PLAYER 1 WIN') : (result = 'COM WIN'); +} + +/* Game dimulai */ +/* DOM Selector */ +const versus = document.querySelector('.versus h1'); +const resultClass = document.querySelector('.versus div div'); +const textResult = document.querySelector('.versus h5'); +const compuBox = document.querySelectorAll('.greyBox.compuImage'); +const playerBox = document.querySelectorAll('.greyBox.playerImage'); + +/* Beri delay untuk membuat komputer seolah berpikir dahulu */ + +function wait() { + const start = new Date().getTime(); + let i = 0; + + setInterval(function () { + /* Jalankan fungsi dalam waktu 1s */ + if (new Date().getTime() - start >= 1000) { + clearInterval; + return; + } + + /* Komputer seolah-olah berpikir dengan bantuan greyBox */ + compuBox[i++].style.backgroundColor = '#c4c4c4'; + if (i == compuBox.length) i = 0; + + /* Hilangkan kembali class result saat wait () */ + resultClass.classList.remove('result'); + + /* Tampilkan kembali tulisan VS saat wait () */ + versus.style.color = 'rgb(189,48,46)'; + }, 50); + + setTimeout(function () { + setInterval(function () { + if (new Date().getTime() - start >= 1200) { + clearInterval; + return; + } + + /* Handling agar Menyamarkan greyBox dengan bgColor supaya tidak semuanya memiliki greyBox berwarna abu */ + compuBox[i++].style.backgroundColor = '#9c835f'; + if (i == compuBox.length) i = 0; + }, 50); + }, 50); +} + +/* Menangkap pilihan pemain */ +const player = document.querySelectorAll('.contentImage .player'); +player.forEach(function (choice) { + choice.addEventListener('click', function () { + /* Samarkan seluruh greyBox pada sisi player saat game dijalankan */ + for (let i = 0; i < playerBox.length; i++) { + playerBox[i].style.backgroundColor = '#9c835f'; + } + + /* Eventlistener hanya dikerjakan apabila result masih dalam kondisi null */ + if (result === null) { + /* Tangkap pilihan komputer */ + const compuChoice = getcompuChoice(); + + /* Tangkap pilihan pemain */ + const playerChoice = choice.className.substr(7, 7); + + /* Jalankan Rules permainan untuk mendapatkan hasil */ + result = getResult(compuChoice, playerChoice); + + /* Berikan greyBox pada pilihan pemain */ + if (playerChoice == 'rock') { + playerBox[0].style.backgroundColor = '#c4c4c4'; + } else if (playerChoice == 'paper') { + playerBox[1].style.backgroundColor = '#c4c4c4'; + } else { + playerBox[2].style.backgroundColor = '#c4c4c4'; + } + + /* Jalankan fungsi wait agar komputer terlihat berpikir dahulu */ + wait(); + + /* Jalankan seluruh perintah dibawah setelah fungsi wait selesai dijalankan */ + setTimeout(function () { + /* Samarkan tulisan VS dengan background saat hasil ditampilkan */ + versus.style.color = '#9c835f'; + + /* Tampilkan class result */ + resultClass.classList.add('result'); + + /* Tampilkan hasil dalam class result (kotak hijau) */ + textResult.innerHTML = result; + if (result == 'DRAW') { + textResult.style.backgroundColor = '#225c0e'; + } else { + textResult.style.backgroundColor = '#4c9654'; + } + + /* Berikan greyBox pada compu choice */ + if (compuChoice == 'rock') { + compuBox[0].style.backgroundColor = '#c4c4c4'; + } else if (compuChoice == 'paper') { + compuBox[1].style.backgroundColor = '#c4c4c4'; + } else { + compuBox[2].style.backgroundColor = '#c4c4c4'; + } + }, 1200); + } else { + alert('Click Refresh Button'); + } + }); +}); + +/* Reset tampilan game dengan tombol refresh */ +const reset = document.querySelector('.refresh'); +reset.addEventListener('click', function () { + /* Hapus tulisan hasil dalam result */ + textResult.innerHTML = ''; + + /* Hilangkan kembali class result */ + resultClass.classList.remove('result'); + + /* Hilangkan kembali seluruh greyBox */ + for (let i = 0; i < compuBox.length; i++) { + playerBox[i].style.backgroundColor = '#9c835f'; + compuBox[i].style.backgroundColor = '#9c835f'; + } + + /* Tampilkan kembali tulisan VS */ + versus.style.color = 'rgb(189,48,46)'; + + /* Reset kembali result menjadi null agar dapat melakukan permainan kembali */ + result = null; +}); diff --git a/netizen/rickyzakariap/index.html b/netizen/rickyzakariap/index.html new file mode 100644 index 0000000..a26fdbc --- /dev/null +++ b/netizen/rickyzakariap/index.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + Tu-Tas-Ting! | Traditional Games + + + + + + + + +
+
+
+
+

Player 1

+
+
+

Com

+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+

VS

+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + + + + + + + + + diff --git a/netizen/rickyzakariap/style.css b/netizen/rickyzakariap/style.css new file mode 100644 index 0000000..abca1f4 --- /dev/null +++ b/netizen/rickyzakariap/style.css @@ -0,0 +1,104 @@ +body, +html { + scroll-behavior: smooth; + text-decoration: none !important; + font-family: 'Open Sans', sans-serif; +} + +.customHeader div .d-inline-block { + line-height: 2; +} + +.customHeader a .headerTitle { + font-size: 16px; + font-weight: bold; + text-transform: uppercase; + color: #ffc107; +} + +.bgColor { + height: 100%; + position: absolute; + z-index: -1; + top: 0; + background-color: #9c835f; +} + +.gameContent { + position: relative; + top: 100px; + text-align: center; +} + +.gameContent .row div h3 { + text-transform: uppercase; + font-weight: bold; + font-size: 20px; +} + +.gameContent .row.contentImage .col-4 { + height: 75px; +} + +.gameContent .row.contentImage img { + width: 40px; + height: 40px; + cursor: pointer; +} + +.gameContent .row div.greyBox { + border-radius: 15%; +} + +.gameContent .refresh { + width: 50px; + height: 50px; + cursor: pointer; +} + +.gameContent .row.contentImage .versus { + position: relative; + z-index: 1; + display: table-cell; + vertical-align: middle; + width: 100px; + height: 100px; +} + +.gameContent .row.contentImage .versus h1 { + font-weight: bold; + font-size: 40px; + color: #bd302f; +} + +.gameContent .row.contentImage .versus .result { + position: absolute; + top: 0; + left: 0; + z-index: 1; + transform: rotate(-30deg); + margin-left: -30px; +} + +.gameContent .row.contentImage .versus .result h5 { + display: table-cell; + vertical-align: middle; + background-color: #4c9654; + border-radius: 5%; + font-size: 14px; + font-weight: bold; + letter-spacing: 2px; + color: #ffffff; + height: 55px; + padding: 10px 40px; +} + +.contentImage :hover img { + -webkit-transform: scale(1.6); + transform: scale(1.6); +} + +.my-2 :hover img { + -webkit-transform: scale(1.3); + transform: scale(1.3); +}