Stupid random bars - does what it says!
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,Windows;
const
barlength = 70;
type
randombar = class
strict private // use strict private for normal visibility rules
flength : integer;
fx : integer;
fy : integer;
procedure display();
public
procedure setlength(value:integer);
procedure setposition(x,y:integer);
function getlength() : integer;
procedure update();
constructor create();
end;
//--------Windows console stuff
function GetConInputHandle : THandle;
begin
Result := GetStdHandle(STD_INPUT_HANDLE)
end;
function GetConOutputHandle : THandle;
begin
Result := GetStdHandle(STD_OUTPUT_HANDLE)
end;
//-----------------------------------
procedure printxy(x,y:integer;s:string);
var
coords : _COORD;
chandle : THandle;
begin
chandle := GetConOutputHandle();
coords.X := x;
coords.Y := y;
setconsolecursorposition(chandle,coords);
writeln(s);
end;
//----- end of service routines
constructor randombar.create();
begin
inherited;
randomize;
self.fx := random(80);
self.fy := random(25);
self.flength := random(barlength);
end;
procedure randombar.update;
begin
self.flength := random(barlength);
self.display;
end;
procedure randombar.setlength(value: Integer);
begin
flength := value;
end;
function randombar.getlength;
begin
Result := flength;
end;
procedure randombar.setposition(x: Integer; y: Integer);
begin
fx := x;
fy := y;
end;
procedure randombar.display;
begin
printxy(fx,fy,stringofchar('X',flength)+stringofchar(' ',barlength-flength));
end;
var
bar : array[1 .. 10] of randombar;
i : integer;
begin
for i := 1 to 10 do
bar[i] := randombar.create;
//bar.setposition(20,20);
while true do
begin
for i := 1 to 10 do
bar[i].update;
end;
readln;
end.