o que esta errado
Olá pessoal estou tendo problemas com o código abaixo. O codigo faz um sorteio de uma imagem e três nomes de uma banco de dados (paradox 7), o objetivo do programa é que o usuario associe a imagem com um dos nomes e o programa verifica se esta certo ou errado. O Problema é que está aparecendo nomes e imagens repetidas durante a execução do programa. o codigo é o seguinte:
(aceito sugestões de como melhorar o codigo)
procedure TFJogo2.Timer2Timer(Sender: TObject);
begin
if bot = 0 then
begin
image2.visible:= not image2.visible;
end
else if bot = 1 then
begin
image3.visible:= not image3.visible;
end
else if bot = 2 then
begin
image4.visible:= not image4.visible;
end;
end;
procedure TFJogo2.sort1;
begin
Randomize;
bot := Random(3);
if bot = 0 then
begin
BitBtn1.caption:=label9.caption;
BitBtn2.caption:=label10.caption;;
BitBtn3.caption:=label11.caption;;
end
else if bot = 1 then
begin
BitBtn2.caption:=label9.caption;
BitBtn1.caption:=label10.caption;;
BitBtn3.caption:=label11.caption;;
end
else if bot = 2 then
begin
BitBtn3.caption:=label9.caption;
BitBtn2.caption:=label10.caption;;
BitBtn1.caption:=label11.caption;;
end;
end;
procedure TFJogo2.sort;
var x,reg,reg1,reg2 : integer;
teste : boolean;
begin
Randomize;
Table1.First;
teste := true;
while teste do
begin
reg := Random(Table1.RecordCount + 1);
teste := false;
if j <> 1 then
begin
for x := 1 to j do
begin
if reg = ma[x] then
teste := true;
end;
end;
end;
ma[j] := reg;
Table1.MoveBy(reg);
label9.caption := Table1.FieldByName(´Nome´).AsString;
Le_Imagem_JPEG(table1picture, Image1);
table1.edit;
table1ativo.value := false;
table1.post;
// sorteio de outro nome
reg1 := reg;
while reg1 = reg do
begin
Randomize;
Table1.First;
reg1 := Random(Table1.RecordCount + 1);
end;
Table1.MoveBy(reg1);
label10.caption := Table1.FieldByName(´Nome´).AsString;
// sorteio de um nome
reg2 := reg;
while (reg2 = reg) or (reg2 = reg1) do
begin
Randomize;
Table1.First;
reg2 := Random(Table1.RecordCount + 1);
end;
Table1.MoveBy(reg2);
label11.caption := Table1.FieldByName(´Nome´).AsString;
end;
procedure TFJogo2.FormActivate(Sender: TObject);
var x : integer;
begin
numjog := 10;
if fjogo2.label2.visible then
numjog := 20;
pontos1:=0;
pontos2:=0;
label7.caption:=IntToStr(Pontos1);
label8.caption:=IntToStr(Pontos2);
j := 1;
sort;
sort1;
for x := 1 to 22 do
ma[x] := 0;
scaled := true;
if (screen.width <> ScreenWidth) then
begin
height := longint(height) * longint(screen.height) DIV ScreenHeight;
width := longint(width) * longint(screen.width) DIV ScreenWidth;
scaleBy(screen.width, ScreenWidth);
end;
end;
procedure TFJogo2.BitBtn1Click(Sender: TObject);
begin
btCk(0);
end;
procedure TFJogo2.BitBtn2Click(Sender: TObject);
begin
btCk(1);
end;
procedure TFJogo2.BitBtn3Click(Sender: TObject);
begin
btCk(2);
end;
procedure TFJogo2.btCk(bt:integer);
begin
if bt = bot then
begin
sndplaysound(´tada.wav´,snd_async);
j:=j+1;
sort;
sort1;
if fjogo2.label2.visible then
begin
if (j mod 2) = 0 then
begin
pontos1:= pontos1+1;
label7.Caption:=IntToStr(Pontos1);
end
else
begin
pontos2:= pontos2+1;
label8.Caption:=IntToStr(Pontos2);
end;
end
else
begin
pontos1:= pontos1+1;
label7.Caption:=IntToStr(Pontos1);
end;
end
else
begin
timer1.Enabled :=true;
Timer2.Enabled := true;
sndplaysound(´erro.wav´,snd_async);
end;
if j > numjog then
begin
if label2.visible then
begin
if pontos1 > pontos2 then
showmessage(´Fim de Jogo. O Jogador ´+ label3.caption +´ ganhou, ele fez ´+ label7.caption +´ pontos e o jogador ´+ label4.caption +´ fez ´+ label8.caption +´ pontos´)
else if pontos2 > pontos1 then
showmessage(´Fim de Jogo. O Jogador ´+ label4.caption +´ ganhou, ele fez ´+ label8.caption +´ pontos e o jogador ´+ label3.caption +´ fez ´+ label7.caption +´ pontos´)
else
showmessage(´Fim de Jogo. Houve empate entre o jogador ´+ label3.caption +´ e o jogador ´+ label4.caption +´ cada um com ´+ label7.caption +´ pontos.´);
end
else
showmessage(´Fim de Jogo. O Jogador ´+ label3.caption +´ fez ´+ label7.caption +´ pontos´ );
OKBottomDlg.Show;
end;
end;
procedure TFJogo2.Timer1Timer(Sender: TObject);
begin
timer2.Enabled := false;
image2.Visible := false;
image3.Visible := false;
image4.Visible := false;
j:=j+1;
sort;
sort1;
timer1.Enabled:=false;
end;
(aceito sugestões de como melhorar o codigo)
procedure TFJogo2.Timer2Timer(Sender: TObject);
begin
if bot = 0 then
begin
image2.visible:= not image2.visible;
end
else if bot = 1 then
begin
image3.visible:= not image3.visible;
end
else if bot = 2 then
begin
image4.visible:= not image4.visible;
end;
end;
procedure TFJogo2.sort1;
begin
Randomize;
bot := Random(3);
if bot = 0 then
begin
BitBtn1.caption:=label9.caption;
BitBtn2.caption:=label10.caption;;
BitBtn3.caption:=label11.caption;;
end
else if bot = 1 then
begin
BitBtn2.caption:=label9.caption;
BitBtn1.caption:=label10.caption;;
BitBtn3.caption:=label11.caption;;
end
else if bot = 2 then
begin
BitBtn3.caption:=label9.caption;
BitBtn2.caption:=label10.caption;;
BitBtn1.caption:=label11.caption;;
end;
end;
procedure TFJogo2.sort;
var x,reg,reg1,reg2 : integer;
teste : boolean;
begin
Randomize;
Table1.First;
teste := true;
while teste do
begin
reg := Random(Table1.RecordCount + 1);
teste := false;
if j <> 1 then
begin
for x := 1 to j do
begin
if reg = ma[x] then
teste := true;
end;
end;
end;
ma[j] := reg;
Table1.MoveBy(reg);
label9.caption := Table1.FieldByName(´Nome´).AsString;
Le_Imagem_JPEG(table1picture, Image1);
table1.edit;
table1ativo.value := false;
table1.post;
// sorteio de outro nome
reg1 := reg;
while reg1 = reg do
begin
Randomize;
Table1.First;
reg1 := Random(Table1.RecordCount + 1);
end;
Table1.MoveBy(reg1);
label10.caption := Table1.FieldByName(´Nome´).AsString;
// sorteio de um nome
reg2 := reg;
while (reg2 = reg) or (reg2 = reg1) do
begin
Randomize;
Table1.First;
reg2 := Random(Table1.RecordCount + 1);
end;
Table1.MoveBy(reg2);
label11.caption := Table1.FieldByName(´Nome´).AsString;
end;
procedure TFJogo2.FormActivate(Sender: TObject);
var x : integer;
begin
numjog := 10;
if fjogo2.label2.visible then
numjog := 20;
pontos1:=0;
pontos2:=0;
label7.caption:=IntToStr(Pontos1);
label8.caption:=IntToStr(Pontos2);
j := 1;
sort;
sort1;
for x := 1 to 22 do
ma[x] := 0;
scaled := true;
if (screen.width <> ScreenWidth) then
begin
height := longint(height) * longint(screen.height) DIV ScreenHeight;
width := longint(width) * longint(screen.width) DIV ScreenWidth;
scaleBy(screen.width, ScreenWidth);
end;
end;
procedure TFJogo2.BitBtn1Click(Sender: TObject);
begin
btCk(0);
end;
procedure TFJogo2.BitBtn2Click(Sender: TObject);
begin
btCk(1);
end;
procedure TFJogo2.BitBtn3Click(Sender: TObject);
begin
btCk(2);
end;
procedure TFJogo2.btCk(bt:integer);
begin
if bt = bot then
begin
sndplaysound(´tada.wav´,snd_async);
j:=j+1;
sort;
sort1;
if fjogo2.label2.visible then
begin
if (j mod 2) = 0 then
begin
pontos1:= pontos1+1;
label7.Caption:=IntToStr(Pontos1);
end
else
begin
pontos2:= pontos2+1;
label8.Caption:=IntToStr(Pontos2);
end;
end
else
begin
pontos1:= pontos1+1;
label7.Caption:=IntToStr(Pontos1);
end;
end
else
begin
timer1.Enabled :=true;
Timer2.Enabled := true;
sndplaysound(´erro.wav´,snd_async);
end;
if j > numjog then
begin
if label2.visible then
begin
if pontos1 > pontos2 then
showmessage(´Fim de Jogo. O Jogador ´+ label3.caption +´ ganhou, ele fez ´+ label7.caption +´ pontos e o jogador ´+ label4.caption +´ fez ´+ label8.caption +´ pontos´)
else if pontos2 > pontos1 then
showmessage(´Fim de Jogo. O Jogador ´+ label4.caption +´ ganhou, ele fez ´+ label8.caption +´ pontos e o jogador ´+ label3.caption +´ fez ´+ label7.caption +´ pontos´)
else
showmessage(´Fim de Jogo. Houve empate entre o jogador ´+ label3.caption +´ e o jogador ´+ label4.caption +´ cada um com ´+ label7.caption +´ pontos.´);
end
else
showmessage(´Fim de Jogo. O Jogador ´+ label3.caption +´ fez ´+ label7.caption +´ pontos´ );
OKBottomDlg.Show;
end;
end;
procedure TFJogo2.Timer1Timer(Sender: TObject);
begin
timer2.Enabled := false;
image2.Visible := false;
image3.Visible := false;
image4.Visible := false;
j:=j+1;
sort;
sort1;
timer1.Enabled:=false;
end;
Emilio
Curtidas 0