Recent

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

nhelraios

  • Newbie
  • Posts: 2
Rock,Paper,Scissors
« on: August 28, 2012, 01:02:05 pm »
Hey guys, a bit new to Lazarus here and am trying to make a Rock,Paper,Scissors program. Can someone help me out?

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.
« Last Edit: August 28, 2012, 01:28:37 pm by nhelraios »

nhelraios

  • Newbie
  • Posts: 2
Re: Rock,Paper,Scissors
« Reply #1 on: August 28, 2012, 01:32:07 pm »
okay so far. I have made three buttons w/c displays the images in the upper left box. how do I continue from here on?

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Rock,Paper,Scissors
« Reply #2 on: August 28, 2012, 01:36:17 pm »
I can give some code pieces.

Code: [Select]
const
  ROCK = 1;
  PAPER = 2;
  SCISSORS = 3;

Code: [Select]
function PlayGame(choice1, choice2: integer): integer;
begin
  if choice1=choice2 then begin
    // If they select same, tie game
    result:=0;
  end else begin
    // By default player 1 wins
    result:=1;
    // But if player 2 selects winning combination, he wins
    case choice1 of
      ROCK: if choice2=PAPER then result:=2;
      PAPER: if choice2=SCISSORS then result:=2;
      SCISSORS: if choice2=ROCK then result:=2;
    end;
  end;
end;

Code: [Select]
...
var gameresult: integer;
...
  gameresult:=PlayGame(random(3)+1, random(3)+1);
  case gameresult of
    0: begin
      // Tie game

    end;
    1: begin
      // Player 1 won

    end;
    2: begin
      // Player 2 won

    end;
  end;

 

TinyPortal © 2005-2018