-
-
Notifications
You must be signed in to change notification settings - Fork 278
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 #382 from Tanmay-Giram/adding-Catch-Me-Card-Game
adding Catch Me Card Edition
- Loading branch information
Showing
6 changed files
with
79 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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Catch Me</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
|
||
<div id="box"> | ||
<p>Catch Me</p> | ||
</div> | ||
<script src="script.js"></script> | ||
</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,7 @@ | ||
## Catch me if you can | ||
|
||
|
||
### Using HTML, CSS & JS | ||
##### you can find screenshot in this folder | ||
|
||
## Screeen shot: https://github.com/ammy20019/javascript-mini-projects/blob/master/CatchMeIfYouCan/ammy20019/screenshot.PNG |
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 @@ | ||
var box = document.getElementById("box"); | ||
|
||
var viewWidth = window.innerWidth; | ||
var viewHeight = window.innerHeight; | ||
|
||
|
||
// Updates the viewport height and width dynamically | ||
window.addEventListener("resize", function(event) { | ||
viewWidth = window.innerWidth; | ||
viewHeight = window.innerHeight; | ||
}); | ||
|
||
|
||
|
||
box.addEventListener("mouseover", function(event) { | ||
var boxAttr = box.getBoundingClientRect(); | ||
|
||
var pos = getNewPosition(boxAttr.width, boxAttr.height); | ||
|
||
box.style.top = pos.y + "px"; | ||
box.style.left = pos.x + "px"; | ||
}); | ||
|
||
|
||
|
||
function getNewPosition(boxWidth, boxHeight) { | ||
|
||
// The boxWidth and boxHeight are subtracted so that they would not move out from the right and bottom direction | ||
var newX = Math.floor((Math.random() * viewWidth) + 1 - boxWidth); | ||
var newY = Math.floor((Math.random() * viewHeight) + 1 - boxHeight); | ||
|
||
// These will satisfy that box does not move go out in the top and left direction | ||
if(newX < 0) { | ||
newX = 0; | ||
} | ||
if(newY < 0) { | ||
newY = 0; | ||
} | ||
|
||
return {x: newX, y: newY}; | ||
} |
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,15 @@ | ||
#box { | ||
width: 10vw; | ||
height: 10vw; | ||
background-color: #b916f4; | ||
cursor: pointer; | ||
position: absolute; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
#box p { | ||
font-size: 1.7vw; | ||
color: white; | ||
} |
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