📄 old_block.cs
字号:
square2.Location = new Point(square3.Location.X, square3.Location.Y-squareSize);
square4.Location = new Point(square3.Location.X, square3.Location.Y-2*squareSize);
break;
}
break;
case BlockTypes.L:
// Rotate all squares around square 3
switch(StatusRotation) {
case RotationDirections.North:
StatusRotation = RotationDirections.East;
square1.Location = new Point(square3.Location.X+squareSize, square3.Location.Y);
square2.Location = new Point(square3.Location.X+2*squareSize, square3.Location.Y);
square4.Location = new Point(square3.Location.X, square3.Location.Y+squareSize);
break;
case RotationDirections.East:
StatusRotation = RotationDirections.South;
square1.Location = new Point(square3.Location.X-squareSize, square3.Location.Y);
square2.Location = new Point(square3.Location.X, square3.Location.Y+squareSize);
square4.Location = new Point(square3.Location.X, square3.Location.Y+2*squareSize);
break;
case RotationDirections.South:
StatusRotation = RotationDirections.West;
square1.Location = new Point(square3.Location.X-2*squareSize, square3.Location.Y);
square2.Location = new Point(square3.Location.X-squareSize, square3.Location.Y);
square4.Location = new Point(square3.Location.X, square3.Location.Y-squareSize);
break;
case RotationDirections.West:
StatusRotation = RotationDirections.North;
square1.Location = new Point(square3.Location.X, square3.Location.Y-2*squareSize);
square2.Location = new Point(square3.Location.X, square3.Location.Y-squareSize);
square4.Location = new Point(square3.Location.X+squareSize, square3.Location.Y);
break;
}
break;
case BlockTypes.T:
switch(StatusRotation) {
case RotationDirections.North:
StatusRotation = RotationDirections.East;
square1.Location = new Point(square2.Location.X, square2.Location.Y-squareSize);
square3.Location = new Point(square2.Location.X, square2.Location.Y+squareSize);
square4.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
break;
case RotationDirections.East:
StatusRotation = RotationDirections.South;
square1.Location = new Point(square2.Location.X+squareSize, square2.Location.Y);
square3.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
square4.Location = new Point(square2.Location.X, square2.Location.Y-squareSize);
break;
case RotationDirections.South:
StatusRotation = RotationDirections.West;
square1.Location = new Point(square2.Location.X, square2.Location.Y+squareSize);
square3.Location = new Point(square2.Location.X, square2.Location.Y-squareSize);
square4.Location = new Point(square2.Location.X+squareSize, square2.Location.Y);
break;
case RotationDirections.West:
StatusRotation = RotationDirections.North;
square1.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
square3.Location = new Point(square2.Location.X+squareSize, square2.Location.Y);
square4.Location = new Point(square2.Location.X, square2.Location.Y+squareSize);
break;
}
break;
case BlockTypes.Z:
// Rotate all squares around square 2
switch(StatusRotation) {
case RotationDirections.North:
StatusRotation = RotationDirections.East;
square1.Location = new Point(square2.Location.X, square2.Location.Y-squareSize);
square3.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
square4.Location = new Point(square2.Location.X-squareSize, square2.Location.Y+squareSize);
break;
case RotationDirections.East:
StatusRotation = RotationDirections.North;
square1.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
square3.Location = new Point(square2.Location.X, square2.Location.Y+squareSize);
square4.Location = new Point(square2.Location.X+squareSize, square2.Location.Y+squareSize);
break;
}
break;
case BlockTypes.S:
// Rotate all squares around square 2
switch(StatusRotation) {
case RotationDirections.North:
StatusRotation = RotationDirections.East;
square1.Location = new Point(square2.Location.X, square2.Location.Y-squareSize);
square3.Location = new Point(square2.Location.X+squareSize, square2.Location.Y);
square4.Location = new Point(square2.Location.X+squareSize, square2.Location.Y+squareSize);
break;
case RotationDirections.East:
StatusRotation = RotationDirections.North;
square1.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
square3.Location = new Point(square2.Location.X, square2.Location.Y-squareSize);
square4.Location = new Point(square2.Location.X+squareSize, square2.Location.Y-squareSize);
break;
}
break;
}
// After rotating the squares, test if they overlap other squares.
// If so, return to original position
if (!(GameField.IsEmpty(square1.Location.X/squareSize, square1.Location.Y/squareSize)&&GameField.IsEmpty(square2.Location.X/squareSize, square2.Location.Y/squareSize)&&GameField.IsEmpty(square3.Location.X/squareSize, square3.Location.Y/squareSize)&&GameField.IsEmpty(square4.Location.X/squareSize, square4.Location.Y/squareSize))) {
StatusRotation = OldStatusRotation;
square1.Location = OldPosition1;
square2.Location = OldPosition2;
square3.Location = OldPosition3;
square4.Location = OldPosition4;
}
Show(GameField.GraphBackground);
}
public bool Down() {
// If there's no block below the current one, go down
if (GameField.IsEmpty(square1.Location.X/squareSize, square1.Location.Y/squareSize+1)&&GameField.IsEmpty(square2.Location.X/squareSize, square2.Location.Y/squareSize+1)&&GameField.IsEmpty(square3.Location.X/squareSize, square3.Location.Y/squareSize+1)&&GameField.IsEmpty(square4.Location.X/squareSize, square4.Location.Y/squareSize+1)) {
// Hide the block (in the previous position)
Hide(GameField.GraphBackground);
// Update the block position
square1.Location = new Point(square1.Location.X, square1.Location.Y+squareSize);
square2.Location = new Point(square2.Location.X, square2.Location.Y+squareSize);
square3.Location = new Point(square3.Location.X, square3.Location.Y+squareSize);
square4.Location = new Point(square4.Location.X, square4.Location.Y+squareSize);
// Draw the block in the new position
Show(GameField.GraphBackground);
return true;
}
else {
// If there's a block below the current one, doesn't go down
// -> put it on the array that controls the game and return FALSE
GameField.StopSquare(square1, square1.Location.X/squareSize, square1.Location.Y/squareSize);
GameField.StopSquare(square2, square2.Location.X/squareSize, square2.Location.Y/squareSize);
GameField.StopSquare(square3, square3.Location.X/squareSize, square3.Location.Y/squareSize);
GameField.StopSquare(square4, square4.Location.X/squareSize, square4.Location.Y/squareSize);
return false;
}
}
public bool Right() {
// If there's no block to the right of the current one, go right
if (GameField.IsEmpty(square1.Location.X/squareSize+1, square1.Location.Y/squareSize)&&GameField.IsEmpty(square2.Location.X/squareSize+1, square2.Location.Y/squareSize)&&GameField.IsEmpty(square3.Location.X/squareSize+1, square3.Location.Y/squareSize)&&GameField.IsEmpty(square4.Location.X/squareSize+1, square4.Location.Y/squareSize)) {
// Hide the block (in the previous position)
Hide(GameField.GraphBackground);
// Update the block position
square1.Location = new Point(square1.Location.X+squareSize, square1.Location.Y);
square2.Location = new Point(square2.Location.X+squareSize, square2.Location.Y);
square3.Location = new Point(square3.Location.X+squareSize, square3.Location.Y);
square4.Location = new Point(square4.Location.X+squareSize, square4.Location.Y);
// Draw the block in the new position
Show(GameField.GraphBackground);
return true;
}
else {
// If there's a block to the right of the current one,
// doesn't go right and return FALSE
return false;
}
}
public bool Left() {
// If there's no block to the left of the current one, go left
if (GameField.IsEmpty(square1.Location.X/squareSize-1, square1.Location.Y/squareSize)&&GameField.IsEmpty(square2.Location.X/squareSize-1, square2.Location.Y/squareSize)&&GameField.IsEmpty(square3.Location.X/squareSize-1, square3.Location.Y/squareSize)&&GameField.IsEmpty(square4.Location.X/squareSize-1, square4.Location.Y/squareSize)) {
// Hide the block (in the previous position)
Hide(GameField.GraphBackground);
// Update the block position
square1.Location = new Point(square1.Location.X-squareSize, square1.Location.Y);
square2.Location = new Point(square2.Location.X-squareSize, square2.Location.Y);
square3.Location = new Point(square3.Location.X-squareSize, square3.Location.Y);
square4.Location = new Point(square4.Location.X-squareSize, square4.Location.Y);
// Draw the block in the new position
Show(GameField.GraphBackground);
return true;
}
else {
// If there's a block to the left of the current one,
// doesn't go left and return FALSE
return false;
}
}
// Draws each square of the block on the game field
public void Show(Graphics g) {
square1.Show(g);
square2.Show(g);
square3.Show(g);
square4.Show(g);
}
// Hides each square of the block on the game field
public void Hide(Graphics g) {
square1.Hide(g);
square2.Hide(g);
square3.Hide(g);
square4.Hide(g);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -