Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Games/Game_01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


https://user-images.githubusercontent.com/89895559/148755705-4ddf9cf7-bc77-42d4-a912-962035dbafe7.mp4

225 changes: 225 additions & 0 deletions Games/Game_01/assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
const easy = [
"6------7------5-2------1---362----81--96-----71--9-4-5-2---651---78----345-------",
"685329174971485326234761859362574981549618732718293465823946517197852643456137298"
];
const medium = [
"--9-------4----6-758-31----15--4-36-------4-8----9-------75----3-------1--2--3--",
"619472583243985617587316924158247369926531478734698152891754236365829741472163895"
];
const hard = [
"-1-5-------97-42----5----7-5---3---7-6--2-41---8--5---1-4------2-3-----9-7----8--",
"712583694639714258845269173521436987367928415498175326184697532253841769976352841"
];
var timer;
var timeRemaining;
var lives;
var selectedNum;
var selectedTiles;
var disableSelect;
window.onload=function(){


id("start").addEventListener("click",startGame);
for(let i=0;i<id("number-container").children.length;i++){
id("number-container").children[i].addEventListener("click",function(){

if(!disableSelect){
if(this.classList.contains("selected")){
this.classList.remove("selected");
selectedNum=null;
}else{
for(let i=0;i<9;i++)
{
id("number-container").children[i].classList.remove("selected");
}

this.classList.add("selected");
selectedNum=this;
updateMove();


}
}
});

}
}


function startGame(){

id("lives").textContent="";
let board;
if(id("diff-1").checked) board=easy[0];
else if (id("diff-2").checked) board=medium[0];
else board=hard[0];

disableSelect=false;
generateBoard(board);
startTimer();
if(id("theme-1").checked){
qs("body").classList.remove("dark");
}else{
qs("body").classList.add("dark");
}
id("number-container").classList.remove("hidden");

}
function startTimer(){
if(id("time-1").checked) timeRemaining=300;
else if(id("time-2").checked) timeRemaining=600;
else if(id("time-3").checked) timeRemaining=900;

id("timer").textContent=timeConversion(timeRemaining);
timer=setInterval(function(){
timeRemaining--;
if(timeRemaining==0) endGame();
id("timer").textContent=timeConversion(timeRemaining);
},1000)
}
function timeConversion(time){
let minutes=Math.floor(time/60);
if(minutes<10) minutes="0"+minutes;
let seconds=time%60;
if(seconds<10) seconds="0"+seconds;
return minutes+":"+seconds;


}

function generateBoard(board){
clearPrevious();
let idCount=0;
for(let i=0;i<81;i++){
let tile=document.createElement("p");
if(board.charAt(i)!="-"){
tile.textContent=board.charAt(i);
}else{
tile.addEventListener("click",function(){
if(!disableSelect){
if(tile.classList.contains("selected")){
tile.classList.remove("selected");
selectedTiles=null;
}else{
for(let i=0;i<81;i++){
qsa(".tile")[i].classList.remove("selected");

}
tile.classList.add("selected");
selectedTiles=tile;
updateMove();
}
}

});
}
tile.id=idCount;
idCount++;
tile.classList.add("tile");
if((tile.id>17 && tile.id<27)||(tile.id>44 && tile.id<54)){
tile.classList.add("bottomborder");
}
if((tile.id+1)%9==3 ||(tile.id+1)%9==6 ){
tile.classList.add("rightborder");
}
id("board").appendChild(tile);
}


}

function updateMove(){
if(selectedTiles && selectedNum){
selectedTiles.textContent=selectedNum.textContent;
if(checkCorrect(selectedTiles)){

selectedTiles.classList.remove("selected");

selectedNum.classList.remove("selected");
selectedTiles=null;
selectedNum=null;
if(checkDone()){
endGame();
}

}else{
disableSelect=true;
selectedTiles.classList.add("incorrect");
setTimeout(function(){
disableSelect=false;
selectedTiles.classList.remove("incorrect");
selectedTiles.classList.remove("selected");
selectedTiles.classList.remove("selected");
selectedTiles.textContent="";
selectedTiles=null;
selectedNum=null;

},1000);


}

}
}
function checkDone(){
let tile=qsa(".tile");
for(let i=0;i<tile.length;i++){
if(tile[i].textContent==="")
return false;
}
return true;

}


function endGame(){
disableSelect=true;
clearTimeout(timer);
if(timeRemaining === 0){
id("lives").textContent="you lost!";

}else{

id("lives").textContent="you won!";
}
}
function checkCorrect(tile){
let solution;
if(id("diff-1").checked) solution=easy[1]
else if (id("diff-2").checked) solution=medium[1];
else solution=hard[1];
if(solution.charAt(tile.id)==tile.textContent){
return true;

}else{
return false;
}
}

function clearPrevious() {

let tiles= qsa(".tile");
for(let i=0;i<tiles.length;i++){
tiles[i].remove();

}
if (timer) clearTimeout(timer);
for(let i=0;i<id("number-container").children.length;i++){
id("number-container").children[i].classList.remove("selected");
}
selectedTiles=null;
selectedNum=null;
}
function qs(selector){

return document.querySelector(selector);
}
function qsa(selector){


return document.querySelectorAll(selector);
}

function id(id){
return document.getElementById(id);
}
105 changes: 105 additions & 0 deletions Games/Game_01/assets/sodoku.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!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>Sodoku</title>
<link
rel="stylesheet"
href="C:\Users\sachi\OneDrive\Desktop\sodoku\styles.css"
/>
<script src="index.js"></script>
</head>

<body>
<header class="header">
<h1 id="A">SUDOKU</h1>
<div id="setup-game">
<div id="diff">
<h2 id="B">Choose difficulty:</h2>
<label id="label">
<input
type="radio"
id="diff-1"
name="diff"
value="easy"
checked
/>Easy</label
>
<label id="label">
<input
type="radio"
id="diff-2"
name="diff"
value="easy"
/>Medium</label
>
<label id="label">
<input
type="radio"
id="diff-3"
name="diff"
value="easy"
/>Hard</label
>
</div>
<div id="time">
<h2 id="B">Choose time:</h2>
<label id="label">
<input type="radio" id="time-1" name="time" value="five" checked />5
min</label
>
<label id="label">
<input type="radio" id="time-2" name="time" value="ten" />10
min</label
>
<label id="label">
<input type="radio" id="time-3" name="time" value="fifteen" />15
min</label
>
</div>
<div id="theme">
<h2 id="B">Choose theme:</h2>
<label id="label"
><input
type="radio"
id="theme-1"
name="theme"
value="light"
checked
/>light</label
>
<label id="label"
><input
type="radio"
id="theme-2"
name="theme"
value="Dark"
/>Dark</label
>
</div>
</div>
<button id="start">New Game</button>
</header>
<div id="stats">
<p id="timer"></p>
<p id="lives"></p>
</div>
<div ig="game">
<div id="board"></div>

<div id="number-container" class="hidden">
<p id="one">1</p>
<p id="two">2</p>
<p id="three">3</p>
<p id="four">4</p>
<p id="five">5</p>
<p id="six">6</p>
<p id="seven">7</p>
<p id="eight">8</p>
<p id="nine">9</p>
</div>
</div>
</body>
</html>
Loading