کد:
type
TWordGame = class
public
function GetSecretWordID(aDifficultyLevel: Integer): Integer;
function GetSecretWord(aDifficultyLevel: Integer): string;
function GetLastWinner(aDifficultyLevel: Integer): string;
function GetLastFoundSecretWord(aDifficultyLevel: Integer): string;
function AddNewSecretWord(aDifficultyLevel: Integer): Integer;
function AddNewSuggestionWord(aUserID, agsID: Integer; aSuggestionWord: string;
aPoint1, aPoint2, aDifficultyLevel: Integer): boolean;
function GetWordGameData(aDifficultyLevel: Integer): TADOQuery;
end;
کد:
function TWordGame.GetSecretWordID(aDifficultyLevel: Integer): Integer;
begin
Result := fOpenReturnInt('select gsID from GameSecrets where IsFound = 0 and DifficultyLevel = ' +
IntToStr(aDifficultyLevel));
end;
function TWordGame.GetSecretWord(aDifficultyLevel: Integer): string;
begin
Result := fOpenReturnStr('SELECT Word FROM GameSecrets GS inner join Words' + IntToStr(aDifficultyLevel) +
' W on GS.SecretWordID = W.wID where IsFound = 0 and DifficultyLevel = ' +
IntToStr(aDifficultyLevel));
end;
function TWordGame.GetLastWinner(aDifficultyLevel: Integer): string;
begin
Result := fOpenReturnStr('Select FullName from GameSecrets GS '
+ ' inner join GameWords GW on GW.gsID = GS.gsID and GW.DifficultyLevel = GS.DifficultyLevel '
+ ' inner join Users U on U.UserID = GW.UserID '
+ ' where GW.Point1 = GW.Point2 and GW.Point2 = GW.DifficultyLevel and GW.DifficultyLevel = ' +
IntToStr(aDifficultyLevel) + ' Order by GW.gwID Desc ');
end;
function TWordGame.GetLastFoundSecretWord(aDifficultyLevel: Integer): string;
begin
Result := fOpenReturnStr('Select SuggestionWord from GameSecrets GS '
+ ' inner join GameWords GW on GW.gsID = GS.gsID and GW.DifficultyLevel = GS.DifficultyLevel '
+ ' inner join Users U on U.UserID = GW.UserID '
+ ' where GW.Point1 = GW.Point2 and GW.Point2 = GW.DifficultyLevel and GW.DifficultyLevel = ' +
IntToStr(aDifficultyLevel) + ' Order by GW.gwID Desc ');
end;
function TWordGame.AddNewSecretWord(aDifficultyLevel: Integer): Integer;
begin
Result := fOpenReturnInt('declare @Result int;'
+ ' Exec sp_AddNewSecretWord ' + IntToStr(aDifficultyLevel) + ' , @Result output'
+ ' Select @Result;');
end;
function TWordGame.AddNewSuggestionWord(aUserID, agsID: Integer; aSuggestionWord: string;
aPoint1, aPoint2, aDifficultyLevel: Integer): boolean;
var
SuggestedCount: Integer;
aDataSet : TADOQuery;
begin
SuggestedCount := 0;
aDataSet := fOpen('Select SuggestionWord, Count(*) from GameWords '
+ ' where SuggestionWord = N' + QuotedStr(aSuggestionWord) + ' and gsid = ' + IntToStr(agsID)
+ ' Group By SuggestionWord ');
SuggestedCount := aDataSet.Fields[1].AsInteger;
FreeAndNil(aDataSet);
if SuggestedCount = 0 then
fRun('Exec sp_AddNewSuggestionWord ' + IntToStr(aUserID) + ',N' + QuotedStr(aSuggestionWord) + ',' +
IntToStr(aPoint1) +
',' + IntToStr(aPoint2) + ',' + IntToStr(aDifficultyLevel));
Result := SuggestedCount = 0;
end;
function TWordGame.GetWordGameData(aDifficultyLevel: Integer): TADOQuery;
begin
Result := fOpen('Select U.FullName, GW.SuggestionWord, Cast(Point1 as Varchar(1))+'' + ''+Cast(Point2 as Varchar(1)) as Point from GameWords GW '
+ 'inner join GameSecrets GS on GS.gsID = GW.gsID and GS.DifficultyLevel = GW.DifficultyLevel '
+ 'inner join Users U on GW.UserID = U.UserID '
+ 'where GS.IsFound = 0 and GS.DifficultyLevel = ' + IntToStr(aDifficultyLevel)
+ ' Order By GW.gwID Desc ');
end;
علاقه مندي ها (Bookmarks)