-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
139 lines (123 loc) · 4.43 KB
/
index.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<html>
<head>
<title>Polytris</title>
<link rel="stylesheet" href="style.css" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div id="main">
<h1>
<a href="/Polytris">Polytris</a>
</h1>
<div>
<p>Move pieces with the arrow keys. Rotate with Z and X. Pause with the P key.</p>
</div>
<div id="status"></div>
<div id="game_row">
<div class="game_container main_container container">
<canvas id="gtx" width="350" height="630"></canvas>
</div>
<div class="info_container container">
<div class="info_panel">
<p>Score:</p>
<p id="score" class="right-align"></p>
</div>
<div class="info_panel">
<p>Level:</p>
<p id="level" class="right-align"></p>
</div>
<div class="info_panel">
<p>Lines:</p>
<p id="lines_cleared" class="right-align"></p>
</div>
<div class="game_container preview_container">
<canvas id="preview_gtx" width="140" height="140"></canvas>
</div>
</div>
<div class="text_container container">
<div>
<p>Polytris is a version of Tetris that has polyominoes made of n sized blocks.</p>
</div>
<div class="emphasis">
<p>
<a href="preview.html">View all pieces</a>
<a href="highscores.html">View high scores</a>
</p>
</div>
<div id="game_links"></div>
</div>
</div>
</div>
<script src="src/utilities.js"></script>
<script src="src/poly.js"></script>
<script src="src/pieceGenerator.js"></script>
<script src="src/game.js"></script>
<script>
var links = "Poly size: ";
for (var i = 1; i < 10; i++) {
links += `<a href="${window.location.pathname}?polySize=${i}">${i}</a>`
}
$("#game_links").html(links);
var polySize = 4;
var polySizeQuery = getQueryParam("polySize");
var polySize = parseInt(polySizeQuery, 10);
if (isNaN(polySize)) {
polySize = 4;
}
var pieces = new PieceGenerator().createPolyominoes(polySize);
var game = new PolytrisGame(10, 18, pieces);
game.startGame();
function resize() {
var currentCanvasHeight = $("#game_row").height();
var blockLength = currentCanvasHeight / game.gridHeight;
var gameHeight = blockLength * game.gridHeight;
var gameWidth = blockLength * game.gridWidth;
console.log(`width: ${gameWidth} - height: ${gameHeight}`);
$("#gtx").attr("height", gameHeight);
$("#gtx").attr("width", gameWidth);
game.rebuildGtx();
};
window.onresize = resize;
resize();
window.onkeydown = function (e) {
var key = e.keyCode ? e.keyCode : e.which;
var xMod = 0;
var yMod = 0;
if (!game.paused && !game.gameOver && game.removingLinesFrames == 0) {
// up or space
if (key == 38 || key == 32 || key == 87) {
game.dropPiece();
}
// down
else if (key == 40 || key == 83) {
yMod++;
}
// left
else if (key == 37 || key == 65) {
xMod--;
}
// right
else if (key == 39 || key == 68) {
xMod++;
}
// X
else if (key == 88 || key == 69) {
game.rotateCurrentPieceClockwise();
}
// Z
else if (key == 90 || key == 81) {
game.rotateCurrentPieceAntiClockwise();
}
}
// P
if (key == 80) {
game.paused = !game.paused;
}
if (xMod != 0 || yMod != 0) {
game.moveCurrentPiece(xMod, yMod);
}
}
</script>
</body>
</html>