From ba71c9cfc2dbb7e730cf06cc79e4ef59900952a7 Mon Sep 17 00:00:00 2001 From: thsh-odoo Date: Tue, 7 Feb 2023 16:17:55 +0530 Subject: [PATCH 1/2] Create a basic simple Rock Paper Scissor game --- task1.css | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ task1.html | 32 ++++++++++++++++++ task1.js | 69 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 task1.css create mode 100644 task1.html create mode 100644 task1.js diff --git a/task1.css b/task1.css new file mode 100644 index 0000000..1923b07 --- /dev/null +++ b/task1.css @@ -0,0 +1,96 @@ +*, +*:Before, +*:After{ + Padding: 0; + Margin: 0; + Box-Sizing: Border-Box; +} +Body{ + Height: 100vh; + Background: Linear-Gradient( + 135deg, + #1bcaff, + #231bff + ); +} +.Container{ + Width: 45%; + Min-Width: 500px; + Background-Color: #Ffffff; + Padding: 40px 30px; + Position: Absolute; + Transform: Translate(-50%,-50%); + Top: 50%; + Left: 50%; + Border-Radius: 10px; + Box-Shadow: 0 15px 25px Rgba(0,0,0,0.15); +} +.Scores{ + Margin-Bottom: 50px; + Text-Align: Right; +} +.Details{ + Margin-Top: 30px; + Text-Align: Center; +} +.Scores,.Details{ + Font-Family: 'Poppins',Sans-Serif; + Font-Weight: 400; + Font-Size: 15px; +} + +#User_choice, +#Computer_choice{ + Font-Weight: 400; + Margin-Bottom: 10px; +} +Span{ + Font-Weight: 600; +} + + + + +.btn { + border: 2px solid black; + background-color: white; + color: black; + padding: 14px 28px; + font-size: 16px; + cursor: pointer; + } + + .success { + border-color: #04AA6D; + color: green; + } + + .success:hover { + background-color: #04AA6D; + color: white; + } + /* Orange */ + .warning { + border-color: #ff9800; + color: orange; + } + + .warning:hover { + background: #ff9800; + color: white; + } + + /* Red */ + .danger { + border-color: #f44336; + color: red; + } + + .danger:hover { + background: #f44336; + color: white; + } + .center { + text-align: center; + padding: 10px; + } \ No newline at end of file diff --git a/task1.html b/task1.html new file mode 100644 index 0000000..fbf162c --- /dev/null +++ b/task1.html @@ -0,0 +1,32 @@ + + + + Rock Paper Scissor Game + + + + +
+

Rock Paper & Scissor Game

+
+

Computer : + 0 +

+

+ You : + 0 +

+
+
+

+
+
+ + + +
+
+ + + + \ No newline at end of file diff --git a/task1.js b/task1.js new file mode 100644 index 0000000..203bbca --- /dev/null +++ b/task1.js @@ -0,0 +1,69 @@ +const choices=['Rock','Paper','Scissor']; +var user_scores=0,computer_score=0; +function rock() +{ + let computer_choice=Math.floor(Math.random() * choices.length); + console.log(choices[computer_choice]) + + if(choices[computer_choice]=='Rock') + { + // console.log("helllllllo") + document.getElementById("status").textContent="Draw"; + } + else if (choices[computer_choice]=='Paper') + { + document.getElementById("status").textContent="Computer Wins"; + computer_score+=1; + document.getElementById("computer_score").textContent=computer_score; + console.log(computer_score) + } + else if(choices[computer_choice]=='Scissor') + { + document.getElementById("status").textContent="You Win"; + user_scores+=1; + document.getElementById("user_scores").textContent=user_scores; + console.log(user_scores) + } +} +function paper() +{ + let computer_choice=Math.floor(Math.random() * choices.length); + console.log(choices[computer_choice]) + if(choices[computer_choice]=='Paper') + { + document.getElementById("status").textContent="Draw"; + } + else if (choices[computer_choice]=='Scissor') + { + document.getElementById("status").textContent="Computer Wins"; + computer_score+=1; + document.getElementById("computer_score").textContent=computer_score; + } + else if(choices[computer_choice]=='Rock') + { + document.getElementById("status").textContent="You Win"; + user_scores+=1; + document.getElementById("user_scores").textContent=user_scores; + } +} +function scissor() +{ + let computer_choice=Math.floor(Math.random() * choices.length); + console.log(choices[computer_choice]) + if(choices[computer_choice]=='Scissor') + { + document.getElementById("status").textContent="Draw"; + } + else if (choices[computer_choice]=='Rock') + { + document.getElementById("status").textContent="Computer Wins"; + computer_score+=1; + document.getElementById("computer_score").textContent=computer_score; + } + else if(choices[computer_choice]=='Paper') + { + document.getElementById("status").textContent="You Win"; + user_scores+=1; + document.getElementById("user_scores").textContent=user_scores; + } +} From a7be74ac3c7b87e8ff68c568e0166375705e284c Mon Sep 17 00:00:00 2001 From: thsh-odoo Date: Mon, 13 Feb 2023 10:38:05 +0530 Subject: [PATCH 2/2] Optimize the code with less no of line and created a single function to perform the task --- .vscode/launch.json | 14 ++++ .../task1.css | 0 .../task1.html | 6 +- Rock Paper & Scissor Game/task1.js | 24 +++++++ task1.js | 69 ------------------- 5 files changed, 41 insertions(+), 72 deletions(-) create mode 100644 .vscode/launch.json rename task1.css => Rock Paper & Scissor Game/task1.css (100%) rename task1.html => Rock Paper & Scissor Game/task1.html (74%) create mode 100644 Rock Paper & Scissor Game/task1.js delete mode 100644 task1.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..694587b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Open currency_converter.html", + "file": "/home/odoo/odoo/Javascript-training/Currency Converter/currency_converter.html" + } + ] +} \ No newline at end of file diff --git a/task1.css b/Rock Paper & Scissor Game/task1.css similarity index 100% rename from task1.css rename to Rock Paper & Scissor Game/task1.css diff --git a/task1.html b/Rock Paper & Scissor Game/task1.html similarity index 74% rename from task1.html rename to Rock Paper & Scissor Game/task1.html index fbf162c..dfb6ae6 100644 --- a/task1.html +++ b/Rock Paper & Scissor Game/task1.html @@ -21,9 +21,9 @@

Rock Paper & Scissor Game

- - - + + +
diff --git a/Rock Paper & Scissor Game/task1.js b/Rock Paper & Scissor Game/task1.js new file mode 100644 index 0000000..be8619b --- /dev/null +++ b/Rock Paper & Scissor Game/task1.js @@ -0,0 +1,24 @@ +const choices = ['Rock','Paper','Scissor']; +var user_scores = 0,computer_score = 0; +function playgame(a) +{ + const choices=['Rock','Paper','Scissor']; + let user_choice=choices[a]; + let computer_choice=Math.floor(Math.random() * choices.length); + if(choices[computer_choice]=='Rock' && user_choice=="Rock" || choices[computer_choice]=='Paper' && user_choice=="Paper" || choices[computer_choice]=='Scissor' && user_choice=="Scissor" ) + { + document.getElementById("status").textContent="Draw"; + } + else if (choices[computer_choice]=='Paper' && user_choice=="Rock" || choices[computer_choice]=='Rock' && user_choice=="Scissor" || choices[computer_choice]=='Scissor' && user_choice=="Paper") + { + document.getElementById('status').textContent="Computer Wins"; + computer_score += 1; + document.getElementById('computer_score').textContent=computer_score; + } + else + { + document.getElementById("status").textContent="You Win"; + user_scores +=1; + document.getElementById('user_scores').textContent=user_scores; + } +} \ No newline at end of file diff --git a/task1.js b/task1.js deleted file mode 100644 index 203bbca..0000000 --- a/task1.js +++ /dev/null @@ -1,69 +0,0 @@ -const choices=['Rock','Paper','Scissor']; -var user_scores=0,computer_score=0; -function rock() -{ - let computer_choice=Math.floor(Math.random() * choices.length); - console.log(choices[computer_choice]) - - if(choices[computer_choice]=='Rock') - { - // console.log("helllllllo") - document.getElementById("status").textContent="Draw"; - } - else if (choices[computer_choice]=='Paper') - { - document.getElementById("status").textContent="Computer Wins"; - computer_score+=1; - document.getElementById("computer_score").textContent=computer_score; - console.log(computer_score) - } - else if(choices[computer_choice]=='Scissor') - { - document.getElementById("status").textContent="You Win"; - user_scores+=1; - document.getElementById("user_scores").textContent=user_scores; - console.log(user_scores) - } -} -function paper() -{ - let computer_choice=Math.floor(Math.random() * choices.length); - console.log(choices[computer_choice]) - if(choices[computer_choice]=='Paper') - { - document.getElementById("status").textContent="Draw"; - } - else if (choices[computer_choice]=='Scissor') - { - document.getElementById("status").textContent="Computer Wins"; - computer_score+=1; - document.getElementById("computer_score").textContent=computer_score; - } - else if(choices[computer_choice]=='Rock') - { - document.getElementById("status").textContent="You Win"; - user_scores+=1; - document.getElementById("user_scores").textContent=user_scores; - } -} -function scissor() -{ - let computer_choice=Math.floor(Math.random() * choices.length); - console.log(choices[computer_choice]) - if(choices[computer_choice]=='Scissor') - { - document.getElementById("status").textContent="Draw"; - } - else if (choices[computer_choice]=='Rock') - { - document.getElementById("status").textContent="Computer Wins"; - computer_score+=1; - document.getElementById("computer_score").textContent=computer_score; - } - else if(choices[computer_choice]=='Paper') - { - document.getElementById("status").textContent="You Win"; - user_scores+=1; - document.getElementById("user_scores").textContent=user_scores; - } -}