Skip to content

Commit

Permalink
added score with bigint!
Browse files Browse the repository at this point in the history
Signed-off-by: farteryhr <[email protected]>
  • Loading branch information
farteryhr committed Oct 7, 2015
1 parent 3f00dd3 commit c55940b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
15 changes: 15 additions & 0 deletions bigmin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h3>Hold</h3>
</ul>

<table id=stats>
<tr><th id=score>0</th><th>Score 分</th></tr>
<tr><td id=line>0</td><th>Line 行</th></tr>
<tr><td id=piece>0</td><th>Piece 块</th></tr>
<tr><th id=time>00:00.00</th></tr>
Expand Down Expand Up @@ -145,6 +146,7 @@ <h3>Next</h3>
</div>

<canvas id=sprite></canvas>
<script src=bigmin.js></script>
<script src=tetris.js></script>
<script src=piece.js></script>
<script src=stack.js></script>
Expand Down
3 changes: 2 additions & 1 deletion piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Piece.prototype.new = function(index) {
if (settings.Gravity !== 0) {
this.gravity = gravityArr[settings.Gravity - 1];
} else if (gametype === 1) { //Marathon
var level = ~~((lines)/10);
if (level < 20) {
this.gravity = [
1/60, 1/30, 1/25, 1/20, 1/15, 1/12, 1/10, 1/8, 1/6, 1/6,
Expand All @@ -67,9 +66,11 @@ Piece.prototype.new = function(index) {

// Check for blockout.
if (!this.moveValid(0, 0, this.tetro)) {
this.dead = true;
gameState = 9;
msg.innerHTML = 'BLOCK OUT!';
menu(3);
return;
}

piece.checkFall(); //real 20G !
Expand Down
54 changes: 53 additions & 1 deletion stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ Stack.prototype.new = function(x, y) {
* Adds tetro to the stack, and clears lines if they fill up.
*/
Stack.prototype.addPiece = function(tetro) {
var lineClear = 0;
var isSpin = false;
var once = false;

// spin check
if (
!piece.moveValid(-1, 0, piece.tetro) &&
!piece.moveValid( 1, 0, piece.tetro) &&
!piece.moveValid( 0,-1, piece.tetro)
) {
isSpin = true;
}

// Add the piece to the stack.
var range = [];
var valid = false;
Expand Down Expand Up @@ -58,7 +69,7 @@ Stack.prototype.addPiece = function(tetro) {
// Clear the line. This basically just moves down the stack.
// TODO Ponder during the day and see if there is a more elegant solution.
if (count === 10) {
lines++; // NOTE stats
lineClear++; // NOTE stats
if (gametype === 4) { // dig race
if (digLines.indexOf(row) !== -1) {
digLines.splice(digLines.indexOf(row), 1);
Expand All @@ -72,6 +83,47 @@ Stack.prototype.addPiece = function(tetro) {
}
}

var scoreAdd = bigInt(level + 1);
if (lineClear !== 0) {
console.log("C"+combo+" B"+b2b)
if (isSpin) {
scoreAdd = scoreAdd.mul(
bigInt([800,1200,1600,2000][lineClear - 1])
.mul(bigInt(2).pow(b2b + combo))
);
b2b += 1;
} else if(lineClear === 4) {
scoreAdd = scoreAdd.mul(
bigInt(800)
.mul(bigInt(2).pow(b2b + combo))
);
b2b += 1;
} else {
scoreAdd = scoreAdd.mul(
bigInt([100,300,500,800][lineClear - 1])
.mul(bigInt(2).pow(combo))
);
b2b = 0;
}
combo += 1;
} else {
if (isSpin) {
scoreAdd = scoreAdd.mul(
bigInt(2).pow(bigInt(b2b))
.mul(bigInt(400))
);
} else {
scoreAdd = bigInt(0);
}
combo = 0;
}
lines += lineClear;
if (gametype === 1)
level = ~~(lines / 10);
score = score.add(scoreAdd);
if (scoreAdd.cmp(0) > 0)
console.log(scoreAdd.toString());

statsFinesse += piece.finesse - finesse[piece.index][piece.pos][column];
piecesSet++; // NOTE Stats
// TODO Might not need this (same for in init)
Expand Down
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ nav a {
font-size: 1.125em;
display: block;
}
#score {
text-align: center;
font-weight: 900;
font-size: 1em;
display: block;
}

/* Menus */
.menu {
Expand Down Expand Up @@ -316,6 +322,7 @@ nav a {
height: 50%;
font-family: 'Lucida Console';
font-size: 0.5em;
word-wrap:break-word;
word-break:break-all;
background-color: #000;
color: #bfb;
Expand Down
19 changes: 19 additions & 0 deletions tetris.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var stats = document.getElementById('stats');
var statsTime = document.getElementById('time');
var statsLines = document.getElementById('line');
var statsPiece = document.getElementById('piece');
var statsScore = document.getElementById('score');
var h3 = document.getElementsByTagName('h3');
var set = document.getElementById('settings');
var leaderboard = document.getElementById('leaderboard');
Expand Down Expand Up @@ -428,8 +429,14 @@ var gameparams;
// var dirtyHold, dirtyActive, dirtyStack, dirtyPreview;
var lastX, lastY, lastPos, lastLockDelay, landed;

// Scoreing related status
var b2b;
var combo;
var level;

// Stats
var lines;
var score;
var statsFinesse;
var piecesSet;
var startTime;
Expand Down Expand Up @@ -780,8 +787,12 @@ function init(gt, params) {
preview.init()
//preview.draw();

b2b = 0;
combo = 0;
level = 0;
statsFinesse = 0;
lines = 0;
score = bigInt(0);
piecesSet = 0;

clear(stackCtx);
Expand Down Expand Up @@ -931,6 +942,14 @@ function statisticsStack() {
else{
statsLines.innerHTML = lines;
}

var strsplit = score.toString().split("");
var spacetoggle = 0;
for (var i = strsplit.length - 1 - 3; i >= 0; i -= 3) {
strsplit[i] += spacetoggle===0?"&#8239;":"&#8202;";
spacetoggle ^= 1;
}
statsScore.innerHTML = strsplit.join("");
}
// ========================== View ============================================

Expand Down

0 comments on commit c55940b

Please sign in to comment.