fix next block on first swap

This commit is contained in:
Baipyrus 2022-11-07 09:11:22 +01:00
parent 7652d2cb2a
commit 5411af3153

View File

@ -423,14 +423,20 @@ namespace Tetris {
int[][]? tempMem = player.memPos;
Color tempCol1 = player.color;
Color? tempCol2 = player.memCol;
// Generating new Block
int blockIndex = 0;
for (int i = 1; i < blocks.Length; i++)
if (blocks[i].Equals(next.positions)) {
blockIndex = i;
break;
}
// Generate new Player and assign saved variables
player = new();
player.memPos = tempPos;
player.memCol = tempCol1;
player = new(blockIndex, tempPos, tempCol1);
if (tempMem != null && tempCol2 != null) {
player.positions = tempMem;
player.color = (Color)tempCol2;
}
} else
next = new(true);
// Actually clone the content of block in memory to be displayed without rotating later
player.memDis = new int[tempPos.Length][];
for (int i = 0; i < tempPos.Length; i++) {
@ -547,22 +553,8 @@ namespace Tetris {
positions = blocks[randInt];
color = colors[randInt];
int xB;
switch (randInt) {
default:
xB = 3;
break;
case 2:
xB = 2;
break;
case 4:
xB = 4;
break;
}
x = 4 - xB / 2;
y = 0;
initSelf(randInt);
}
// Constructor to carry over variables
@ -573,7 +565,29 @@ namespace Tetris {
positions = blocks[blockIndex];
color = colors[blockIndex];
initSelf(blockIndex);
}
// Same difference
public Player(int blockIndex, int[][] _memPos, Color _memCol) {
positions = blocks[blockIndex];
color = colors[blockIndex];
memPos = _memPos;
memCol = _memCol;
initSelf(blockIndex);
}
// Constructor to use Player Object as a simple memory
public Player(int _x, int _y, int[][] _positions) {
x = _x;
y = _y;
positions = _positions;
}
public void initSelf(int blockIndex) {
int xB;
switch (blockIndex) {
default:
@ -590,13 +604,6 @@ namespace Tetris {
x = 4 - xB / 2;
y = 0;
}
// Constructor to use Player Object as a simple memory
public Player(int _x, int _y, int[][] _positions) {
x = _x;
y = _y;
positions = _positions;
}
}
}
}