1

I use Borland Pascal 7.0, and I would like to make a slots game (If 3 random numbers are the same, you win). The problem is that when I click on the start (Inditas) button on the menu, the procedure executes many times until I release the mouse button. I was told that I should check if the mouse button is released before executing the procedure once. How can I do that? Here's what the menu looks like:

procedure eger;
begin;
  mouseinit;
  mouseon;
  menu;
  repeat  
    getmouse(m);
    if (m.left) and (m.x>60) AND (m.x<130) and (m.y>120) and (m.y<150) then
      teglalap(90,90,300,300,blue);
    if (m.left) and (m.x>60) AND (m.x<130) and (m.y>160) and (m.y<190) then
      jatek(a,b,c,coin,coins);     

  until ((m.left) and (m.x>60) AND (m.x<130) and (m.y>240) and (m.y<270));
end;

Thanks, Robert

Johan
  • 74,508
  • 24
  • 191
  • 319
Robert
  • 197
  • 11
  • Robert, what are the fields of `m` record? – Nick Dandoulakis Apr 04 '10 at 19:39
  • We were taught to use it this way,I don't know. I guess m.left and m.right are boolean, and m.x and m.y are integer or something like that.. We use a file in the program, named mymouse.tpu – Robert Apr 06 '10 at 09:47

1 Answers1

0

In case the mouse unit doesn't provide a way to wait for a mouse click, or something similar,
you can simulate a "button released" behavior with a couple of flag variables.

Example:

button_down := false; // 1
repeat
   button_released := false; // 2
   getmouse(m);
   // 3
   If m.left and not button_down Then button_down := true;
   If not m.left and button_down Then
   Begin
      button_released = true; 
      button_down := false;
   End;
   //
  if button_released and ... then ...
  if button_released and ... then ...
until (...);

(I don't know what m.left is but I assume it indicates whether the left button is down or not)

Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136