library GenuineDice;
uses MMSystem;
{$mode objfpc}{$H+}
var
RandomizeAlreadyCalled: Boolean = False;
function Dice: Integer; {$ifdef windows}stdcall{$else}cdecl{$endif};
var
D1, D2: Integer;
begin
// call randomize once and never again.
if not RandomizeAlreadyCalled then begin
Randomize;
RandomizeAlreadyCalled := True;
end;
D1 := Random(6) + 1;
D2 := Random(6) + 1;
Result := D1 * 8 + D2;
// test sound sndPlaySound('D:\applause2.wav', snd_Async or snd_NoDefault);
end;
exports
Dice;
begin
end.
(I ask because in other languages I've learned (VBA and SQL) CASE statements are sometimes frowned on as being inefficient).
I don't know much about the FPC internals, but usually in compiled languages case statements are better for the optimizer because:
(I ask because in other languages I've learned (VBA and SQL) CASE statements are sometimes frowned on as being inefficient).On the contrary: Case structures in compiled languages like Pascal or C/C++ are highly efficient.
FileName := IntToStr(D1 * D2)+.'wav';
That will give you 1.wav … 36.wav
FN:= DiceFileNames[D1 * D2];
So I have thirty-six wav files and I want to play the one that relates to the dice rolls in the above code. So if D1 = 6 and D2 = 4, I'd play 6-4.wav.
function Dice: Integer;Если вам надо проиграть файл именно в формате "6-4.waw", то функция в корне не правильная.