diff --git a/Game/Rock_Paper_Scissors/index.html b/Game/Rock_Paper_Scissors/index.html new file mode 100644 index 00000000..2998dc9b --- /dev/null +++ b/Game/Rock_Paper_Scissors/index.html @@ -0,0 +1,21 @@ + + + + + + Document + + + +
+

Challenge 3: Rock, Paper, Scissors

+
+ + + +
+ +
+ + + \ No newline at end of file diff --git a/Game/Rock_Paper_Scissors/paper.jpg b/Game/Rock_Paper_Scissors/paper.jpg new file mode 100644 index 00000000..22d9fd3c Binary files /dev/null and b/Game/Rock_Paper_Scissors/paper.jpg differ diff --git a/Game/Rock_Paper_Scissors/rock.png b/Game/Rock_Paper_Scissors/rock.png new file mode 100644 index 00000000..43ad1d86 Binary files /dev/null and b/Game/Rock_Paper_Scissors/rock.png differ diff --git a/Game/Rock_Paper_Scissors/scissors.png b/Game/Rock_Paper_Scissors/scissors.png new file mode 100644 index 00000000..3936fd2b Binary files /dev/null and b/Game/Rock_Paper_Scissors/scissors.png differ diff --git a/Game/Rock_Paper_Scissors/script.js b/Game/Rock_Paper_Scissors/script.js new file mode 100644 index 00000000..5750dfee --- /dev/null +++ b/Game/Rock_Paper_Scissors/script.js @@ -0,0 +1,73 @@ +function rps_game(yourchoice){ + console.log(yourchoice); + var humanChoice, botChoice; + humanChoice = yourchoice.id; + botChoice = numberToChoice(randToRpsInt()); + console.log(botChoice); + var results = decidewinner(humanChoice,botChoice); + console.log(results); + var message = finalmessage(results); + console.log(message); + frontend(yourchoice.id,botChoice,message); + +} + +function randToRpsInt(){ + return Math.floor(Math.random() * 3); +} + +function numberToChoice(number){ + return ['rock','paper','scissors'][number]; +} + +function decidewinner(humanChoice,botChoice){ + var rpsdatabase = { + 'rock':{'scissors':1 , 'rock':0.5, 'paper':0}, + 'paper':{'rock':1 , 'paper':0.5, 'scissors':0}, + 'scissors':{'paper':1 , 'scissors':0.5, 'rock':0} + }; + + var yourscore = rpsdatabase[humanChoice][botChoice]; + var botscore = rpsdatabase[botChoice][humanChoice]; + + return [yourscore,botscore]; +} + +function finalmessage([yourscore,botscore]){ + if(yourscore === 0){ + return {'message':'You Lost!!','color':'red'}; + } + else if(yourscore === 0.5){ + return {'message':'You tied!!','color':'yellow'}; + } + else { + return {'message':'You Won!!','color':'green'}; + } +} + +function frontend(humanImageChoice,botImageChoice,finalmessage){ + var imagesdatabase = { + 'rock': document.getElementById('rock').src, + 'paper': document.getElementById('paper').src, + 'scissors': document.getElementById('scissors').src + } + + document.getElementById('rock').remove(); + document.getElementById('paper').remove(); + document.getElementById('scissors').remove(); + + var humanDiv = document.createElement('div'); + var botDiv = document.createElement('div'); + var messageDiv = document.createElement('div'); + + humanDiv.innerHTML = ""; + document.getElementById('flex-box-rps-div').appendChild(humanDiv); + + messageDiv.innerHTML = "

"+ finalmessage['message'] +"

" + document.getElementById('flex-box-rps-div').appendChild(messageDiv); + + botDiv.innerHTML = " "; + document.getElementById('flex-box-rps-div').appendChild(botDiv); + + +} diff --git a/Game/Rock_Paper_Scissors/style.css b/Game/Rock_Paper_Scissors/style.css new file mode 100644 index 00000000..16bd7ecd --- /dev/null +++ b/Game/Rock_Paper_Scissors/style.css @@ -0,0 +1,23 @@ +body{ + background-color: lightgray ; +} + +.container{ + border: 1px solid black; + width: 75%; + margin: 0 auto; + text-align: center; +} + +.flex-box-rps{ + display: flex; + padding: 10px; + flex-wrap: wrap; + border: 1px solid black; + flex-direction: row; + justify-content: space-around; +} + +.flex-box-rps img:hover{ + box-shadow: 0px 10px 50px rgba(37, 50, 233, 1); +} \ No newline at end of file