• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking
computinglesson.com

Variable roles

program fixedarray;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,Windows;

type
  Tbouncer = record
    x,y : integer;
    dx,dy : integer;
    s : string[10];
  end;

const
   n = 4;
   maxx = 76;
   maxy = 22;

var
   b: Array[1..n] of Tbouncer;
   i : integer;
//-----------------------------------------
// Get handle to console input
//-----------------------------------------
function GetConInputHandle : THandle;
begin
Result := GetStdHandle(STD_INPUT_HANDLE)
end;
//-----------------------------------------
// Get handle to console output
//-----------------------------------------
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;

procedure update(clear:boolean);
var
   i : integer;

begin
        for i  := 1 to n do
        begin


          if clear then
             printxy(b[i].x,b[i].y,'.')
          else
            begin
           b[i].x := b[i].x+b[i].dx;
           b[i].y := b[i].y+b[i].dy;
           if b[i].x > maxx then b[i].dx := -1;
           if b[i].y > maxy then b[i].dy := -1;
           if b[i].x < 1  then b[i].dx := 1;
           if b[i].y < 1  then b[i].dy := 1;
           printxy(b[i].x,b[i].y,b[i].s);
            end;
        end;
end;



begin
   randomize;
   for i := 1 to n do
   begin
      b[i].x:=random(maxx);b[i].y:=random(maxy);b[i].dx:=1;b[i].dy:=1;
      b[i].s := 'O';
   end;
   while true do
   begin
        update(false);
        sleep(10);
        update(true);

   end;
   readln;
end.
Powered by Create your own unique website with customizable templates.