ООП
- Program oop;
- Uses
- graph,crt;
- Type
- barObj = Object
- x1,x2,y1,y2: integer;
- Procedure Show;
- Procedure Hide;
- Procedure Init(nX1,nX2,nY1,nY2:integer);
- Procedure Move(speedX,speedY:integer);
- End;
- Procedure barObj.Init(nX1,nX2,nY1,nY2:integer);
- Begin
- x1 := nX1;
- x2 := nX2;
- y1 := nY1;
- y2 := nY2;
- End;
- Procedure barObj.Show;
- Begin
- SetFillStyle(SolidFill,15);
- Bar(x1,y1,x2,y2);
- End;
- Procedure barObj.Hide;
- Begin
- SetFillStyle(SolidFill,0);
- Bar(x1,y1,x2,y2);
- End;
- Procedure barObj.Move(speedX,speedY:integer);
- Begin
- Hide;
- x1 := x1+speedX;
- y1 := y1+speedY;
- x2 := x2+speedX;
- y2 := y2+speedY;
- Show;
- End;
- Var
- j,Err: integer;
- key: char;
- ourBar: barObj;
- Begin
- Err := detect;
- InitGraph(Err,j,'');
- ourBar.Init(100,200,300,400);
- Err := GraphResult;
- WriteLn(GraphErrorMsg(Err));
- ourBar.Show;
- While key<>'x' Do
- Begin
- key := readkey;
- If key='w' Then ourBar.Move(0,-5);
- If key='s' Then ourBar.Move(0,5);
- If key='a' Then ourBar.Move(-5,0);
- If key='d' Then ourBar.Move(5,0);
- End;
- halt;
- End.
Может помочь в написании многих игр и программ