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

Dice game #3204

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions Games/Dice-toss/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# DIceGame.github.io
33 changes: 33 additions & 0 deletions Games/Dice-toss/dicee.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Dicee</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css?family=Indie+Flower|Lobster" rel="stylesheet">

</head>
<body>


<div class="container">
<h1>Refresh Me</h1>

<div class="dice">
<p>Player 1</p>
<img id="img1" src="images/dice2.png">
</div>

<div class="dice">
<p>Player 2</p>
<img id="img2" src="images/dice6.png">
</div>

</div>
<script src="index.js"></script>
</body>




</html>
Binary file added Games/Dice-toss/images/dice1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Dice-toss/images/dice2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Dice-toss/images/dice3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Dice-toss/images/dice4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Dice-toss/images/dice5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Dice-toss/images/dice6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions Games/Dice-toss/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var randomnum1=Math.floor(Math.random()*6+1);

var randomnum2=Math.floor(Math.random()*6+1);

// For first dice(left)
if(randomnum1==1){
document.getElementById("img1").setAttribute('src','images/dice1.png');
}
else if(randomnum1==2){
document.getElementById("img1").setAttribute('src','images/dice2.png');
}
else if(randomnum1==3){
document.getElementById("img1").setAttribute('src','images/dice3.png');
}
else if(randomnum1==4){
document.getElementById("img1").setAttribute('src','images/dice4.png');
}
else if(randomnum1==5){
document.getElementById("img1").setAttribute('src','images/dice5.png');
}
else if(randomnum1==6){
document.getElementById("img1").setAttribute('src','images/dice6.png');
}



// For second dice (right)
if(randomnum2==1){
document.getElementById("img2").setAttribute('src','images/dice1.png');
}
else if(randomnum2==2){
document.getElementById("img2").setAttribute('src','images/dice2.png');
}
else if(randomnum2==3){
document.getElementById("img2").setAttribute('src','images/dice3.png');
}
else if(randomnum2==4){
document.getElementById("img2").setAttribute('src','images/dice4.png');
}
else if(randomnum2==5){
document.getElementById("img2").setAttribute('src','images/dice5.png');
}
else if(randomnum2==6){
document.getElementById("img2").setAttribute('src','images/dice6.png');
}

if(randomnum1>randomnum2){
document.querySelector("h1").innerHTML="Player1 wins!!";
}
else if(randomnum2>randomnum1){
document.querySelector("h1").innerHTML="Player2 wins!!";
}
else{
document.querySelector("h1").innerHTML="It's a Draw!.....try again";

}
41 changes: 41 additions & 0 deletions Games/Dice-toss/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.container {
width: 70%;
margin: auto;
text-align: center;
}

.dice {
text-align: center;
display: inline-block;

}

body {
background-color: #393E46;
}

h1 {
margin: 30px;
font-family: 'Lobster', cursive;
text-shadow: 5px 0 #232931;
font-size: 8rem;
color: #4ECCA3;
}

p {
font-size: 2rem;
color: #4ECCA3;
font-family: 'Indie Flower', cursive;
}

img {
width: 80%;
}

footer {
margin-top: 5%;
color: #EEEEEE;
text-align: center;
font-family: 'Indie Flower', cursive;

}
38 changes: 38 additions & 0 deletions Games/Membox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# **Membox**

---

<br>

## **Description 📃**
- Game logic and basic description: MemBox is a memory based fun game with infinite levels each getting tougher ever level.
It has 4 boxes all different colors.
level 1: 1 box will glow for a sec and u need to click on it.
level 2 : now 2 boxes will glow and u need to remember the order and click it;
level 3 : now 3 boxes and so on.
Your duty is to remember the pattern of that glow and click it in the same order.
The game doesn't have end its just about when your memory power gives up.
**Test Your Memory Power**

## **functionalities 🎮**
- level 1: 1 box will glow for a sec and u need to click on it.
level 2 : now 2 boxes will glow and u need to remember the order and click it;
level 3 : now 3 boxes and so on.
<br>

## **How to play? 🕹️**
- Click any button to start
- Try to remember the sequence
- click that sequence in order and you will find yourself in next level
- Happy Playing😉!!

<br>

## **Screenshots 📸**
![image](../../assets/images/Membox.png)
<br>

<br>

## **Working video 📹**
<!-- add your working video over here -->
94 changes: 94 additions & 0 deletions Games/Membox/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

var buttonColours = ["red", "blue", "green", "yellow"];

var gamePattern = [];
var userClickedPattern = [];

var started = false;
var level = 0;

$(document).keypress(function() {
if (!started) {
$("#level-title").text("Level " + level);
nextSequence();
started = true;
}
});

$(".btn").click(function() {

var userChosenColour = $(this).attr("id");
userClickedPattern.push(userChosenColour);

playSound(userChosenColour);
animatePress(userChosenColour);

checkAnswer(userClickedPattern.length-1);
});


function checkAnswer(currentLevel) {

if (gamePattern[currentLevel] === userClickedPattern[currentLevel]) {

console.log("success");

if (userClickedPattern.length === gamePattern.length){
setTimeout(function () {
nextSequence();
}, 1000);
}

} else {

console.log("wrong");

playSound("wrong");

$("body").addClass("game-over");
setTimeout(function () {
$("body").removeClass("game-over");
}, 200);

$("#level-title").text("Game Over, Press Any Key to Restart");

//2. Call startOver() if the user gets the sequence wrong.
startOver();
}

}

function nextSequence() {

userClickedPattern = [];
level++;
$("#level-title").text("Level " + level);

var randomNumber = Math.floor(Math.random() * 4);
var randomChosenColour = buttonColours[randomNumber];
gamePattern.push(randomChosenColour);

$("#" + randomChosenColour).fadeIn(100).fadeOut(100).fadeIn(100);
playSound(randomChosenColour);
}

function playSound(name) {
var audio = new Audio("sounds/" + name + ".mp3");
audio.play();
}

function animatePress(currentColor) {
$("#" + currentColor).addClass("pressed");
setTimeout(function () {
$("#" + currentColor).removeClass("pressed");
}, 100);
}

//1. Create a new function called startOver().
function startOver() {

//3. Inside this function, you'll need to reset the values of level, gamePattern and started variables.
level = 0;
gamePattern = [];
started = false;
}
41 changes: 41 additions & 0 deletions Games/Membox/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
<meta charset="utf-8">
<title>Simon</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet">
</head>

<body>
<h1 id="level-title">Press A Key to Start</h1>
<div class="container">
<div class="row">

<div type="button" id="green" class="btn green">

</div>

<div type="button" id="red" class="btn red">

</div>
</div>

<div class="row">

<div type="button" id="yellow" class="btn yellow">

</div>
<div type="button" id="blue" class="btn blue">

</div>

</div>

</div>
<script src="https://code.jquery.com/jquery-3.6.3.js" integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM=" crossorigin="anonymous"></script>
<script src="game.js"></script>
</body>

</html>
Binary file added Games/Membox/sounds/blue.mp3
Binary file not shown.
Binary file added Games/Membox/sounds/green.mp3
Binary file not shown.
Binary file added Games/Membox/sounds/red.mp3
Binary file not shown.
Binary file added Games/Membox/sounds/wrong.mp3
Binary file not shown.
Binary file added Games/Membox/sounds/yellow.mp3
Binary file not shown.
53 changes: 53 additions & 0 deletions Games/Membox/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
body {
text-align: center;
background-color: #011F3F;
}

#level-title {
font-family: 'Press Start 2P', cursive;
font-size: 3rem;
margin: 5%;
color: #FEF2BF;
}

.container {
display: block;
width: 50%;
margin: auto;

}

.btn {
margin: 25px;
display: inline-block;
height: 200px;
width: 200px;
border: 10px solid black;
border-radius: 20%;
}

.game-over {
background-color: red;
opacity: 0.8;
}

.red {
background-color: red;
}

.green {
background-color: green;
}

.blue {
background-color: blue;
}

.yellow {
background-color: yellow;
}

.pressed {
box-shadow: 0 0 20px white;
background-color: grey;
}
Binary file added assets/images/Membox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading