forked from codemistic/Web-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from soumdatta81/soumdatta81-patch-1
Added the dice game
- Loading branch information
Showing
16 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
// Player name | ||
var player1 = "Player 1"; | ||
var player2 = "Player 2"; | ||
|
||
// Function to change the player name | ||
function editNames() { | ||
player1 = prompt("Change Player1 name"); | ||
player2 = prompt("Change player2 name"); | ||
|
||
document.querySelector("p.Player1").innerHTML = player1; | ||
document.querySelector("p.Player2").innerHTML = player2; | ||
} | ||
|
||
// Function to roll the dice | ||
function rollTheDice() { | ||
setTimeout(function () { | ||
var randomNumber1 = Math.floor(Math.random() * 6) + 1; | ||
var randomNumber2 = Math.floor(Math.random() * 6) + 1; | ||
|
||
document.querySelector(".img1").setAttribute("src", | ||
"dice" + randomNumber1 + ".png"); | ||
|
||
|
||
document.querySelector(".img2").setAttribute("src", | ||
"dice" + randomNumber2 + ".png"); | ||
|
||
if (randomNumber1 === randomNumber2) { | ||
document.querySelector("h1").innerHTML = "Draw!"; | ||
} | ||
|
||
else if (randomNumber1 < randomNumber2) { | ||
document.querySelector("h1").innerHTML | ||
= (player2 + " WINS!"); | ||
} | ||
|
||
else { | ||
document.querySelector("h1").innerHTML | ||
= (player1 + " WINS!"); | ||
} | ||
}, 2500); | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content= | ||
"width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="./style.css"> | ||
<script src="dice.js"></script> | ||
<title>Dice Game</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>Let's Start</h1> | ||
|
||
<div class="dice"> | ||
<p class="Player1">Player 1</p> | ||
<img class="img1" src="img1/dice6.png"> | ||
</div> | ||
|
||
<div class="dice"> | ||
<p class="Player2">Player 2</p> | ||
<img class="img2" src="img2/dice6.png"> | ||
</div> | ||
</div> | ||
|
||
<div class="container bottom"> | ||
<button type="button" class="butn" | ||
onClick="rollTheDice()"> | ||
Roll the Dice | ||
</button> | ||
</div> | ||
<div class="container bottom"> | ||
<button type="button" class="butn" | ||
onClick="editNames()"> | ||
Edit Names | ||
</button> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
.container { | ||
width: 70%; | ||
margin: auto; | ||
text-align: center; | ||
} | ||
|
||
.dice { | ||
text-align: center; | ||
display: inline-block; | ||
margin: 10px; | ||
} | ||
|
||
body { | ||
background-color: #042f4b; | ||
margin: 0; | ||
} | ||
|
||
h1 { | ||
margin: 30px; | ||
font-family: "Lobster", cursive; | ||
text-shadow: 5px 0 #232931; | ||
font-size: 4.5rem; | ||
color: #4ecca3; | ||
text-align: center; | ||
} | ||
|
||
p { | ||
font-size: 2rem; | ||
color: #4ecca3; | ||
font-family: "Indie Flower", cursive; | ||
} | ||
|
||
img { | ||
width: 100%; | ||
} | ||
|
||
.bottom { | ||
padding-top: 30px; | ||
} | ||
|
||
.butn { | ||
background: #4ecca3; | ||
font-family: "Indie Flower", cursive; | ||
border-radius: 7px; | ||
color: #ffff; | ||
font-size: 30px; | ||
padding: 16px 25px 16px 25px; | ||
text-decoration: none; | ||
} | ||
|
||
.butn:hover { | ||
background: #232931; | ||
text-decoration: none; | ||
} |