-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtetris.html
More file actions
84 lines (76 loc) · 2.47 KB
/
tetris.html
File metadata and controls
84 lines (76 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html>
<head>
<title>Tetris</title>
<script src="tetrominoes.js"></script>
<script src="gameLoop.js"></script>
<script src="initialiseGrid.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="columnContainer">
<div id="column1">
<h1 class="scoreHeading">Controls</h1>
<b><p>Left and Right arrows to move <br />Up and Down arrows to rotate <br />
Space to drop <br />Z to switch blocks <br />P to pause
</p></b>
</div>
<div id="column2">
<div id="gameContainer">
<div id="overlay">
<table border="0">
<tr>
<td>
<div class = "textBackground">
<h1 id="displayText" class="overlayHeading">Game Over</h1>
</div>
</td>
</tr>
<tr height="10px" />
<tr>
<td align="center">
<button type="button" id="restartButton" onclick="reset()">
<h1 class="overlayHeading" style="font-size: 22;">Restart</h1>
</button>
</td>
</tr>
</table>
</div>
<div id="blockContainer" class="base"></div>
</div>
</div>
<div id="column3">
<div id="infoContainer">
<h1 class="scoreHeading">Next</h1>
<div id="nextBlockContainer"></div>
<div id="storageBlockContainer"></div>
</div>
<div id="scoreContainer">
<h1 class="scoreHeading">Score</h1>
<h1 id="score" style="font-size: 40;" class="scoreHeading">0</h1>
</div>
</div>
</div>
<script>
let mainGridContainer = document.getElementById("blockContainer");
let nextBlockContainer = document.getElementById("nextBlockContainer");
let storageBlockContainer = document.getElementById("storageBlockContainer");
let overlay = document.getElementById("overlay");
let displayText = document.getElementById("displayText");
let scoreText = document.getElementById("score");
let rows = 18;
let cols = 10;
let grid = createGrid(mainGridContainer, rows, cols);
let nextBlockGrid = createGrid(nextBlockContainer, 4, 2);
let storageBlockGrid = createGrid(storageBlockContainer, 4, 2);
// set size of overlay to match the grid
overlay.style.width = (cols*sideLength + 20) + "px";
overlay.style.height = (rows*sideLength + 20) + "px";
document.onkeydown = checkKey;
mainGridContainer.addEventListener("lockedInPlace", gameLoop);
let newTet = createTetromino();
let storeTet = createTetromino();
storeTet.showPreview(storageBlockGrid);
gameLoop();
</script>
</body>
</html>