Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- const
- DEFAULT_START = 7;
- TETRIS_ROWS = 15;
- var
- column: string := ' '*20;
- board: array of Char;
- tetroLocation: Int32 = DEFAULT_START;
- thisTetro: TByteArray;
- const
- tetros:array of TByteArray = [[1,16,31,46], [2,15,16,17], [1,15,16,17], [2,15,16,17], [1,2,16,17], [0,1,16,17], [1,2,15,16]];
- function ToString(constref x:array of Char): string; override;
- var i: Int32;
- begin
- for i:=0 to High(x) do
- begin
- if (i mod 15 = 0) and (i > 0) then Result += LINE_SEP;
- Result += x[i];
- end;
- end;
- procedure SetRandomTetro();
- begin
- thisTetro := tetros[Random(Length(tetros))];
- end;
- function VerifyFreeSapce(blank:Char=' '): Boolean;
- begin
- {lowest pnt}
- if (tetroLocation+thisTetro[3]) div 15 > TETRIS_ROWS then Exit(False);
- Result := (board[tetroLocation+thisTetro[0]] = blank) and
- (board[tetroLocation+thisTetro[1]] = blank) and
- (board[tetroLocation+thisTetro[2]] = blank) and
- (board[tetroLocation+thisTetro[3]] = blank);
- end;
- procedure DrawTetro(sym:Char='#');
- begin
- board[tetroLocation+thisTetro[0]] := sym;
- board[tetroLocation+thisTetro[1]] := sym;
- board[tetroLocation+thisTetro[2]] := sym;
- board[tetroLocation+thisTetro[3]] := sym;
- end;
- procedure DropTetro();
- begin
- Inc(tetroLocation, 15);
- end;
- procedure UndropTetro();
- begin
- Dec(tetroLocation, 15);
- end;
- var
- I:int32;
- TetrisFrame: TImage;
- begin
- SetLength(board, Length(column)*25);
- for i:=0 to 14 do Move(column[1], board[i*20], 20);
- TetrisFrame := TImage.Create(500,1000); //this could be a form
- TetrisFrame.FontName := 'Consolas';
- TetrisFrame.Show();
- SetRandomTetro();
- while true do
- begin
- TetrisFrame.DrawColor := 0;
- TetrisFrame.DrawText(ToString(board), [50,50]);
- DrawTetro(#32);
- DropTetro();
- if not VerifyFreeSapce() then
- begin
- UnDropTetro();
- DrawTetro('#');
- TetrisFrame.DrawColor := $0077FF;
- TetrisFrame.DrawText(ToString(board), [50,50]);
- TetrisFrame.Show(False);
- SetRandomTetro();
- tetroLocation := Random(0,12);// DEFAULT_START;
- // still not free!?¤!"¤"!#%"#%
- if not VerifyFreeSapce() then
- TerminateScript('Game over');
- end else
- begin
- DrawTetro('#');
- TetrisFrame.DrawColor := $0077FF;
- TetrisFrame.DrawText(ToString(board), [50,50]);
- TetrisFrame.Show(False);
- end;
- //Sleep(100);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement