views:

28

answers:

1

I am a student, and I'm working on a little slots game (if the same random number comes up 3 timed, you win). I use Borland Pascal 7. I use graph to make this a bit more visual, but when I start the game my background turns from black to grey, and the other problem is that if I click the game start button, the game runs many times until I release the mouse button. How can I solve this?

Here is my full program:

program slots;
uses mymouse,graph,crt;
var gdriver,gmode,coin:integer;
    m:mouserec;
    a,b,c,coins:string;
   procedure gomb(x1,y1,x2,y2:integer;szoveg:string);
   var j,n:integer;
   begin
      setcolor(blue);
      rectangle(x1,y1,x2,y2);
      setfillstyle(1,blue);
      floodfill(x1+2,y1+2,blue);
      setcolor(0);
      outtextxy((x1+x2)div 2 -textwidth(szoveg) div 2 ,(y1+y2) div 2-textheight(szoveg) div 2,szoveg);
      end;

  procedure randomal(var a,b,c:string);
  begin

  randomize;
  STR(random(2)+1,a);
  STR(random(2)+1,b);
  STR(random(2)+1,c);
  end;

 procedure menu;
  begin;
   settextstyle(0,0,1);
   outtextxy(20,10,'Meno menu');
   gomb(20,20,90,50,'Teglalap');
   gomb(20,60,90,90,'Inditas');
   gomb(20,100,90,130,'Harmadik');
   gomb(20,140,90,170,'Negyedik');
   end;
  procedure teglalap(x1,x2,y1,y2,tinta:integer);
  begin
  setcolor(tinta);
  rectangle(x1,x2,y1,y2);
  end;

  procedure jatek(var a,b,c:string;var coin:integer;coins:string);
  begin;
  clrscr;
  menu;
  randomal(a,b,c);
  if ((a=b) AND (b=c)) then coin:=coin+1 else coin:=coin-1;
  settextstyle(0,0,3);
  setbkcolor(black);
  outtextxy(200,20,a);
  outtextxy(240,20,b);
  outtextxy(280,20,c);
  STR(coin,coins);
  outtextxy(400,400,coins);
  end;

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

  until ((m.left) and (m.x>20) ANd (m.x<140) and (m.y>140) and (m.y<170));
end;
 begin
   coin:=50;
   gdriver:=detect;
   initgraph(gdriver, gmode, '');
   eger;
end.
A: 

I have many years to use Turbo Pascal :)

I used this snippet to init BGI (graphic) mode:

  Gd := Detect;
  InitGraph(Gd, Gm, 'bgi');
  if GraphResult <> grOk then
    Halt(1);
  SetBkColor(black);
  Cleardevice;

If I recall correctly, ClearDevice is proper for clearing the screen, ClrScr is for text mode.

Now, GetMouse(m); probably returns immediately the mouse data thus the code
in the repeat loop runs again and again with no delay, even if you don't use the mouse.
One solution is to check if the mouse button is up before you execute that code or
add some kind of delay before calling the GetMouse.

Nick D