2011-09-10 21:30:22 +00:00
|
|
|
unit mod_tappywords;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2011-11-15 00:03:21 +00:00
|
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
2011-09-15 14:34:06 +00:00
|
|
|
// LCL
|
2011-11-15 00:03:21 +00:00
|
|
|
ExtCtrls,
|
2011-09-15 14:34:06 +00:00
|
|
|
// TappyTux
|
2011-11-15 00:03:21 +00:00
|
|
|
tappyconfig, tappydrawer, tappymodules;
|
2011-09-10 21:30:22 +00:00
|
|
|
|
|
|
|
type
|
2011-09-10 21:42:25 +00:00
|
|
|
|
|
|
|
{ TTappyWords }
|
|
|
|
|
2011-09-10 21:30:22 +00:00
|
|
|
TTappyWords = class(TTappyModule)
|
2011-11-14 00:46:40 +00:00
|
|
|
|
2011-09-15 14:34:06 +00:00
|
|
|
private
|
2011-10-25 14:29:52 +00:00
|
|
|
gameScore : Integer;
|
|
|
|
gameLives : Integer;
|
|
|
|
gameLevel : Integer;
|
|
|
|
gameSLevel : Integer;
|
|
|
|
gameSndFX : Boolean;
|
|
|
|
gameMusic : Boolean;
|
2011-11-14 17:17:47 +00:00
|
|
|
gameQuestionList : TStringList;
|
2011-09-15 14:34:06 +00:00
|
|
|
timerWords: TTimer;
|
|
|
|
procedure HandleOnTimer(Sender: TObject);
|
2011-09-10 21:30:22 +00:00
|
|
|
public
|
2011-09-10 21:42:25 +00:00
|
|
|
constructor Create; override;
|
2011-09-15 14:34:06 +00:00
|
|
|
destructor Destroy; override;
|
2011-09-10 21:42:25 +00:00
|
|
|
procedure TranslateTextsToEnglish; override;
|
|
|
|
procedure TranslateTextsToPortuguese; override;
|
2011-10-25 22:24:00 +00:00
|
|
|
procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); override;
|
2011-11-15 00:03:21 +00:00
|
|
|
procedure createQuestion(); override;
|
2011-10-25 10:21:59 +00:00
|
|
|
procedure Answered(); override;
|
2011-09-15 14:34:06 +00:00
|
|
|
procedure EndGame(); override;
|
2011-09-10 21:30:22 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2011-11-15 00:03:21 +00:00
|
|
|
uses gameplayform;
|
2011-10-24 19:51:13 +00:00
|
|
|
|
2011-09-10 21:42:25 +00:00
|
|
|
{ TTappyWords }
|
|
|
|
|
2011-09-15 14:34:06 +00:00
|
|
|
procedure TTappyWords.HandleOnTimer(Sender: TObject);
|
2011-11-14 00:46:40 +00:00
|
|
|
var
|
|
|
|
i: Integer;
|
2011-09-15 14:34:06 +00:00
|
|
|
begin
|
2011-11-15 00:03:21 +00:00
|
|
|
{for i:= 1 to vTappyTuxDrawer.GetAnimationCount do
|
|
|
|
begin
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).InheritsFrom(TFallingText) then
|
|
|
|
begin
|
|
|
|
vTappyTuxDrawer.GetAnimation(i).;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;}
|
|
|
|
|
2011-11-14 00:46:40 +00:00
|
|
|
for i:= 1 to 5 do
|
2011-10-25 14:29:52 +00:00
|
|
|
begin
|
2011-11-14 00:46:40 +00:00
|
|
|
Questions[i].Top := Questions[i].Top + (5*gameLevel);
|
|
|
|
if ((Questions[i].Top >= 370)) then
|
|
|
|
begin
|
2011-10-25 14:29:52 +00:00
|
|
|
gameLives := gameLives - 1;
|
|
|
|
formTappyTuxGame.Lives.Text := IntToStr(gameLives);
|
|
|
|
if (gameLives = 0) then EndGame();
|
2011-11-14 00:46:40 +00:00
|
|
|
Questions[i].Top:= 24;
|
|
|
|
Questions[i].Text := formTappyTuxGame.Test.Lines.Strings[random(71)];
|
|
|
|
end;
|
2011-11-14 17:24:45 +00:00
|
|
|
end;
|
2011-10-25 14:29:52 +00:00
|
|
|
|
2011-11-15 12:47:57 +00:00
|
|
|
for i:= 0 to vTappyTuxDrawer.GetAnimationCount - 1 do
|
|
|
|
begin
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).InheritsFrom(TFallingText) then
|
|
|
|
begin
|
|
|
|
vTappyTuxDrawer.GetAnimation(i).StartPoint.y:= vTappyTuxDrawer.GetAnimation(i).StartPoint.y + (5*gameLevel);
|
|
|
|
vTappyTuxDrawer.GetAnimation(i).EndPoint.y:= vTappyTuxDrawer.GetAnimation(i).StartPoint.y;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-14 17:24:45 +00:00
|
|
|
vTappyTuxDrawer.HandleAnimationOnTimer();
|
2011-09-15 14:34:06 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-10 21:42:25 +00:00
|
|
|
constructor TTappyWords.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
2011-09-15 14:34:06 +00:00
|
|
|
|
|
|
|
timerWords := TTimer.Create(nil);
|
|
|
|
timerWords.Enabled := False;
|
|
|
|
timerWords.Interval := 1000;
|
|
|
|
timerWords.OnTimer := @HandleOnTimer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TTappyWords.Destroy;
|
|
|
|
begin
|
|
|
|
timerWords.Free;
|
|
|
|
|
|
|
|
inherited Destroy;
|
2011-09-10 21:42:25 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTappyWords.TranslateTextsToEnglish;
|
|
|
|
begin
|
2011-11-14 17:17:47 +00:00
|
|
|
ShortDescription := 'TappyWords';
|
|
|
|
LongDescription := 'A game to learn typing and ortography.'; // Hint: Try to keep looking at the screen instead of the keyboard!
|
2011-09-10 21:42:25 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTappyWords.TranslateTextsToPortuguese;
|
|
|
|
begin
|
2011-11-14 17:17:47 +00:00
|
|
|
ShortDescription := 'TappyWords';
|
|
|
|
LongDescription := 'Um jogo para aprender a digitar e ortografia';
|
2011-09-10 21:42:25 +00:00
|
|
|
end;
|
|
|
|
|
2011-10-25 22:24:00 +00:00
|
|
|
procedure TTappyWords.StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer);
|
2011-11-14 00:46:40 +00:00
|
|
|
var
|
|
|
|
i: Integer;
|
2011-11-14 17:24:45 +00:00
|
|
|
lTuxAnimation: TTappySpriteAnimation;
|
2011-11-15 12:47:57 +00:00
|
|
|
|
2011-09-15 14:34:06 +00:00
|
|
|
begin
|
|
|
|
timerWords.Enabled := True;
|
2011-10-25 14:29:52 +00:00
|
|
|
gameScore := 0;
|
|
|
|
gameLives := 5;
|
|
|
|
gameLevel := Level+1;
|
|
|
|
if (Level < 0) then gameLevel := 1;
|
|
|
|
if (SndFX <= 0) then gameSndFX := true;
|
|
|
|
if (SndFX = 1) then gameSndFX := false;
|
|
|
|
if (Music <= 0) then gameMusic := true;
|
|
|
|
if (Music = 1) then gameMusic := false;
|
|
|
|
gameSLevel := gameLevel;
|
|
|
|
|
2011-11-15 12:47:57 +00:00
|
|
|
if QuestionList < 0 then QuestionList := 0;
|
2011-11-14 17:17:47 +00:00
|
|
|
gameQuestionList := TStringList.Create;
|
2011-11-15 13:37:10 +00:00
|
|
|
gameQuestionList.LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images'+PathDelim+'modules'+PathDelim+'tappywords'+PathDelim+'0.txt');
|
|
|
|
//gameQuestionList.LoadFromFile('C:/'+IntToStr(QuestionList)+'.txt');
|
2011-11-14 17:17:47 +00:00
|
|
|
|
2011-10-25 14:29:52 +00:00
|
|
|
formTappyTuxGame.Answer.ReadOnly := false;
|
|
|
|
formTappyTuxGame.GameOver.Visible := false;
|
|
|
|
formTappyTuxGame.Yes.Visible := false;
|
|
|
|
formTappyTuxGame.No.Visible := false;
|
|
|
|
formTappyTuxGame.Level.Text := IntToStr(gameLevel);
|
|
|
|
formTappyTuxGame.Score.Text := IntToStr(gameScore);
|
|
|
|
formTappyTuxGame.Lives.Text := IntToStr(gameLives);
|
2011-10-24 19:51:13 +00:00
|
|
|
|
2011-11-14 00:46:40 +00:00
|
|
|
for i:= 1 to 5 do
|
|
|
|
begin
|
2011-11-15 12:47:57 +00:00
|
|
|
//Questions[i].Text := formTappyTuxGame.Test.Lines.Strings[random(71)];
|
|
|
|
Questions[i].Text := gameQuestionList[random(gameQuestionList.Count - 1)];
|
2011-11-14 17:24:45 +00:00
|
|
|
end;
|
2011-10-25 22:24:00 +00:00
|
|
|
|
2011-11-15 00:03:21 +00:00
|
|
|
// Animations Creation
|
2011-11-14 17:24:45 +00:00
|
|
|
lTuxAnimation := TTappySpriteAnimation.Create;
|
|
|
|
lTuxAnimation.IsInfinite := True;
|
2011-11-15 12:47:57 +00:00
|
|
|
lTuxAnimation.StartPoint := Point(250, 328);
|
2011-11-14 17:24:45 +00:00
|
|
|
lTuxAnimation.EndPoint := lTuxAnimation.StartPoint;
|
|
|
|
SetLength(lTuxAnimation.Bitmaps, 6);
|
|
|
|
lTuxAnimation.Bitmaps[0] := TPortableNetworkGraphic.Create;
|
|
|
|
lTuxAnimation.Bitmaps[0].LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'tux_1.png');
|
|
|
|
lTuxAnimation.Bitmaps[1] := TPortableNetworkGraphic.Create;
|
|
|
|
lTuxAnimation.Bitmaps[1].LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'tux_2.png');
|
|
|
|
lTuxAnimation.Bitmaps[2] := TPortableNetworkGraphic.Create;
|
|
|
|
lTuxAnimation.Bitmaps[2].LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'tux_3.png');
|
|
|
|
lTuxAnimation.Bitmaps[3] := TPortableNetworkGraphic.Create;
|
|
|
|
lTuxAnimation.Bitmaps[3].LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'tux_4.png');
|
|
|
|
lTuxAnimation.Bitmaps[4] := lTuxAnimation.Bitmaps[2];
|
|
|
|
lTuxAnimation.Bitmaps[5] := lTuxAnimation.Bitmaps[1];
|
|
|
|
vTappyTuxDrawer.AddAnimation(lTuxAnimation);
|
2011-11-15 00:03:21 +00:00
|
|
|
|
|
|
|
for i:= 1 to 5 do
|
|
|
|
begin
|
|
|
|
CreateQuestion();
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTappyWords.CreateQuestion();
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
xAux: Integer;
|
|
|
|
yAux: Integer;
|
|
|
|
snowmanAnimation: TFallingText;
|
|
|
|
existenceAux1, existenceAux2, existenceAux3, existenceAux4, existenceAux5: boolean;
|
|
|
|
|
|
|
|
begin
|
|
|
|
existenceAux1:= false;
|
|
|
|
existenceAux2:= false;
|
|
|
|
existenceAux3:= false;
|
|
|
|
existenceAux4:= false;
|
|
|
|
existenceAux5:= false;
|
|
|
|
xAux:=5;
|
|
|
|
yAux:=5;
|
|
|
|
snowmanAnimation := TFallingText.Create;
|
|
|
|
snowmanAnimation.IsInfinite := True;
|
|
|
|
|
2011-11-15 12:47:57 +00:00
|
|
|
if True then
|
2011-11-15 00:03:21 +00:00
|
|
|
begin
|
2011-11-15 12:47:57 +00:00
|
|
|
for i:= 0 to vTappyTuxDrawer.GetAnimationCount - 1 do
|
|
|
|
begin
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).InheritsFrom(TFallingText) then
|
2011-11-15 00:03:21 +00:00
|
|
|
begin
|
2011-11-15 12:47:57 +00:00
|
|
|
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 5 then existenceAux1 := True;
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 108 then existenceAux2 := True;
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 211 then existenceAux3 := True;
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 314 then existenceAux4 := True;
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 427 then existenceAux5 := True;
|
|
|
|
if vTappyTuxDrawer.GetAnimation(i).StartPoint.y > yAux then
|
|
|
|
begin
|
|
|
|
xAux := vTappyTuxDrawer.GetAnimation(i).StartPoint.x;
|
|
|
|
yAux := vTappyTuxDrawer.GetAnimation(i).StartPoint.y;
|
|
|
|
end;
|
2011-11-15 00:03:21 +00:00
|
|
|
end;
|
2011-11-15 12:47:57 +00:00
|
|
|
end;
|
2011-11-15 00:03:21 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
if existenceAux1 = false then xAux := 5
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if existenceAux2 = false then xAux := 108
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if existenceAux3 = false then xAux := 211
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if existenceAux4 = false then xAux := 314
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if existenceAux5 = false then xAux := 427
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
snowmanAnimation.StartPoint := Point(xAux, 5);
|
|
|
|
snowmanAnimation.EndPoint := snowmanAnimation.StartPoint;
|
|
|
|
snowmanAnimation.Bitmap := TPortableNetworkGraphic.Create;
|
2011-11-15 12:47:57 +00:00
|
|
|
snowmanAnimation.QuestionText:= formTappyTuxGame.Test.Lines.Strings[random(71)];
|
2011-11-15 00:03:21 +00:00
|
|
|
snowmanAnimation.Bitmap.LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'snowman.png');
|
|
|
|
vTappyTuxDrawer.AddAnimation(snowmanAnimation);
|
|
|
|
|
2011-10-25 14:29:52 +00:00
|
|
|
end;
|
2011-09-15 14:34:06 +00:00
|
|
|
|
2011-10-25 10:21:59 +00:00
|
|
|
procedure TTappyWords.Answered;
|
2011-11-14 00:46:40 +00:00
|
|
|
var
|
|
|
|
i: Integer;
|
2011-10-25 10:21:59 +00:00
|
|
|
begin
|
2011-11-14 00:46:40 +00:00
|
|
|
for i:= 1 to 5 do
|
2011-10-25 14:29:52 +00:00
|
|
|
begin
|
2011-11-14 00:46:40 +00:00
|
|
|
if (formTappyTuxGame.Answer.Text = Questions[i].Text) then
|
|
|
|
begin
|
|
|
|
Questions[i].Top := 24;
|
2011-11-15 12:47:57 +00:00
|
|
|
//Questions[i].Text := formTappyTuxGame.Test.Lines.Strings[random(71)];
|
|
|
|
Questions[i].Text := gameQuestionList[random(gameQuestionList.Count - 1)];
|
2011-10-25 14:29:52 +00:00
|
|
|
gameScore := gameScore +1;
|
|
|
|
gameLevel := (gameScore div 20) + gameSLevel;
|
|
|
|
formTappyTuxGame.Score.Text := IntToStr(gameScore);
|
|
|
|
formTappyTuxGame.Level.Text := IntToStr(gameLevel);
|
2011-11-14 00:46:40 +00:00
|
|
|
end;
|
|
|
|
end
|
2011-10-25 10:21:59 +00:00
|
|
|
|
|
|
|
end;
|
|
|
|
|
2011-09-15 14:34:06 +00:00
|
|
|
procedure TTappyWords.EndGame;
|
2011-11-15 00:03:21 +00:00
|
|
|
var
|
2011-11-15 12:47:57 +00:00
|
|
|
i : Integer;
|
2011-11-15 00:03:21 +00:00
|
|
|
gameOverScreen: TTappySpriteAnimation;
|
|
|
|
continueBtn: TButton;
|
|
|
|
exitBtn: TButton;
|
2011-09-15 14:34:06 +00:00
|
|
|
begin
|
|
|
|
timerWords.Enabled := False;
|
2011-10-25 14:29:52 +00:00
|
|
|
formTappyTuxGame.Answer.ReadOnly := true;
|
2011-11-15 00:03:21 +00:00
|
|
|
|
|
|
|
//gameOverScreen := TTappySpriteAnimation.Create;
|
|
|
|
//gameOverScreen.IsInfinite := True;
|
|
|
|
//gameOverScreen.StartPoint := Point(90, 150);
|
|
|
|
//gameOverScreen.EndPoint := gameOverScreen.StartPoint;
|
|
|
|
//SetLength(gameOverScreen.Bitmaps, 1);
|
|
|
|
//gameOverScreen.Bitmaps[0] := TPortableNetworkGraphic.Create;
|
|
|
|
//gameOverScreen.Bitmaps[0].LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'gameover.png');
|
|
|
|
//vTappyTuxDrawer.AddAnimation(gameOverScreen);
|
|
|
|
|
2011-11-15 12:47:57 +00:00
|
|
|
for i:= 1 to vTappyTuxDrawer.GetAnimationCount - 1 do
|
|
|
|
begin
|
|
|
|
vTappyTuxDrawer.GetAnimation(i).Destroy;
|
|
|
|
end;
|
|
|
|
|
2011-10-25 14:29:52 +00:00
|
|
|
formTappyTuxGame.GameOver.Visible := true;
|
|
|
|
formTappyTuxGame.Yes.Visible := true;
|
|
|
|
formTappyTuxGame.No.Visible := true;
|
2011-09-15 14:34:06 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-10 21:42:25 +00:00
|
|
|
initialization
|
|
|
|
AddModule(TTappyWords.Create);
|
2011-09-10 21:30:22 +00:00
|
|
|
end.
|
|
|
|
|