diff --git a/(5.) Snake Game/Readme.md b/(5.) Snake Game/Readme.md new file mode 100644 index 00000000..d60991a3 --- /dev/null +++ b/(5.) Snake Game/Readme.md @@ -0,0 +1,2 @@ +![Screenshot (4)](https://user-images.githubusercontent.com/95162790/195906103-8974945e-6a41-4d5c-b5ba-c73d9734ab56.png) +The first look of game ! diff --git a/(5.) Snake Game/Resources.txt b/(5.) Snake Game/Resources.txt new file mode 100644 index 00000000..91a3a0dc --- /dev/null +++ b/(5.) Snake Game/Resources.txt @@ -0,0 +1 @@ +https://stackoverflow.com/questions/38709923/why-is-requestanimationframe-better-than-setinterval-or-settimeout \ No newline at end of file diff --git a/(5.) Snake Game/bg.jpg b/(5.) Snake Game/bg.jpg new file mode 100644 index 00000000..a9e41de6 Binary files /dev/null and b/(5.) Snake Game/bg.jpg differ diff --git a/(5.) Snake Game/food.mp3 b/(5.) Snake Game/food.mp3 new file mode 100644 index 00000000..076198c9 Binary files /dev/null and b/(5.) Snake Game/food.mp3 differ diff --git a/(5.) Snake Game/gameover.mp3 b/(5.) Snake Game/gameover.mp3 new file mode 100644 index 00000000..414bf651 Binary files /dev/null and b/(5.) Snake Game/gameover.mp3 differ diff --git a/(5.) Snake Game/index.html b/(5.) Snake Game/index.html new file mode 100644 index 00000000..c8773301 --- /dev/null +++ b/(5.) Snake Game/index.html @@ -0,0 +1,33 @@ + + + + + + + Snake Mania + + + +
+
+ SNAKE
MANIA
+
+
+
+ (1.)Use Arrow keys to direct
the snake. +
+ (2.)Eat the food to increase snake
length and make high score. +
+ (3.)Try not to bump in walls or
into yourself. +
+ Have Fun !! +
+
+
+
+
Score: 0
+
High-Score: 0
+
+ + + \ No newline at end of file diff --git a/(5.) Snake Game/move.mp3 b/(5.) Snake Game/move.mp3 new file mode 100644 index 00000000..4d3d245d Binary files /dev/null and b/(5.) Snake Game/move.mp3 differ diff --git a/(5.) Snake Game/music.mp3 b/(5.) Snake Game/music.mp3 new file mode 100644 index 00000000..f1507af3 Binary files /dev/null and b/(5.) Snake Game/music.mp3 differ diff --git a/(5.) Snake Game/script.js b/(5.) Snake Game/script.js new file mode 100644 index 00000000..4d63a645 --- /dev/null +++ b/(5.) Snake Game/script.js @@ -0,0 +1,143 @@ +// Game Constants and variables +let inputDir = {x: 0, y: 0}; +const foodSound = new Audio('food.mp3'); +const gameOverSound = new Audio('gameover.mp3'); +const moveSound = new Audio('move.mp3'); +const musicSound = new Audio('music.mp3'); +let speed = 6; +let score = 0; +let lastPaintTime = 0; +let snakeArr = [ // array + {x: 13, y: 15} +] +let food = {x: 6, y:7}; // object + +// Game Functions +function main(ctime){ + window.requestAnimationFrame(main); + // console.log(ctime); + if((ctime - lastPaintTime)/1000 < 1/speed){ + return; + } + lastPaintTime = ctime; + + gameEngine(); +} + +function isCollide(sarr){ + // if snake bump into himself + for (let i = 1; i < snakeArr.length; i++) { + if(sarr[i].x === sarr[0].x && sarr[i].y === sarr[0].y){ + return true; + } + } + // if snake bump into wall + if(sarr[0].x >= 18 || sarr[0].x <= 0 || sarr[0].y >= 18 || sarr[0].y <= 0){ + return true; + } +} + +function gameEngine(){ + // Part 1: Updating the snake array and food + if(isCollide(snakeArr)){ + gameOverSound.play(); + musicSound.pause(); + inputDir = {x:0, y:0}; + alert("Game Over!! Press any key to play again"); + snakeArr = [{x:13, y:15}]; + musicSound.play(); + score = 0; + scoreBoard.innerHTML = "Score: " + score; + } + + // If you have eaten the food , increment the score and regenrate the food + if(snakeArr[0].y === food.y && snakeArr[0].x === food.x){ + foodSound.play(); + score += 1; + if(score > hiscore){ + hiscoreval = score; + localStorage.setItem('hiscore', JSON.stringify(hiscoreval)); + highScoreBoard.innerHTML = "HighScore: "+ hiscoreval; + } + scoreBoard.innerHTML = "Score: " + score; + snakeArr.unshift({x: snakeArr[0].x + inputDir.x, y: snakeArr[0].y + inputDir.y}); + // generating random number between a and b + // Math.round(a + (b - a)*Math.random()) + let a = 2; + let b = 16; + food = {x: Math.round(a + (b - a)*Math.random()), y: Math.round(a + (b - a)*Math.random())}; + } + + // Moving the snake + for (let i = snakeArr.length - 2; i >= 0; i--) { + snakeArr[i + 1] = {...snakeArr[i]}; + } + + snakeArr[0].x += inputDir.x; + snakeArr[0].y += inputDir.y; + + // Part 2: Display the snake and food + // Display Snake + board.innerHTML = ""; + snakeArr.forEach((e,index)=>{ + snakeElement = document.createElement('div'); + snakeElement.style.gridRowStart = e.y; + snakeElement.style.gridColumnStart = e.x; + if(index === 0){ + snakeElement.classList.add('head'); + } + else{ + snakeElement.classList.add('snake'); + } + board.appendChild(snakeElement); + }) + + // Display Food + foodElement = document.createElement('div'); + foodElement.style.gridRowStart = food.y; + foodElement.style.gridColumnStart = food.x; + foodElement.classList.add('food'); + board.appendChild(foodElement); +} + + +// Main logic starts here +let hiscore = localStorage.getItem('hiscore'); +// localStorage.clear() -> to clear local storage / high score +if(hiscore == null){ + hiscoreval = 0; + localStorage.setItem('hiscore', JSON.stringify(hiscoreval)); +} +else{ + highscoreval = JSON.parse(localStorage.getItem(hiscore)); + highScoreBoard.innerHTML = "HighScore: "+ hiscore; +} +window.requestAnimationFrame(main); +window.addEventListener('keydown', e=>{ + inputDir = {x: 0, y: 1}; // start the game + moveSound.play(); + switch (e.key) { + case "ArrowUp": + inputDir.x = 0; + inputDir.y = -1; + break; + + case "ArrowDown": + inputDir.x = 0; + inputDir.y = 1; + break; + + case "ArrowRight": + inputDir.x = 1; + inputDir.y = 0; + break; + + case "ArrowLeft": + inputDir.x = -1; + inputDir.y = 0; + break; + + default: + break; + } +}); \ No newline at end of file diff --git a/(5.) Snake Game/style.css b/(5.) Snake Game/style.css new file mode 100644 index 00000000..f80517b4 --- /dev/null +++ b/(5.) Snake Game/style.css @@ -0,0 +1,87 @@ +@import url('https://fonts.googleapis.com/css2?family=New+Tegomin&family=Varela+Round&display=swap'); + +*{ + padding: 0; + margin: 0; +} + +body{ + overflow: hidden; +} + +.body{ + background-image: url("bg.jpg"); + min-height: 100vh; + background-size: 100vw 100vh; + background-repeat: no-repeat; + display: flex; + justify-content: center; + align-items: center; +} + +#board{ + background: linear-gradient(rgb(170, 236, 170), rgb(236, 236, 167)); + width: 90vmin; + height: 92vmin; + border: 2px solid black; + display: grid; + grid-template-rows: repeat(18, 1fr); + grid-template-columns: repeat(18, 1fr); +} + +#scoreBoard{ + position: absolute; + top: 65px; + font-size: 40px; + right: 100px; + font-weight: bolder; + border: 4px dotted rgb(1, 48, 1); + padding: 10px; + font-family: 'New Tegomin', serif; +} + +#highScoreBoard{ + position: absolute; + top: 160px; + font-size: 40px; + right: 100px; + font-weight: bolder; + border: 4px dotted rgb(1, 48, 1); + padding: 10px; + font-family: 'New Tegomin', serif; +} + +#gameName{ + position: absolute; + top: 65px; + font-size: 70px; + left: 25px; + font-weight: bolder; + padding: 10px; + font-family: 'New Tegomin', serif; + height: 100vh; +} + +#rules{ + font-size: 20px; + line-height: 200%; +} + +.head{ + background: radial-gradient(circle, green, pink, lightgreen, red); + border: .25vmin solid rgb(48, 68, 48); + border-radius: 12px; + transform: scale(1.02); +} + +.snake{ + background-color: purple; + border: .25vmin solid white; + border-radius: 12px; +} + +.food{ + background: linear-gradient(green, blue); + border-radius: 50%; + border: .25vmin dotted purple; +} \ No newline at end of file diff --git a/Block Chain Implimentation/bin/ImplimentChain.class b/Block Chain Implimentation/bin/ImplimentChain.class new file mode 100644 index 00000000..82abc29b Binary files /dev/null and b/Block Chain Implimentation/bin/ImplimentChain.class differ diff --git a/Block Chain Implimentation/bin/MyInfo.class b/Block Chain Implimentation/bin/MyInfo.class new file mode 100644 index 00000000..91b56929 Binary files /dev/null and b/Block Chain Implimentation/bin/MyInfo.class differ diff --git a/Block Chain Implimentation/src/ImplimentChain.java b/Block Chain Implimentation/src/ImplimentChain.java new file mode 100644 index 00000000..ea7ac253 --- /dev/null +++ b/Block Chain Implimentation/src/ImplimentChain.java @@ -0,0 +1,28 @@ +import java.util.ArrayList; +import java.util.Arrays; + +public class ImplimentChain { + /** + Hash = digital signature + Each Block will have :- + List of transactions + Previous Hash + Hash + */ + + ArrayList blockchain = new ArrayList<>(); + + public static void main(String[] args) { + String[] genesisTransactions = {"Ishita sent nini 20 bitcoin","Rajat sent fin 50 bitcoin"}; + MyInfo genesisInfo = new MyInfo(0, genesisTransactions); + + String[] block2Transaction = {"A sent 10 bitcoin to B", "B sent 5 bitcoin to C"}; + MyInfo block2 = new MyInfo(genesisInfo.getBlockHash(), block2Transaction); + + System.out.println("Hash of genesis Block :"); + System.out.println(genesisInfo.getBlockHash()); + System.out.println("Hash of Block 2:"); + System.out.print(block2.getBlockHash()); + } + +} diff --git a/Block Chain Implimentation/src/MyInfo.java b/Block Chain Implimentation/src/MyInfo.java new file mode 100644 index 00000000..958a44f9 --- /dev/null +++ b/Block Chain Implimentation/src/MyInfo.java @@ -0,0 +1,30 @@ +import java.util.Arrays; + +public class MyInfo { + + private int previousHash; + private String[] transactions; + + private int BlockHash; + + public MyInfo(int previousHash, String[] transactions) { + this.previousHash = previousHash; + this.transactions = transactions; + + Object[] contents = {Arrays.hashCode(transactions), previousHash }; + this.BlockHash = Arrays.hashCode(contents); + } + + public int getPreviousHash() { + return previousHash; + } + + public String[] getTransactions() { + return transactions; + } + + public int getBlockHash() { + return BlockHash; + } + +} diff --git a/Tic Tac Toe using vanilla javascript/excited.gif b/Tic Tac Toe using vanilla javascript/excited.gif new file mode 100644 index 00000000..ac0ecac2 Binary files /dev/null and b/Tic Tac Toe using vanilla javascript/excited.gif differ diff --git a/Tic Tac Toe using vanilla javascript/gameover.mp3 b/Tic Tac Toe using vanilla javascript/gameover.mp3 new file mode 100644 index 00000000..34033cdc Binary files /dev/null and b/Tic Tac Toe using vanilla javascript/gameover.mp3 differ diff --git a/Tic Tac Toe using vanilla javascript/index.html b/Tic Tac Toe using vanilla javascript/index.html new file mode 100644 index 00000000..76de4ed3 --- /dev/null +++ b/Tic Tac Toe using vanilla javascript/index.html @@ -0,0 +1,66 @@ + + + + + + + Tic Tac Toe + + + + + +
+ +
+ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+

Welcome to Tic Tac Toe

+
+ Turn for X + +
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/Tic Tac Toe using vanilla javascript/music.mp3 b/Tic Tac Toe using vanilla javascript/music.mp3 new file mode 100644 index 00000000..f1507af3 Binary files /dev/null and b/Tic Tac Toe using vanilla javascript/music.mp3 differ diff --git a/Tic Tac Toe using vanilla javascript/script.js b/Tic Tac Toe using vanilla javascript/script.js new file mode 100644 index 00000000..4d64df43 --- /dev/null +++ b/Tic Tac Toe using vanilla javascript/script.js @@ -0,0 +1,69 @@ +console.log("Welcome to Tic Tac Toe"); +let music = new Audio("music.mp3"); +let audioturn = new Audio("ting.mp3"); +let gameoveraudio = new Audio("gameover.mp3"); +let turn = "X"; +let gameover = false; + +// Function to change turn +const changeTurn = ()=>{ + return turn === "X"?"0":"X"; +} + +// Function to check for a Win +const checkWin = ()=>{ + let boxtexts = document.getElementsByClassName("boxText"); + let wins = [ + [0, 1, 2, 5, 5, 0], + [3, 4, 5, 5, 15, 0], + [6, 7, 8, 5, 25, 0], + [0, 3, 6, -5, 15, 90], + [1, 4, 7, 5, 15, 90], + [2, 5, 8, 15, 15, 90], + [0, 4, 8, 5, 15, 45], + [2, 4, 6, 5, 15, 135] + ] + + wins.forEach(e =>{ + if((boxtexts[e[0]].innerText === boxtexts[e[1]].innerText) && + (boxtexts[e[1]].innerText === boxtexts[e[2]].innerText) && + (boxtexts[e[0]].innerText !== '')){ + document.querySelector('.info').innerText = boxtexts[e[0]].innerText + " Won"; + gameover = true; + document.querySelector('.imageBox').getElementsByTagName('img')[0].style.width = "200px"; + document.querySelector(".line").style.width = "20vw"; + document.querySelector(".line").style.transform = `translate(${e[3]}vw, ${e[4]}vw) rotate(${e[5]}deg)`; + } + }) +} + +// Game Logic +let boxes = document.getElementsByClassName("box"); +Array.from(boxes).forEach(element =>{ + let boxtext = element.querySelector(".boxText"); + element.addEventListener('click',()=>{ + if(boxtext.innerText === ''){ + boxtext.innerText = turn; + turn = changeTurn(); + audioturn.play(); + checkWin(); + if(!gameover){ + document.getElementsByClassName("info")[0].innerText = "Turn for " + turn; + } + } + }) +}) + +// Add onClick Listener to RESET button +reset.addEventListener('click', ()=>{ + let boxtexts = document.querySelectorAll('.boxText'); + Array.from(boxtexts).forEach(element => { + element.innerText = ""; + }); + turn = "X"; + gameOver = false; + document.getElementsByClassName("info")[0].innerText = "Turn for " + turn; + document.querySelector('.imageBox').getElementsByTagName('img')[0].style.width = "0px"; + document.querySelector(".line").style.width = "0"; + +}) \ No newline at end of file diff --git a/Tic Tac Toe using vanilla javascript/style.css b/Tic Tac Toe using vanilla javascript/style.css new file mode 100644 index 00000000..c65aff85 --- /dev/null +++ b/Tic Tac Toe using vanilla javascript/style.css @@ -0,0 +1,131 @@ +@import url('https://fonts.googleapis.com/css2?family=Baloo+Bhaina+2&family=Libre+Baskerville:ital@1&family=New+Tegomin&family=Roboto:wght@300&family=Varela+Round&display=swap'); + + +*{ + margin: 0; + padding: 0; +} + +nav{ + background-color: rgb(68, 4, 68); + color: white; + height: 60px; + font-size: 27px; + display: flex; + align-items: center; + padding: 0 15px; + font-family: 'New Tegomin', serif; +} + +nav ul{ + list-style-type: none; +} + +.gameContainer{ + display: flex; + justify-content: center; + margin-top: 50px; +} + +.container{ + display: grid; + grid-template-columns: repeat(3, 10vw); + grid-template-rows: repeat(3, 10vw); + font-family: 'Roboto', sans-serif; + position: relative; +} + +.box{ + border: 2px solid black; + font-size: 8vw; + cursor: pointer; + display: flex; + justify-content: center; + align-items: center; +} + +.box:hover{ + background-color: rgb(233, 223, 241); +} + +.gameInfo{ + padding: 0 34px; + font-family: 'Baloo Bhaina 2', cursive; +} + +.gameInfo h1{ + font-size: 2.5rem; +} + +.imageBox img{ + width: 0; + transition: width 1s ease-in-out; +} + +.br-0{ + border-right: 0; +} + +.bl-0{ + border-left: 0; +} + +.bt-0{ + border-top: 0; +} + +.bb-0{ + border-bottom: 0; +} + +#reset{ + margin: 0 24px; + padding: 1px 18px; + background-color: rgb(248, 209, 248); + border-radius: 6px; + cursor: pointer; + font-family: 'Baloo Bhaina 2'; + font-size: 15px; + font-weight: bolder; +} + +.info{ + font-size: 22px; + font-weight: bold; + font-family: 'New Tegomin', serif; +} + +.line{ + background-color: black; + width: 0; + height: 3px; + position: absolute; + background-color: #911d91; + transition: width 1s ease-in-out; +} + +@media screen and (max-width: 950px) +{ + .gameContainer{ + flex-wrap: wrap; + } + + .gameInfo{ + margin-top: 34px; + } + + .gameInfo h1{ + font-size: 1.5rem; + } + + .container{ + display: grid; + grid-template-columns: repeat(3, 20vw); + grid-template-rows: repeat(3, 20vw); + font-family: 'Roboto', sans-serif; + } + + .line { + visibility: hidden; + } +} \ No newline at end of file diff --git a/Tic Tac Toe using vanilla javascript/ting.mp3 b/Tic Tac Toe using vanilla javascript/ting.mp3 new file mode 100644 index 00000000..6dbc8775 Binary files /dev/null and b/Tic Tac Toe using vanilla javascript/ting.mp3 differ