背景会自行更改,并且过程会重复多次,直到我释放鼠标按钮

发布于 2024-08-27 06:02:08 字数 1936 浏览 7 评论 0原文

我是一名学生,正在开发一个小型老虎机游戏(如果相同的随机数出现 3 次,您就赢了)。我使用 Borland Pascal 7。我使用图表来使其更加直观,但是当我开始游戏时,我的背景从黑色变成灰色,另一个问题是,如果我单击游戏开始按钮,游戏会运行很多次直到我松开鼠标按钮。我该如何解决这个问题?

这是我的完整程序:

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-09-03 06:02:08

我使用 Turbo Pascal 已经很多年了:)

我用这个片段来初始化 BGI(图形)模式:

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

如果我没记错的话,ClearDevice 适合清除屏幕,ClrScr用于文本模式。

现在,GetMouse(m); 可能立即返回鼠标数据,因此代码
即使您不使用鼠标,repeat 循环也会毫无延迟地一次又一次运行。
一种解决方案是在执行该代码之前检查鼠标按钮是否已弹起,或者
在调用 GetMouse 之前添加某种延迟。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文