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
Binary file modified .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions JavaScript CloneCoding Tetris/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!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">
<link rel="stylesheet" href="style.css">
<title>Tetris</title>
</head>
<body>
<div class="wrapper">
<div class="score">0</div>
<div class="playground">
<ul>
<li></li>
</ul>
</div>
</div>
</body>
</html>
43 changes: 43 additions & 0 deletions JavaScript CloneCoding Tetris/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
* {
margin: 0;
padding: 0;
}

ul {
list-style: 0;
}

body {
height: 100%;
overflow: hidden;
}

.score {
text-align: center;
font-size: 36px;
margin-bottom: 2rem;
}
.playground > ul {
width: 25px;
margin: 0 auto;
border: 1px solid #333;
}

.playground > ul > li {
width: 100%;
height: 25px;
}

.playground > ul > li > ul {
display: flex;
}

.playgorund > ul > li > ul > li {
width: 25px;
height: 25px;
outline: 1px solid #ccc;
}

.tree {
background: #67c23a;
}
59 changes: 59 additions & 0 deletions JavaScript CloneCoding Tetris/tetris.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// DOM
const playground = document.querySelector(".playground > ul");

// Setting
const GAME_ROWS = 20;
const GAME_COLS = 10;

// variables
let score = 0;
let duration = 500;
let downInterval;
let tempMovingItem;

const BLOCKS = {
tree: [
[[2,1], [0,1], [1,1], [1,1]],
[],
[],
[],
]
}
const movingItem = {
type: "tree",
direction: 0,
top: 0,
left: 3,
};

// functions
function init(){
tempMovingItem = { ...movingItem };

for (let i = 0; i < GAME_ROWS; i++) {
prependNewLine()
}
renderBlocks()
}

function prependNewLine() {
const li = document.createElement("li");
const ul = document.createElement("ul");
for (let j = 0; j < GAME_COLS; j++) {
const matrix = document.createElement("li");
ul.prepend(matrix);
}
li.prepend(ul);
playground.prepend(li);
}

function renderBlocks() {
const { type, direction, top, left } = tempMovingItem;

BLOCKS[type][direction].forEach(block=>{
const x = block[0] + left;
const y = block[1];
const target = playground.childNodes[y].childNodes[0].childNodes[x];
target.classList.add(type);
})
}