Quote:
Originally Posted by _r.u.s.s.
why don't you post the code here, maybe we can point out places where you can improve it or tell you what could've been done better and more efficiently
|
Ooo-kay... I was a bit overloaded with joy 'cause when I showed that little nonsense to some fellow students I heard they jaws loudly dropping to the floor (maybe because they couldn't write anything pascal). The code:
Code:
program keymove;
uses crt,graph;
procedure videoinit;
var hibakod,gdriver,gmode:integer;
begin
gdriver:=detect;
initgraph(gdriver,gmode,' ');
hibakod:=graphresult;
if hibakod<>0 then
begin
writeln('GRAFIKUS HIBA: ',grapherrormsg(hibakod));
halt(1);
end;
end;
procedure fall;
var x,y,x1,y1,xirany,yirany:integer;
begin
x:=random(640);
y:=50;
x1:=x+50;
y1:=x-100;
xirany:=1;
yirany:=1;
repeat
y:=y+yirany;
y1:=y;
Setcolor(4);
rectangle(x,y,x1,y1);
delay(25);
Setcolor(0);
rectangle(x,y,x1,y1);
if y>469 then y:=0;
until keypressed;
end;
var x,y,a:integer; q:char;
begin
videoinit;
x:=340;
y:=280;
Setcolor(2);
Circle(x,y,8);
a:=1;
fall;
repeat
q:=readkey;
case q of
'd' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=x+a; Circle(x,y,8); end;
'a' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=x-a; Circle(x,y,8); end;
'w' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=y-a; Circle(x,y,8); end;
's' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=y+a; Circle(x,y,8); end;
'x' : halt(1);
'+' : a:=a+10;
'-' : a:=a-10;
end;
if x>640 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=0; end;
if x<0 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=629; end;
if y>480 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=0; end;
if y<0 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=480; end;
until q=#27;
readkey;
end.
I wanted to make a red square falling down while I can still move the circle. Later I'd make it like that if the square reaches the circle, the program quits. I guess the algorythm must be a little bit more complicated, and maybe I'd need to use blocks to store variables etc. No idea how to continue this...