Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Gaming Website DebugIt'22 #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Color-Picker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Color Picker Game</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="yellow">
<div class="homepage">
<a href="../gaming.html">
<button class="homebutton">Home Page</button>
</a>
</div>
<h1 id="head">THE GREAT</h1>
<h1 id="rgb">
rgb(<em id="r">r</em>,<em id="g">g</em>,<em id="b">b</em>)
</h1>
<h1 id="colorgame">COLOR GAME</h1>
</div>
<div id="white">
<button id="newcolor" onclick="rgb()">NEW COLORS</button><br />
<button id="tryagain">Click NEW COLORS to begin</button><br />
<button id="easy" onclick="easy()">EASY</button>
<button id="hard" onclick="hard()">HARD</button>
</div>
<div id="boxes">
<button id="c1" onclick="colorChoice1()"></button>
<button id="c2" onclick="colorChoice2()"></button>
<button id="c3" onclick="colorChoice3()"></button>
<br />
<button id="c4" onclick="colorChoice4()"></button>
<button id="c5" onclick="colorChoice5()"></button>
<button id="c6" onclick="colorChoice6()"></button>
</div>
<script src="script.js"></script>
</body>
</html>
154 changes: 154 additions & 0 deletions Color-Picker/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
let correctAnswer, random_r, random_g, random_b, value;
let color1 = document.getElementById("c1");
let color2 = document.getElementById("c2");
let color3 = document.getElementById("c3");
let color4 = document.getElementById("c4");
let color5 = document.getElementById("c5");
let color6 = document.getElementById("c6");
disableAllColouredButtons();
// easy button
function easy() {
enableAllColouredButtons();
color4.style.visibility = "hidden";
color5.style.visibility = "hidden";
color6.style.visibility = "hidden";
correctAnswer = Math.floor(Math.random() * 3 + 1);
document.getElementById("yellow").style.background = "rgb(231, 198, 9)";
document.getElementById("tryagain").style.visibility = "hidden";
random_r = Math.floor(Math.random() * 256);
random_g = Math.floor(Math.random() * 256);
random_b = Math.floor(Math.random() * 256);
document.getElementById("r").innerHTML = random_r;
document.getElementById("g").innerHTML = random_g;
document.getElementById("b").innerHTML = random_b;
assignColors();
}
// hard button
function hard() {
enableAllColouredButtons();
correctAnswer = Math.floor(Math.random() * 6 + 1);
document.getElementById("yellow").style.background = "rgb(231, 198, 9)";
document.getElementById("tryagain").style.visibility = "hidden";
random_r = Math.floor(Math.random() * 256);
random_g = Math.floor(Math.random() * 256);
random_b = Math.floor(Math.random() * 256);
document.getElementById("r").innerHTML = random_r;
document.getElementById("g").innerHTML = random_g;
document.getElementById("b").innerHTML = random_b;
assignColors();
}
// set new colors
function rgb() {
enableAllColouredButtons();
document.getElementById("yellow").style.background = "rgb(231, 198, 9)";
document.getElementById("tryagain").style.visibility = "hidden";
random_r = Math.floor(Math.random() * 256);
random_g = Math.floor(Math.random() * 256);
random_b = Math.floor(Math.random() * 256);
document.getElementById("r").innerHTML = random_r;
document.getElementById("g").innerHTML = random_g;
document.getElementById("b").innerHTML = random_b;
if (color5.style.visibility == "hidden") value = 3;
else value = 6;
correctAnswer = Math.floor(Math.random() * value + 1);
assignColors();
}
// button-handelling
function colorChoice1() {
if (correctAnswer == 1) {
winningScenario();
} else {
color1.style.visibility = "hidden";
losingScenario();
}
}
function colorChoice2() {
if (correctAnswer == 2) {
winningScenario();
} else {
color2.style.visibility = "hidden";
losingScenario();
}
}
function colorChoice3() {
if (correctAnswer == 3) {
winningScenario();
} else {
color3.style.visibility = "hidden";
losingScenario();
}
}
function colorChoice4() {
if (correctAnswer == 4) {
winningScenario();
} else {
color4.style.visibility = "hidden";
losingScenario();
}
}
function colorChoice5() {
if (correctAnswer == 5) {
winningScenario();
} else {
color5.style.visibility = "hidden";
losingScenario();
}
}
function colorChoice6() {
if (correctAnswer == 6) {
winningScenario();
} else {
color6.style.visibility = "hidden";
losingScenario();
}
}
function enableAllColouredButtons() {
const colors = [color1, color2, color3, color4, color5, color6];
for (let i = 1; i <= 6; i++) {
colors[i - 1].disabled = false;
colors[i - 1].style.visibility = "visible";
}
}
function disableAllColouredButtons() {
const colors = [color1, color2, color3, color4, color5, color6];
for (let i = 1; i <= 6; i++) {
colors[i - 1].disabled = true;
}
}
function winningScenario() {
const colors = [color1, color2, color3, color4, color5, color6];
for (let i = 1; i <= 6; i++) {
colors[i - 1].style.background =
"rgb(" + random_r + "," + random_g + "," + random_b + ")";
colors[i - 1].style.visibility = "visible";
}
document.getElementById("yellow").style.background =
"rgb(" + random_r + "," + random_g + "," + random_b + ")";
document.getElementById("tryagain").style.visibility = "visible";
document.getElementById("tryagain").innerHTML = "Correct!!";
document.getElementById("newcolor").innerHTML = "PLAY AGAIN";
disableAllColouredButtons();
}
function losingScenario() {
document.getElementById("tryagain").style.visibility = "visible";
document.getElementById("tryagain").innerHTML = "Try again";
}
// generate random colors
function generateRandomColor() {
let colors = [];
for (let i = 1; i <= 3; i++) {
colors.push(Math.floor(Math.random() * 256));
}
return "rgb(" + colors[0] + "," + colors[1] + "," + colors[2] + ")";
}
function assignColors() {
const colors = [color1, color2, color3, color4, color5, color6];
for (let i = 1; i <= 6; i++) {
if (correctAnswer == i) {
colors[i - 1].style.background =
"rgb(" + random_r + "," + random_g + "," + random_b + ")";
} else {
colors[i - 1].style.background = generateRandomColor();
}
}
}
Loading