Recent

Author Topic: Rock,Paper,Scissors  (Read 10511 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5290
  • My goal: build my own game engine using Lazarus
Re: Rock,Paper,Scissors
« Reply #15 on: May 03, 2018, 08:20:18 pm »
Now, we change For-Do looping code to use TTimer

To use a TTimer, usually you need 3 things:
- The condition to stop the TTimer
- The interval
- The code that repeat

1. The Condition
Previously, we use the condition i = 50. But because TTimer does not have index, you cannot use it. You may use if the object reaches certain position for the condition:
Shape1.Left > 250

2. The Interval
Do you still remember Sleep(50); Application.ProcessMessages; ? It is much easier when using TTimer. You just need to provide the value 50 for the Interval property. The bigger the number, the slower the process will be.

3. The Code
The code that you should put inside OnTimer event are code that move the object and the condition to stop:
  Shape1.Left := Shape1.Left + 5;
  if (Shape1.Left > 250) then Timer1.Enabled := False;


Now putting all of them together, this is the code of the animation using TTimer:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Shape1: TShape;
  17.     Timer1: TTimer;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Timer1Timer(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.Button1Click(Sender: TObject);
  32. begin
  33.   Shape1.Left    := 8;
  34.   Timer1.Enabled := True;
  35. end;
  36.  
  37. procedure TForm1.Timer1Timer(Sender: TObject);
  38. begin
  39.   Shape1.Left := Shape1.Left + 5;
  40.   if (Shape1.Left > 250) then Timer1.Enabled := False;
  41. end;
  42.  
  43. end.
You can download animation-ttimer.zip for testing, which I provided at the attachment.

Remember you need those 3 things if you need to use a TTimer.

s158

  • New Member
  • *
  • Posts: 10
Re: Rock,Paper,Scissors
« Reply #16 on: May 03, 2018, 08:23:46 pm »
Yes, thats what I know i did in it already in small car race app.
But I really cant understand this app, please can you help me? Please?
app rock,paper,scissors.
Using images, in component image will be specific picture of rock,paper or scissors.
One image will be for random choose by pc, second image will be choice of player.
There will be 3 next small components Image, where will be also on1.rock,2.paper and 3.scissors
After clicking on one of small images, will be process of select by pc and comparing results.
Winner will add point, in case of draw no points are added.
Score will be always shown in component Label.
The game ends, if player gets 5 points.
Add too button for run again program and end application.

I will be very grateful and I wont forget it. Thx

Handoko

  • Hero Member
  • *****
  • Posts: 5290
  • My goal: build my own game engine using Lazarus
Re: Rock,Paper,Scissors
« Reply #17 on: May 03, 2018, 08:25:45 pm »
Sorry, I can't.
Ask others.

s158

  • New Member
  • *
  • Posts: 10
Re: Rock,Paper,Scissors
« Reply #18 on: May 03, 2018, 08:27:09 pm »
Please someone, I really need help with this:
app rock,paper,scissors.
Using images, in component image will be specific picture of rock,paper or scissors.
One image will be for random choose by pc, second image will be choice of player.
There will be 3 next small components Image, where will be also on1.rock,2.paper and 3.scissors
After clicking on one of small images, will be process of select by pc and comparing results.
Winner will add point, in case of draw no points are added.
Score will be always shown in component Label.
The game ends, if player gets 5 points.
Add too button for run again program and end application.

Please.

Handoko

  • Hero Member
  • *****
  • Posts: 5290
  • My goal: build my own game engine using Lazarus
Re: Rock,Paper,Scissors
« Reply #19 on: May 03, 2018, 08:32:48 pm »
Go to Fiverr. You pay someone $5 and they will write a small program for you.

I write program for hobby not money. And I only teach beginners who really want to learn.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Rock,Paper,Scissors
« Reply #20 on: May 03, 2018, 08:34:10 pm »
hi s158, if my work doesn't helps;
 I think your real problem is perhaps is not the pascal programming, but is your limited time to learn.


anyway here is a thread (I forgot that) for paid task, if you like to provide. I think somebody here will help you for paid.
I am sorry, I didn't have much time either. But you can try for fun,  8-) afaik.
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

s158

  • New Member
  • *
  • Posts: 10
Re: Rock,Paper,Scissors
« Reply #21 on: May 03, 2018, 08:37:36 pm »
I really want to learn, but I promised my friend, that I will send it to him today.
I know I should have learn from beginning, but if you will help me with that code, I will analyze it and I will learn it.
Please.

balazsszekely

  • Guest
Re: Rock,Paper,Scissors
« Reply #22 on: May 03, 2018, 08:42:35 pm »
Quote
I really want to learn, but I promised my friend, that I will send it to him today.
I know I should have learn from beginning, but if you will help me with that code, I will analyze it and I will learn it.
Please.
You got more help then a beginner usually gets. I can't decide for others, but in my opinion you should show us some effort first.

s158

  • New Member
  • *
  • Posts: 10
Re: Rock,Paper,Scissors
« Reply #23 on: May 03, 2018, 08:45:26 pm »
I was trying, There is what Ive done.
But i think thats absolutely not good

 

TinyPortal © 2005-2018