تتغير الخلفية من تلقاء نفسها ويتكرر الإجراء عدة مرات حتى أقوم بتصوير زر الماوس
-
24-09-2019 - |
سؤال
أنا طالب ، وأنا أعمل على لعبة صغيرة من فتحات (إذا كان الرقم العشوائي نفسه يظهر 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.
المحلول
لدي سنوات عديدة لاستخدام توربو باسكال :)
لقد استخدمت هذا المقتطف لبدء BGI (الرسم):
Gd := Detect;
InitGraph(Gd, Gm, 'bgi');
if GraphResult <> grOk then
Halt(1);
SetBkColor(black);
Cleardevice;
إذا كنت أذكر بشكل صحيح، ClearDevice
مناسبة لتطهير الشاشة ، ClrScr
هو لوضع النص.
حاليا، GetMouse(m);
ربما يعيد بيانات الماوس على الفور وبالتالي الرمز
في ال repeat
تعمل الحلقة مرارًا وتكرارًا دون أي تأخير ، حتى لو لم تستخدم الماوس.
يتمثل أحد الحلول في التحقق مما إذا كان زر الماوس قد ارتفع قبل تنفيذ هذا الرمز أو
أضف نوعًا من التأخير قبل الاتصال بـ GetMouse
.