views:

62

answers:

1

Hi! 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

A: 

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 D

related questions