Unit brick;
Interface
Uses types;
///////////////
Type
// Tbrick = array [0 .. 6] of array [0 .. 6] of integer; // two-dimensional coordinate of the square
Tbrick1 = array [0 .. 3] of tpoint;
Tgame = Class
Public
Game_domain: array [0 .. 9] of array [0 .. 19] of integer; // game region, 2-dimensional array x = 10, y = 19
Pre_game_domain: array [0 .. 9] of array [0 .. 19] of integer; // previous game region, 2-dimensional array x = 10, y = 19
Graph_domain: array [0 .. 5] of array [0 .. 5] of integer; // block preview area x = 6, y = 6
// Bricks_coordinate: array [0 .. 4] of array [0 .. 3] of tbrick; // square coordinate Group 2-dimensional [I] [J] I = 5, j = 4;
Bricks_coordinate1: array [0 .. 4] of array [0 .. 3] of tbrick1; // square coordinate Group 2-dimensional I = 5, j = 4;
Score: integer; // game score
Speed: integer; // game speed
Bricksi: integer; // block type
Bricksj: integer; // the status of a certain Block
Brickx: integer; // coordinates of the position of the square in the game Area
Bricky: integer; // y coordinate of the square in the game zone
Procedure newbrick (); // generate a new square
// Procedure over (); // end
// Procedure pause (); // pause
// Procedure resume (); // continue
Procedure left (); // move left
Procedure right (); // shift right
Procedure down (); // move down
// Check whether the intersection is 0, not intersection, 1 intersection. State, 0 New, 1, drop, 2 left shift, 3 right shift
Function isintersection (State: integer): integer;
// Function getscore (): integer; // obtain the game score.
// Function isover (direct: integer): integer; // judge whether the game is over. The value 1 indicates that the game is over. The value 0 indicates that the game is not over.
Procedure update_game_domain (State: integer); // update the game area, 0, generate new Block 1, the block falls, and 2 ends the game
Procedure init_game (); // initialize the game
Function converst1 (Brick: tbrick1): tbrick1; // rotate // initialize the call
Procedure rotate (); // call the process of rotating the square whereabouts
End;
Implementation
// Initialize the Function
Procedure tgame. init_game ();
VaR
I, j, X, Y: integer;
Begin
// Initialize the game zone
For X: = 0 to 9 do
Begin
For Y: = 0 to 19 do
Begin
Game_domain [x, y]: = 0;
End;
End;
// Initialize the block preview area
For I: = 0 to 5 do
Begin
For J: = 0 to 5 do
Begin
Graph_domain [I, j]: = 0;
End;
End;
// Initialize the coordinate Group of the square
//****
//****
//****
//****
// For I: = 0 to 4 do
// Begin // **** one-font
Bricks_coordinate1 [0, 0]. X: =-3;
Bricks_coordinate1 [0, 0]. Y: =-1;
Bricks_coordinate1 [0, 0, 1]. X: =-1;
Bricks_coordinate1 [0, 0, 1]. Y: =-1;
Bricks_coordinate1 [0, 0, 2]. X: = 1;
Bricks_coordinate1 [0, 0, 2]. Y: =-1;
Bricks_coordinate1 [0, 0, 3]. X: = 3;
Bricks_coordinate1 [0, 0, 3]. Y: =-1;
// Dashboard
Bricks_coordinate1 [1, 0]. X: =-1;
Bricks_coordinate1 [1, 0]. Y: =-1;
Bricks_coordinate1 [1, 0, 1]. X: = 1;
Bricks_coordinate1 [1, 0, 1]. Y: =-1;
Bricks_coordinate1 [1, 0, 2]. X: =-1;
Bricks_coordinate1 [1, 0, 2]. Y: = 1;
Bricks_coordinate1 [1, 0, 3]. X: = 1;
Bricks_coordinate1 [1, 0, 3]. Y: = 1;
// Font
Bricks_coordinate1 [2, 0, 0]. X: =-3;
Bricks_coordinate1 [2, 0, 0]. Y: =-1;
Bricks_coordinate1 [2, 0, 1]. X: =-1;
Bricks_coordinate1 [2, 0, 1]. Y: =-1;
Bricks_coordinate1 [2, 0, 2]. X: =-1;
Bricks_coordinate1 [2, 0, 2]. Y: = 1;
Bricks_coordinate1 [2, 0, 3]. X: = 1;
Bricks_coordinate1 [2, 0, 3]. Y: = 1;
// Font 7
Bricks_coordinate1 [3, 0, 0]. X: = 1;
Bricks_coordinate1 [3, 0, 0]. Y: =-3;
Bricks_coordinate1 [3, 0, 1]. X: = 1;
Bricks_coordinate1 [3, 0, 1]. Y: =-1;
Bricks_coordinate1 [3, 0, 2]. X: = 1;
Bricks_coordinate1 [3, 0, 2]. Y: = 1;
Bricks_coordinate1 [3, 0, 3]. X: =-1;
Bricks_coordinate1 [3, 0, 3]. Y: = 1;
// Convex
Bricks_coordinate1 [4, 0]. X: =-3;
Bricks_coordinate1 [4,0, 0]. Y: =-1;
Bricks_coordinate1 [4, 0, 1]. X: =-1;
Bricks_coordinate1 [4, 0, 1]. Y: =-1;
Bricks_coordinate1 [4, 0, 2]. X: = 1;
Bricks_coordinate1 [4, 0, 2]. Y: =-1;
Bricks_coordinate1 [4, 0, 3]. X: =-1;
Bricks_coordinate1 [4, 0, 3]. Y: = 1;
For I: = 0 to 4 do
Begin
For J: = 0 to 2 do
Begin
// Bricks_coordinate [I, j + 1]: = converst (bricks_coordinate [I, j]); // A tbrick pointer may be returned if an error occurs.
Bricks_coordinate1 [I, j + 1]: = converst1 (bricks_coordinate1 [I, j]); // The tbrick1 pointer may be returned if an error occurs.
End; // J
End; // I
End;
// End initialization Function
// Generate a new square
Procedure tgame. newbrick (); // generate a new square
VaR
Rand: integer;
X: integer;
Y: integer;
Begin
For X: = 0 to 9 do
Begin
For Y: = 0 to 19 do
Begin
Pre_game_domain [x, y]: = game_domain [x, y]; // Save the current game region status when a new square is generated.
End; // y
End; // X
Rand: = random (20); // block has 20 statuses
Bricksi: = Rand Div 4;
Bricksj: = Rand mod 4;
Brickx: = 4; // The X coordinate of the square shifts left by 4
Bricky: = 16; // The Y coordinate of the square moves down 16
If isintersection (0) = 0 then
Update_game_domain (0 );
End;
// End generates a new square
// Update the game zone
Procedure tgame. update_game_domain (State: integer); // update the game area, 0, generate new Block 1, block fall complete, 2, left shift, 3, right shift, 4 end game
VaR
I, X, Y: integer;
Begin
For X: = 0 to 9 do
Begin
For Y: = 0 to 19 do
Begin
Game_domain [x, y]: = pre_game_domain [x, y]; // Save the current game region status when a new square is generated.
End; // y
End; // X
For I: = 0 to 3 do
Begin
Game_domain [(bricks_coordinate1 [bricksi, bricksj, I]. X-1) Div 2 + brickx, (bricks_coordinate1 [bricksi, bricksj, I]. Y-1) Div 2 + Bricky]: = 1;
End; // I
End;
// End updates the game zone
// Move down
Procedure tgame. Down (); // move down
VaR
X, Y, X1, Y1, Count: integer;
Begin
Bricky: = Bricky-1;
If isintersection (0) = 0 then
Begin
Update_game_domain (1)
End
Else
Begin
Bricky: = Bricky + 1;
For Y: = 0 to 19 do
Begin
Count: = 0;
For X: = 0 to 9 do
Begin
Count: = game_domain [x, y] + count;
End; // X
If Count = 10 then
Begin
For Y1: = y to 18 do
Begin
For X1: = 0 to 9 do
Begin
Game_domain [X1, Y1]: = game_domain [X1, Y1 + 1];
End; // X1
End; // Y1
End; // If
End; // y
End;
End;
// Move the end down
// Move left
Procedure tgame. Left (); // shift left
Begin
Brickx: = brickx-1;
If isintersection (0) = 0 then
Begin
Update_game_domain (2 );
End
Else
Begin
Brickx: = brickx + 1;
End;
End;
// End; move left
// Shift right
Procedure tgame. Right (); // shift right
Begin
Brickx: = brickx + 1;
If isintersection (0) = 0 then
Begin
Update_game_domain (3 );
End
Else
Begin
Brickx: = brickx-1;
End;
End;
// Shift end right
// Rotate the square
Procedure tgame. Rotate (); // call the process of rotating the square whereabouts
VaR
Temp: integer;
Begin
Temp: = bricksj;
Bricksj: = (bricksj + 1) mod 4;
If isintersection (0) = 0 then
Begin
Update_game_domain (4 );
End
Else
Begin
Bricksj: = temp;
End;
End;
// End Rotation
// Check for intersection
// Check whether the intersection is 0, not intersection, 1 intersection. State, 0 New, 1, drop, 2 left shift, 3 right shift
Function tgame. isintersection (State: integer): integer;
VaR
I, X, Y: integer;
Begin
For I: = 0 to 3 do
Begin
If pre_game_domain [(parts [bricksi, bricksj, I]. X-1) Div 2 + brickx, (bricks_coordinate1 [bricksi, bricksj, I]. Y-1) Div 2 + Bricky] = 1 then
Begin
Result: = 1;
Exit;
End;
If (bricks_coordinate1 [bricksi, bricksj, I]. x-1) Div 2 + brickx <0) or (bricks_coordinate1 [bricksi, bricksj, I]. x-1) Div 2 + brickx> 9) or (bricks_coordinate1 [bricksi, bricksj, I]. y-1) Div 2 + Bricky <0) then
Begin
Result: = 1;
Exit;
End; // If
End; // I
Result: = 0;
End;
// End Detection
// Rotate // initialize the call
Function tgame. converst1 (Brick: tbrick1): tbrick1; // rotate // initialize the call
VaR
I: integer;
Nextbrick: tbrick1;
Begin
For I: = 0 to 3 do
Begin
Nextbrick [I]. X: = brick [I]. Y;
Nextbrick [I]. Y: =-brick [I]. X;
End; // I
Result: = nextbrick;
End;
// End rotation // initialization call
End.