diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f69f75 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bootstrap +font-awesome diff --git a/pig game project/README.md b/pig game project/README.md new file mode 100644 index 0000000..b7d01cb --- /dev/null +++ b/pig game project/README.md @@ -0,0 +1,8 @@ +in this project I use +1- HTML +2- CSS + a. bootstrap + b. font-awesome +3- javascript + +by Abdulwahed talash diff --git a/pig game project/app.js b/pig game project/app.js new file mode 100644 index 0000000..09affd9 --- /dev/null +++ b/pig game project/app.js @@ -0,0 +1,113 @@ + +/* +Game RULES: +- The game has 2 players, playing in rounds +- In each turn, a player rolls a dice as many times as he whishes. Easch esult geet added to his ROUND score +- BUT, if the player rolls a 1, all his ROUND score gets localStorage. After OES_texture_half_float_linear, + it's the next player's turn +- the player can chosse to 'hold', which means thet his ROUND score gets added to his GLBAL score. + After OES_texture_half_float_linear, it's the next player's turn +- the first player to reach 100 points on GLOBAL score wins the game +-two time six come you will lose all your score */ + + // important variable +var score = [0,0] , roundScore = 0 , activePlayer = 0 ,i=0,dice,WinngScore = 100; +const newGame = document.querySelector(".newGame"), + circle0 = document.querySelector("#player0-circle"), + circle1 = document.querySelector("#player1-circle"), + current0 = document.querySelector("#current-0"), + current1 = document.querySelector("#current-1"), + rollDice = document.querySelector("#dice"), + hold = document.querySelector("#hold") + diceImage = document.querySelector(".dice-image"); + + + diceImage.style.display = 'none'; + + // add event listener to ROLL DICE + + rollDice.addEventListener('click',function(){ + // change icon color and reverse + document.querySelector(".fa-refresh").classList.add("reverse"); + // my icon should rotate over and over so i use setTimeout function to remove reverse function + setTimeout(function(){document.querySelector(".fa-refresh").classList.remove("reverse");},1000) + // rondam number + dice = Math.floor(Math.random()*6)+1; + // display the result + diceImage.style.display = 'block'; + // document.querySelector('#score-' + roundScore).textContent = dice; + document.querySelector('.dice-image').src= `img/dice-${dice}.png`; + // Update the round score if the rolled number was not 1 + if (dice !== 1) { + roundScore += dice; + document.querySelector("#current-" + activePlayer).textContent = roundScore; + }else{ + nextPlayer(); + } + // two time six come you will lose all your score + if (activePlayer == 0) { + TwoTimeSix(); + } + else if(activePlayer == 1){ + TwoTimeSix(); + } + }) + + document.querySelector("#hold").addEventListener("click",function(){ + // move current value to global value + score[activePlayer] += roundScore; + document.querySelector("#score-" + activePlayer).textContent = score[activePlayer]; + // change icon color and reverse + // document.querySelector(".fa-download").style.transform = "rotate(180deg)"; + // document.querySelector(".fa-download").style.transition = "transform 1s ease"; + + + // if player won the game + if (score[activePlayer] >= WinngScore) { + document.querySelector('#player-'+activePlayer).innerHTML = "Winner!🥳"; + document.querySelector('#player-'+(activePlayer ==0 ?activePlayer = 1:activePlayer = 0)).innerHTML = "Losser!😔"; + rollDice.disabled ="disabled"; + hold.disabled="disabled"; + circle0.remove("fa-circle"); + circle1.remove("fa-circle"); + diceImage.style.display ="none"; + } + //next player + nextPlayer(); + +}) + +// next player function + +function nextPlayer(){ + roundScore = 0; + document.querySelector("#current-" + activePlayer).textContent = 0; + activePlayer == 0 ? activePlayer = 1 : activePlayer = 0; + circle0.classList.toggle("fa-circle"); + circle1.classList.toggle("fa-circle"); + document.querySelector('.left-div').classList.toggle("active-background"); + document.querySelector('.right-div').classList.toggle("active-background"); +} + +// new game button +newGame.addEventListener('click',function(){ + window.location.reload(); +}) +// two time six function + +function TwoTimeSix(){ + if (dice != 6) { + i =0 + } + else { + ++i; + hold.onclick = function(){i=0} + if (i == 2) { + document.querySelector("#score-" + activePlayer).textContent = 0; + nextPlayer(); + i= 0; + } + setTimeout(function(){i=0},2000); + + } +} diff --git a/pig game project/img/dice-1.png b/pig game project/img/dice-1.png new file mode 100644 index 0000000..0d911ca Binary files /dev/null and b/pig game project/img/dice-1.png differ diff --git a/pig game project/img/dice-2.png b/pig game project/img/dice-2.png new file mode 100644 index 0000000..f3c32af Binary files /dev/null and b/pig game project/img/dice-2.png differ diff --git a/pig game project/img/dice-3.png b/pig game project/img/dice-3.png new file mode 100644 index 0000000..e3ef2b5 Binary files /dev/null and b/pig game project/img/dice-3.png differ diff --git a/pig game project/img/dice-4.png b/pig game project/img/dice-4.png new file mode 100644 index 0000000..0c785f7 Binary files /dev/null and b/pig game project/img/dice-4.png differ diff --git a/pig game project/img/dice-5.png b/pig game project/img/dice-5.png new file mode 100644 index 0000000..b4b41e3 Binary files /dev/null and b/pig game project/img/dice-5.png differ diff --git a/pig game project/img/dice-6.png b/pig game project/img/dice-6.png new file mode 100644 index 0000000..6f4d9b3 Binary files /dev/null and b/pig game project/img/dice-6.png differ diff --git a/pig game project/index.html b/pig game project/index.html new file mode 100644 index 0000000..41c614b --- /dev/null +++ b/pig game project/index.html @@ -0,0 +1,54 @@ + + + + + + + + + + + Pig Game + + +
+
+
+ + +
+
+

PLAYER 1

+ +
+

0

+
+
+

Current

+

0

+
+
+
+

PLAYER 2

+ +
+

0

+
+
+

Current

+

0

+
+
+
+ + +
+ +
+
+ + + + + + diff --git a/pig game project/style.css b/pig game project/style.css new file mode 100644 index 0000000..1e02ea1 --- /dev/null +++ b/pig game project/style.css @@ -0,0 +1,96 @@ +*{ + font-family:'Courier New', Courier, monospace; +} +body{ + background:tan !important; +} +.row{ + width: 80%; + height: 450px; + position: relative; + margin-top: 60px; + margin-left: 100px !important; + +} +.left-div{ + width: 50%; + background-color: rgba(255, 255, 255, 0.5); +} +.right-div{ + width: 50%; + background-color: rgba(255, 255, 255, 0.5); +} +.active-background{ + background-color:#e9ecef; +} +.new-game{ + position: absolute; + margin: 20px 0 0 44%; /* top right bottom left */ + +} +.new-game-span{ + position: absolute; + font-size: 23px !important; + margin-left:-20px !important; + margin-top: 7px !important; + +} +.new-game input{ + font-size: 24px; + word-spacing: -7px; + background: transparent; + border: none; + +} +.roll-dice{ + position: absolute; + margin: 36% 0 0 40%; + font-size: 23px; +} +#dice ,#hold{ + display: block; + margin-bottom: 23px; + background: transparent; + border: none; + outline: none; +} +#hold:hover{ + + margin-top: 2px !important; + /* transition: all 1s ease; */ + float: left; + +} +#hold{ + margin-left: 31px; +} +.reverse{ + transform : rotate(180deg) !important; + transition : transform 1s ease !important; +} +.playerText{ + margin: 80px 0 0 110px; +} +.fa-circle{ + position: absolute; + margin:-33px 0 0 318px; + /* display: none !important; */ +} +.point{ + margin: 0px 0 0 173px; +} +.current{ + width: 100px; + height: 80px; + text-align: center; + margin: 116px 0 0 150px; +} +.current-point{ + font-size: 35px; + margin-top: -20px; +} +.dice-image{ + position: absolute; + width: 90px; + margin: 166px 0 0 390px; +} \ No newline at end of file