Forum > General

Rock,Paper,Scissors

(1/5) > >>

s158:
Hey guys, a bit new to Lazarus here and am trying to make a Rock,Paper,Scissors program. Can someone help me out?
I am in Lazarus.
I'm trying to make a program that'll load an image of rock,paper,scissors  randomly on both boxes above(see the attachment) and at the same time will display who won, lost or draw on the boxes below when the button is pressed. So yep it's like a comp vs comp game. Any help is appreciated!

Uhh,sorry for my bad english/ grammar. Its not my native language.
Also, sorry if this is not the right section to post this stuff.

Handoko:
Hello s158,
Welcome to the forum.

You first need the pictures. Have you drawn them? Or maybe you can get some from OpenClipArt:
https://openclipart.org/search/?query=hand+scissor

It is easier to use bmp or png or jpg images than the others. So if the pictures you got aren't in these formats, you should convert them.

Do you understand how to use Random in Pascal? If not, you may need to read this:
https://www.freepascal.org/docs-html/rtl/system/random.html

You may need to use a TImageList to store the images, read more here:
http://wiki.freepascal.org/TImageList

The tutorial in the TImageList link above is a bit too technical. What you need for showing the image is TImageList.Draw or TImageList.GetBitmap (depends on how you use it). And for loading images from file, you only need to double click the TImageList that you've already put it on the form. But remember, you need to set the size (height and width) before loading any images.

You also need a TTimer. Set the Interval you want and then write your code inside OnTimer event.
http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/ttimer.html

Have fun.

s158:
Thx, please can you explain me what should i give to timer?

balazsszekely:
@s158
First of all you should really read what @Handoko posted,  basically it covers everything you need.
Secondly if you are a beginner it can be overwhelming, so I decided to help you a little bit, but I'm not gonna do all the work for you:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function RandomRPS: Integer;begin  Result := (Random(1000) + 1) mod 3;end; function WhoWins(const R1, R2: Integer): String;begin  case R2 - R1 of        0: Result := 'Draw.';    -2, 1: Result := 'First wins.';    -1, 2: Result := 'Second wins.';  end;end; procedure Play;const  RPS:  array[0..2] of String = ('Rock', 'Scissor', 'Paper');var  R1, R2: Integer;begin  R1 := RandomRPS;  R2 := RandomRPS;   ShowMessage('1: ' + RPS[R1] + sLineBreak +              '2: ' + RPS[R2] + sLineBreak +              WhoWins(R1, R2);end; procedure TForm1.Button1Click(Sender: TObject);begin  Play;end; procedure TForm1.FormCreate(Sender: TObject);begin  Randomize;end;
To do: Load the images, add a timer if you wish to repeat the process multiple times, etc...

PS: I did not test the code myself. It may contain bugs.

s158:
I am trying to understanding it, but i am not, please can you give me yet some more advice? Thx

Navigation

[0] Message Index

[#] Next page

Go to full version