我正在研究一个带有object-pascal的学校项目,我正在尝试制作一台水果机。我试图让那个轮转过来,我得到了这张照片:icons fruitmachine 我到目前为止它只显示了第一个,但我试图让图片向上移动,所以它显示其他人。这有可能吗?如果可以的话怎么样?
编辑:相框为100 * 100像素。图片为100 * 900像素。我希望图片移动它首先显示从0到100的像素,下一步10到110,下一步到20到120,等等。
代码:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Crt;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
Button17: TButton;
Button18: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure Button18Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11click(Sender: TObject);
procedure Button12click(Sender: TObject);
procedure Button13click(Sender: TObject);
procedure Button14click(Sender: TObject);
procedure Button15click(Sender: TObject);
procedure Button16click(Sender: TObject);
procedure Button17click(Sender: TObject);
procedure Timer1StopTimer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
x1, x2, x3, x4, money: double;
s1, s2, s3, s4, Smoney: string;
meloen, pruim, citroen, banaan, zeven: TPicture;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
s4:=label3.Caption;
if s4='0' then label1.Caption:='Kies een inzet bedrag!'
else
begin
Smoney:=label2.Caption;
money:=StrToFloat(Smoney);
x4:=StrToFloat(s4);
if x4>money then label1.Caption:='Uw inzet is te hoog!'
else
begin
money:=money-x4;
Smoney:=FloatToStr(money);
label2.Caption:=Smoney;
image1.Picture.LoadFromFile('rol2.png');
image2.Picture.LoadFromFile('rol2.png');
image3.Picture.LoadFromFile('rol2.png');
image4.Picture.LoadFromFile('rol1.png');
image5.Picture.LoadFromFile('rol2.png');
image6.Picture.LoadFromFile('rol3.png');
image7.Picture.LoadFromFile('rol1.png');
image8.Picture.LoadFromFile('rol2.png');
image9.Picture.LoadFromFile('rol3.png');
timer1.Enabled:=true;
end;
end;
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
label1.Caption:='';
label2.Caption:='100';
label3.Caption:='0';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
label3.Caption:='1';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
label3.Caption:='2';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
label3.Caption:='3';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
label3.Caption:='4';
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
label3.Caption:='5';
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
label3.Caption:='10';
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
label3.Caption:='20';
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
label3.Caption:='25';
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
label3.Caption:='50';
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
label3.Caption:='75';
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
label3.Caption:='100';
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
label3.Caption:='200';
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
label3.Caption:='250';
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
label3.Caption:='500';
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
label3.Caption:='750';
end;
procedure TForm1.Button17Click(Sender: TObject);
begin
label3.Caption:='1000';
end;
procedure TForm1.Timer1StopTimer(Sender: TObject);
begin
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
x1:=random(2);
x2:=random(5);
x3:=random(5);
if x1=1 then begin
image1.Picture.LoadFromFile('kers.png');
image4.Picture.LoadFromFile('meloen.png');
image7.Picture.LoadFromFile('zeven.png');
end;
if x1=2 then begin
image1.Picture.LoadFromFile('meloen.png');
image4.Picture.LoadFromFile('zeven.png');
image7.Picture.LoadFromFile('citroen.png');
end;
if x1=3 then begin
image1.Picture.LoadFromFile('zeven.png');
image4.Picture.LoadFromFile('citroen.png');
image7.Picture.LoadFromFile('banaan.png');
end;
if x1=4 then begin
image1.Picture.LoadFromFile('citroen.png');
image4.Picture.LoadFromFile('banaan.png');
image7.Picture.LoadFromFile('pruim.png');
end;
if x1=5 then begin
image1.Picture.LoadFromFile('banaan.png');
image4.Picture.LoadFromFile('pruim.png');
image7.Picture.LoadFromFile('big.png');
end;
if x1=6 then begin
image1.Picture.LoadFromFile('pruim.png');
image4.Picture.LoadFromFile('big.png');
image7.Picture.LoadFromFile('bar.png');
end;
if x1=7 then begin
image1.Picture.LoadFromFile('big.png');
image4.Picture.LoadFromFile('bar.png');
image7.Picture.LoadFromFile('sinaas.png');
end;
if x1=8 then begin
image1.Picture.LoadFromFile('bar.png');
image4.Picture.LoadFromFile('sinaas.png');
image7.Picture.LoadFromFile('kers.png');
end;
if x1=9 then begin
image1.Picture.LoadFromFile('sinaas.png');
image4.Picture.LoadFromFile('kers.png');
image7.Picture.LoadFromFile('meloen.png');
end;
if x2=1 then begin
image2.Picture.LoadFromFile('kers.png');
image5.Picture.LoadFromFile('meloen.png');
image8.Picture.LoadFromFile('zeven.png');
end;
if x2=2 then begin
image2.Picture.LoadFromFile('meloen.png');
image5.Picture.LoadFromFile('zeven.png');
image8.Picture.LoadFromFile('citroen.png');
end;
if x2=3 then begin
image2.Picture.LoadFromFile('zeven.png');
image5.Picture.LoadFromFile('citroen.png');
image8.Picture.LoadFromFile('banaan.png');
end;
if x2=4 then begin
image2.Picture.LoadFromFile('citroen.png');
image5.Picture.LoadFromFile('banaan.png');
image8.Picture.LoadFromFile('pruim.png');
end;
if x2=5 then begin
image2.Picture.LoadFromFile('banaan.png');
image5.Picture.LoadFromFile('pruim.png');
image8.Picture.LoadFromFile('big.png');
end;
if x2=6 then begin
image2.Picture.LoadFromFile('pruim.png');
image5.Picture.LoadFromFile('big.png');
image8.Picture.LoadFromFile('bar.png');
end;
if x2=7 then begin
image2.Picture.LoadFromFile('big.png');
image5.Picture.LoadFromFile('bar.png');
image8.Picture.LoadFromFile('sinaas.png');
end;
if x2=8 then begin
image2.Picture.LoadFromFile('bar.png');
image5.Picture.LoadFromFile('sinaas.png');
image8.Picture.LoadFromFile('kers.png');
end;
if x2=9 then begin
image2.Picture.LoadFromFile('sinaas.png');
image5.Picture.LoadFromFile('kers.png');
image8.Picture.LoadFromFile('meloen.png');
end;
if x3=1 then begin
image3.Picture.LoadFromFile('kers.png');
image6.Picture.LoadFromFile('meloen.png');
image9.Picture.LoadFromFile('zeven.png');
end;
if x3=2 then begin
image3.Picture.LoadFromFile('meloen.png');
image6.Picture.LoadFromFile('zeven.png');
image9.Picture.LoadFromFile('citroen.png');
end;
if x3=3 then begin
image3.Picture.LoadFromFile('zeven.png');
image6.Picture.LoadFromFile('citroen.png');
image9.Picture.LoadFromFile('banaan.png');
end;
if x3=4 then begin
image3.Picture.LoadFromFile('citroen.png');
image6.Picture.LoadFromFile('banaan.png');
image9.Picture.LoadFromFile('pruim.png');
end;
if x3=5 then begin
image3.Picture.LoadFromFile('banaan.png');
image6.Picture.LoadFromFile('pruim.png');
image9.Picture.LoadFromFile('big.png');
end;
if x3=6 then begin
image3.Picture.LoadFromFile('pruim.png');
image6.Picture.LoadFromFile('big.png');
image9.Picture.LoadFromFile('bar.png');
end;
if x3=7 then begin
image3.Picture.LoadFromFile('big.png');
image6.Picture.LoadFromFile('bar.png');
image9.Picture.LoadFromFile('sinaas.png');
end;
if x3=8 then begin
image3.Picture.LoadFromFile('bar.png');
image6.Picture.LoadFromFile('sinaas.png');
image9.Picture.LoadFromFile('kers.png');
end;
if x3=9 then begin
image3.Picture.LoadFromFile('sinaas.png');
image6.Picture.LoadFromFile('kers.png');
image9.Picture.LoadFromFile('meloen.png');
end;
if (x1=x2) and (x2=x3) then
begin
x4:=x4*10;
money:=StrToFloat(Smoney);
money:=money+x4;
Smoney:=FloatToStr(money);
label2.caption:=Smoney;
x4:=x4/4;
end
else if (x1=x2) xor (x2=x3) xor (x1=x3) then
begin
x4:=x4*3;
money:=StrToFloat(Smoney);
money:=money+x4;
Smoney:=FloatToStr(money);
label2.caption:=Smoney;
x4:=x4/2;
end;
timer1.Enabled:=false;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var
i:integer;
y:double;
begin
image1.Picture.LoadFromFile('rol.png');
end;
end.
答案 0 :(得分:0)
您可以将100x900图像加载到TBitmap中,然后使用图像的Canvas属性和画布的CopyRect方法从位图中的任何矩形绘制到画布。例如,如果您的位图已加载到FFruit中,并且您使用FPos作为位图中的行(例如,第三张图片将从200开始):
Image1.Canvas.CopyRect(Rect(0, 0, 100, 100), FFruit.Canvas, Rect(0, FPos, 100, FPos+100));
您可以在计时器事件中执行此操作,也可以更新其中的FPOS。
对您发布的当前代码的一个批评:不要在计时器中执行LoadFromFile方法调用。将图像加载到TBitmaps中,然后将它们分配到计时器中。 LoadFromFile需要大量的磁盘读取和处理。