Skip to content

Commit 12da85e

Browse files
author
hagward
committed
Fixed issue in random generator
- Fixed so that the random generator disallow a mixed run of more than four consecutive S or Z, instead of non-mixed. - Edited the comment chunk at the top of tetris.js. - Edited version label from beta to stable.
1 parent cbb4717 commit 12da85e

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

random.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* These functions are responsible for generating "fair" "random" tetrominos.
33
* It is making sure that an 'I' tetromino comes at least every 12th round and
4-
* that a maximum of four 'S' and 'Z' tetriminos can be spawned consecutively.
4+
* that a maximum of four 'S' and 'Z' tetriminos can be spawned consecutively.
55
*/
66

77
var g_numTetros = [];
@@ -28,10 +28,10 @@ function getRandomTetromino() {
2828
// Make sure that we at least get one I each 12th time.
2929
newTetromino = 0;
3030
} else if (len >= 4
31-
&& g_prevQueue[len-1] == g_prevQueue[len-2]
32-
&& g_prevQueue[len-2] == g_prevQueue[len-3]
33-
&& g_prevQueue[len-3] == g_prevQueue[len-4]
34-
&& g_prevQueue[len-4] >= 5) {
31+
&& (g_prevQueue[len-1] == 5 || g_prevQueue[len-1] == 6)
32+
&& (g_prevQueue[len-2] == 5 || g_prevQueue[len-2] == 6)
33+
&& (g_prevQueue[len-3] == 5 || g_prevQueue[len-3] == 6)
34+
&& (g_prevQueue[len-4] == 5 || g_prevQueue[len-4] == 6)) {
3535
// If the four last tetriminos were 'S' or 'Z', spawn something else.
3636
newTetromino = Math.floor(Math.random() * 5);
3737
} else {

tetris.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
/**
22
* JavaScriptris v0.3 by Anders Hagward
3-
* Date: 2013-06-24
4-
* Last updated: 2013-08-16
3+
* Created on: 2013-06-24
4+
* Last updated: 2013-08-23
55
*
6-
* The challenge was: how long time will it take to write a Tetris clone
7-
* stranded on a desolate island with only a laptop and an old smartphone,
8-
* equipped with a painfully slow and unreliable mobile internet connection and
9-
* barely basic JavaScript knowledge? The answer was: two evenings and one
10-
* morning.
11-
*
12-
* At first I used a list containing the locked g_blocks in order to be able to
13-
* render them more quickly (in contrast to looping through the 10*16 'g_blocks'
14-
* matrix), but maintaining the list when deleting rows showed to be a bit
15-
* tricky. I then reckoned that was a completely unnecessary optimization and
16-
* saved myself from the headache. The score system is from the original Tetris
17-
* but the level system is completely improvised.
18-
*
19-
* Enjoy this fun little project!
6+
* Stranded on a desolate island, equipped with merely a laptop, a painfully
7+
* slow and unreliable mobile internet connection and scarce JavaScript
8+
* knowledge, I started to ponder how long time it would take, and if I even
9+
* had the ability, to write a Tetris clone. Two evenings and one morning of
10+
* coding later I had found the answer.
2011
*/
2112

22-
var g_version = '0.3 beta 3';
13+
var g_version = '0.3';
2314

2415
var g_updateInterval = 1000;
2516

2617
var g_maxlevel = 12;
2718
var g_ghostOpacity = '0.3';
2819

20+
// Specifies how many line clears to be issued per number of lines cleared.
21+
// (To clarify: "line clears" do not equal the number of cleared lines).
2922
var g_lineClearsPerAction = [1, 3, 5, 8];
3023

3124
// Determines whether to show the moving tetromino or not.

0 commit comments

Comments
 (0)