jandj
20-02-2010, 22:52:49
saludos, el problema es el siguiente, estoy tratando de reproducir un sonido que diga una letra del abecedario, luego al precionar la letra si es correcto el programa reproducira un sonido diciendo que es correcto de lo contrario reproducirra otro sonido diciendo incorrecto. este es un ejemplo de lo que hecho.
primero el programa pregunta si tienes la respuesta:
procedure TForm1.Timer2Timer(Sender: TObject);
begin
sndPlaySound('C:\JProyect\JWordGuess\sonidos\tienelarespuesta.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer2.enabled:=false;
end;
segundo el programa reproduce el sonido de la respuesta esperando que se precione la tecla correcta o incorrecta:
procedure TForm1.Timer3Timer(Sender: TObject);
begin
a:=random(1);
if a = 0 then
sndPlaySound('C:\JProyect\JWordGuess\sonidos\A.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
//timerb.Enabled:=true;
timer3.enabled:=false;
timer3.Interval:=4000;
end;
tercero tengo este codigo en un edit:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
case a of
0:
begin
if (key = 'A') or (key = 'a') then
begin
sndPlaySound('C:\JProyect\JWordGuess\sonidos\correcto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer3.Enabled:=false;
timerb.Enabled:=true;
b:=random(1);
exit;
end
else
sndPlaySound('C:\JProyect\JWordGuess\sonidos\incorrecto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
a:=random(1);
timer3.Enabled:=false;
timerb.Enabled:=true;
exit;
end;
end;
case b of
0:
begin
if (key = 'B') or (key = 'b') then
begin
sndPlaySound('C:\JProyect\JWordGuess\sonidos\correcto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer3.Enabled:=true;
timerb.Enabled:=false;
a:=random(1);
exit;
end
else
sndPlaySound('C:\JProyect\JWordGuess\sonidos\incorrecto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer3.Enabled:=true;
timerb.Enabled:=false;
b:=random(1);
end;
end;
end;
y este otro en el evento onchange del edit:
procedure TForm1.Edit1Change(Sender: TObject);
begin
IF Length(Edit1.Text) = 1 then
edit1.SelectAll;
end;
en este codigo estaba pensando poner la letras por separado cada una en un timer direfrente, pero como quiera, el problema mayor lo tengo cuando preciono las teclas siempre dice que es correcto se que es por que estan programadas las teclas a y b. por ejemplo si el programa pregunta si tengo la respuesta, luego dice le respuesta por ejemplo dice (a) y yo preciono (b) tambien dice que es correcto. por favor necesito su ayuda.
primero el programa pregunta si tienes la respuesta:
procedure TForm1.Timer2Timer(Sender: TObject);
begin
sndPlaySound('C:\JProyect\JWordGuess\sonidos\tienelarespuesta.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer2.enabled:=false;
end;
segundo el programa reproduce el sonido de la respuesta esperando que se precione la tecla correcta o incorrecta:
procedure TForm1.Timer3Timer(Sender: TObject);
begin
a:=random(1);
if a = 0 then
sndPlaySound('C:\JProyect\JWordGuess\sonidos\A.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
//timerb.Enabled:=true;
timer3.enabled:=false;
timer3.Interval:=4000;
end;
tercero tengo este codigo en un edit:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
case a of
0:
begin
if (key = 'A') or (key = 'a') then
begin
sndPlaySound('C:\JProyect\JWordGuess\sonidos\correcto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer3.Enabled:=false;
timerb.Enabled:=true;
b:=random(1);
exit;
end
else
sndPlaySound('C:\JProyect\JWordGuess\sonidos\incorrecto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
a:=random(1);
timer3.Enabled:=false;
timerb.Enabled:=true;
exit;
end;
end;
case b of
0:
begin
if (key = 'B') or (key = 'b') then
begin
sndPlaySound('C:\JProyect\JWordGuess\sonidos\correcto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer3.Enabled:=true;
timerb.Enabled:=false;
a:=random(1);
exit;
end
else
sndPlaySound('C:\JProyect\JWordGuess\sonidos\incorrecto.wav',SND_NODEFAULT or SND_SYNC or SND_LOOP);
sndPlaySound(nil,0);
timer3.Enabled:=true;
timerb.Enabled:=false;
b:=random(1);
end;
end;
end;
y este otro en el evento onchange del edit:
procedure TForm1.Edit1Change(Sender: TObject);
begin
IF Length(Edit1.Text) = 1 then
edit1.SelectAll;
end;
en este codigo estaba pensando poner la letras por separado cada una en un timer direfrente, pero como quiera, el problema mayor lo tengo cuando preciono las teclas siempre dice que es correcto se que es por que estan programadas las teclas a y b. por ejemplo si el programa pregunta si tengo la respuesta, luego dice le respuesta por ejemplo dice (a) y yo preciono (b) tambien dice que es correcto. por favor necesito su ayuda.