diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..3b4f9e6 --- /dev/null +++ b/css/style.css @@ -0,0 +1,69 @@ +body{ + background-color:#601155; + display: flex; + flex-direction: row; + height: 100vh; + padding: 0px; + margin: 0px; + color: white; + font-family: 'Chilanka', cursive; + } + .container{ + text-align: center; + display: flex; + flex-direction: column; + width: 75%; + padding: 30px; + } + .score{ + display: flex; + flex-direction: row; + justify-content: space-around; + align-items: center; + min-height: 150px; + font-size: 40px; + + } + .score div{ + min-width: 20%; + } + .arena{ + display: flex; + flex-direction: row; + justify-content: space-around; + align-items: center; + min-height: 450px; + font-weight: bold; + font-size: 50px; + } + .arena img{ + width: 350px; + } + + #rounds{ + background-color: #c8e615; + width: 18%; + height: 100%; + border-right: 20px dashed #601155; + padding: 50px 20px 10px 40px; + color: #601155; + } + #player, #computer{ + border: 4px solid #c8e615; + font-size: 30px; + padding: 20px 20px 10px 20px; + } + + button{ + background-color: transparent; + border: none; + cursor: pointer; + } + i{ + color: #c8e615; + margin: 5px 40px; + } + a{ + color: #c8e615; + font-size: 26px; + } diff --git a/game.js b/game.js index 3d7e01b..2bacd0e 100644 --- a/game.js +++ b/game.js @@ -1,3 +1,74 @@ -// Write all your code here -// Replace the contents of this file with your own code -console.log('Hello, world!'); +const choices = ['rock', 'paper', 'scissors']; + +function computerPlay() { + return choices[Math.floor(Math.random() * choices.length)]; +} + +function userPlay(playAgain){ + let msg = (playAgain) ? "Invalid input ...\n please chose one of : rock, paper or scissors":"Lets Play ...\n chose one of : rock, paper or scissors"; + let player = prompt(msg); + //check if player submited a good value, if yes return player input or prompt again + return (!choices.includes(player.toLowerCase())) ? userPlay(1): player.toLowerCase(); +} + +function playRound() { + let player = userPlay(); + let computer = computerPlay(); + let result = ""; + + if(player === computer){ + return "Deaw..!! Play again"; + } + + + let computerWin = "COMPUTER WIN :|"; + let playerWin = "YOU WIN :)"; + + if(player === "rock"){ + result = (computer === "scissors")? playerWin:computerWin; + }else if(player === "scissors"){ + result = (computer === "rock")? computerWin:playerWin; + }else if(player === "paper"){ + result = (computer === "rock")? playerWin:computerWin; + } + + let winer = (result === computer)? computer:player; + let loser = (result === computer)? player:computer; + + result = `${result} \n ${winer} beats ${loser}`; + return result; +} + +function game(rounds = 5){ + let report = { + rounds:[], + score:[] + }; + + report.score['player'] = 0; + report.score['computer'] = 0; + + let i = 0; + while(i < rounds){ + let round = playRound(); + console.log(round); + //add this round to the report + report.rounds.push(round); + + if(round !== "Deaw..!! Play again"){ + if(round.includes("YOU WIN")){ + report.score['player'] = report.score['player'] + 1; + }else{ + report.score['computer'] = report.score['computer'] + 1; + } + i++; + } + + } + report.finalResult = (report.score['computer'] > report.score['player'])? `Computer win ${report.score['computer']} of ${rounds}`:`You win ${report.score['player']} of ${rounds}`; + return report; + //this will return an pbject ,, includes the result of each game, and the score for both player and computer, and final result (who win) +} + + +console.log(game()); diff --git a/images/paper.png b/images/paper.png new file mode 100644 index 0000000..aaf25b1 Binary files /dev/null and b/images/paper.png differ diff --git a/images/rock.png b/images/rock.png new file mode 100644 index 0000000..b46e59a Binary files /dev/null and b/images/rock.png differ diff --git a/images/scissors.png b/images/scissors.png new file mode 100644 index 0000000..418b002 Binary files /dev/null and b/images/scissors.png differ diff --git a/index.html b/index.html index 947177f..f3f65c4 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,60 @@
+