}
//uFruitCollect
var
GameForm : TclGameForm;
PanelTop,PanelCenter : TclProPanel;
ImageBack,ImageTime,ImageScore,ImageNutrients,ImageBesinTikla,
ImageBasket,ImageLeft,ImageRight,ImageY1,ImageY2,ImageAnm: TClProImage;
LblPlayerName,LblTime,LblScore,LblImageY1,LblImageY2,LblConnection,LblEndScore : TClProLabel;
Score,Time,RandomHealthyIndex,RandomUnHealthyIndex,Distance1,Distance2,
PlayerDirection,ImageY1Speed,ImageY2Speed,PlayerSpeed: Integer;
TimerGame , TimerClock,sendTimer : TCLTimer;
MqttGame : TclMQTT;
AnimationStart : Boolean;
Vibrate : TclDeviceManager;
FormExe : TclGameForm;
UsersList : TClProListView;
DesignerListPanel : TClProListViewDesignerPanel;
LabelConnection : TClProLabel;
BtnQueue,BtnPlayerScore,BtnPlayerName: TClProButton;
MqttScreen : TclMQTT;
Qry : TCLJSONQuery;
NameArray,GuidArray,ScoreArray,ListFoods : TclArrayString;
ImgBack : TClProImage;
JsonStr , GelenIsim , GelenGUID : String;
CapturedScore: String;
ListContainer : TclStringList;
void CloseForm;
{
CallerForm.clShow;
ButtonPlay.Enabled = True;
TClProButton(GameForm.clFindComponent('BtnGoBack')).Click;
}
void OpenFoodImage;
{
if(ImageNutrients.Visible == False)
{
ImageNutrients.Visible = true;
}
else
{
ImageNutrients.Visible = False;
}
}
void MqttGameChanged;
{
if not (MqttGame.Connected)
{
MqttGame.Connect;
LblConnection.Text = 'Not Connected';
LblConnection.clProSettings.FontColor = clAlphaColor.clHexToColor('#DA1212');
LblConnection.SetclProSettings(LblConnection.clProSettings);
}
else
{
LblConnection.Text = 'Connected';
LblConnection.clProSettings.FontColor = clAlphaColor.clHexToColor('#00A9FF');
LblConnection.SetclProSettings(LblConnection.clProSettings);
}
}
void FoodPoint;
{
Case RandomHealthyIndex Of
{
0:
{
LblImageY1.Text = '2';
}
1:
{
LblImageY1.Text = '4';
}
2:
{
LblImageY1.Text = '6';
}
3:
{
LblImageY1.Text = '8';
}
4:
{
LblImageY1.Text = '10';
}
5:
{
LblImageY1.Text = '12';
}
6:
{
LblImageY1.Text = '14';
}
7:
{
LblImageY1.Text = '16';
}
8:
{
LblImageY1.Text = '18';
}
9:
{
LblImageY1.Caption = '20';
}
}
Case RandomUnHealthyIndex Of
{
10:
{
LblImageY2.Caption = '-2';
}
11:
{
LblImageY2.Caption = '-4';
}
12:
{
LblImageY2.Caption = '-6';
}
13:
{
LblImageY2.Caption = '-8';
}
14:
{
LblImageY2.Caption = '-10';
}
15:
{
LblImageY2.Caption = '-12';
}
16:
{
LblImageY2.Caption = '-14';
}
17:
{
LblImageY2.Text = '-16';
}
18:
{
LblImageY2.Text = '-18';
}
19:
{
LblImageY2.Text = '-20';
}
}
}
void FillBasket;
{
if(TimerClock.Enabled == true)
{
if ((Score > 0) && (Score < 150))
{
GameForm.setImage(ImageBasket , ' https://clomosy.com/demos/foodBasket.png" rel="nofollow - https://clomosy.com/demos/foodBasket.png ');
TimerGame.Interval = 5;
LblScore.clProSettings.FontSize = 20;
LblScore.SetclProSettings(LblScore.clProSettings);
}
if ((Score > 150) &&(Score < 300))
{
GameForm.SetImage(ImageBasket , ' https://clomosy.com/demos/foodBasket2.png" rel="nofollow - https://clomosy.com/demos/foodBasket2.png ');
TimerGame.Interval = 3;
ImageY1Speed = 7;
ImageY2Speed = 6;
PlayerSpeed = 7;
}
if(Score > 300)
{
TimerGame.Interval = 1;
GameForm.SetImage(ImageBasket , ' https://clomosy.com/demos/foodBasket3.png" rel="nofollow - https://clomosy.com/demos/foodBasket3.png ');
if ((Score > 300) && (Score < 450))
{
ImageY1Speed = 8;
ImageY2Speed = 7;
PlayerSpeed = 8;
ImageY1.Width = TForm(GameForm).ClientWidth / 6;
ImageY1.Height = TForm(GameForm).ClientHeight / 12;
ImageY2.Width = TForm(GameForm).ClientWidth / 5;
ImageY2.Height = TForm(GameForm).ClientHeight / 10;
}
if ((Score > 450) && (Score < 600))
{
ImageY1Speed = 8;
ImageY2Speed = 9;
PlayerSpeed = 9;
ImageBasket.Width = TForm(GameForm).ClientWidth / 3;
}
if ((Score > 600) && (Score < 750))
{
ImageY1Speed = 9;
ImageY2Speed = 7;
PlayerSpeed = 9
}
if ((Score > 750) && (Score < 1000))
{
ImageY1Speed = 10;
ImageY2Speed = 8;
PlayerSpeed = 10;
}
if(Score > 1000)
{
ImageY1Speed = 11;
ImageY2Speed = 9;
PlayerSpeed = 10;
LblScore.clProSettings.FontSize = 18;
if ((Score > 1000)&&(Score < 10000))
{
LblScore.clProSettings.FontSize = 16;
}
else if ((Score > 10000)&&(Score < 100000))
{
LblScore.clProSettings.FontSize = 14;
}
LblScore.SetclProSettings(LblScore.clProSettings);
}
}
}
}
void ScoreAnimation;
{
if(AnimationStart == true)
{
ImageAnm.Visible = False;
if(ImageAnm.Position.Y < 50)
{
ImageAnm.Visible = False;
ImageAnm.Position.Y = 250;
AnimationStart = False;
}
else
{
ImageAnm.Visible = true;
ImageAnm.Position.Y = ImageAnm.Position.Y - 5;
}
}
}
void FoodCollection;
{
Distance1 = Sqrt(Sqr(ImageBasket.Position.X - ImageY1.Position.X) + Sqr(ImageBasket.Position.Y - ImageY1.Position.Y));
Distance2 = Sqrt(Sqr(ImageBasket.Position.X - ImageY2.Position.X) + Sqr(ImageBasket.Position.Y - ImageY2.Position.Y));
if ((Distance1 > 0) && (Distance1 <= 45))
{
AnimationStart = true;
Case RandomHealthyIndex Of
{
0:
{
Score = Score + 2;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/cheese.png" rel="nofollow - https://clomosy.com/demos/cheese.png ');
}
1:
{
Score = Score + 4;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/meat.png" rel="nofollow - https://clomosy.com/demos/meat.png ');
}
2:
{
Score = Score + 6;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/milk.png" rel="nofollow - https://clomosy.com/demos/milk.png ');
}
3:
{
Score = Score + 8;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/fish.png" rel="nofollow - https://clomosy.com/demos/fish.png ');
}
4:
{
Score = Score + 10;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/sweetcorn.png" rel="nofollow - https://clomosy.com/demos/sweetcorn.png ');
}
5:
{
Score = Score + 12;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/watermelon.png" rel="nofollow - https://clomosy.com/demos/watermelon.png ');
}
6:
{
Score = Score + 14;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/apple.png" rel="nofollow - https://clomosy.com/demos/apple.png ');
}
7:
{
Score = Score + 16;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/carrot.png" rel="nofollow - https://clomosy.com/demos/carrot.png ');
}
8:
{
Score = Score + 18;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/strawberry.png" rel="nofollow - https://clomosy.com/demos/strawberry.png ');
}
9:
{
Score = Score + 20;
LblScore.Text = IntToStr(Score);
GameForm.setImage(ImageAnm , ' https://clomosy.com/demos/aubergine.png" rel="nofollow - https://clomosy.com/demos/aubergine.png ');
}
}
ImageY1.Position.Y = 50;
ImageY1.Position.X = clMath.GenerateRandom(60 , TForm(GameForm).ClientWidth - 60);
RandomHealthyIndex = clMath.GenerateRandom(0,9);
GameForm.SetImage(ImageY1 ,ListFoods.GetItem(RandomHealthyIndex));
FillBasket;
}
if ((Distance2 > -10) && (Distance2 <= 45))
{
AnimationStart = true;
Case RandomUnHealthyIndex Of
{
10:
{
Score = Score - 2;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/noddle.png" rel="nofollow - https://clomosy.com/demos/noddle.png ');
}
11:
{
Score = Score - 4;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/toast.png" rel="nofollow - https://clomosy.com/demos/toast.png ');
}
12:
{
Score = Score - 6;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/hamburger.png" rel="nofollow - https://clomosy.com/demos/hamburger.png ');
}
13:
{
Score = Score - 8;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/chips.png" rel="nofollow - https://clomosy.com/demos/chips.png ');
}
14:
{
Score = Score - 10;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/fruitJuice.png" rel="nofollow - https://clomosy.com/demos/fruitJuice.png ');
}
15:
{
Score = Score - 12;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/iceCream.png" rel="nofollow - https://clomosy.com/demos/iceCream.png ');
}
16:
{
Score = Score - 14;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/chocolate.png" rel="nofollow - https://clomosy.com/demos/chocolate.png ');
}
17:
{
Score = Score - 16;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/pie.png" rel="nofollow - https://clomosy.com/demos/pie.png ');
}
18:
{
Score = Score - 18;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/cake.png" rel="nofollow - https://clomosy.com/demos/cake.png ');
}
19:
{
Score = Score - 20;
LblScore.Text = IntToStr(Score);
GameForm.SetImage(ImageAnm , ' https://clomosy.com/demos/topitop.png" rel="nofollow - https://clomosy.com/demos/topitop.png ');
}
}
if(Score < 0)
{
Score = 0;
LblScore.Text = IntToStr(Score);
}
ImageY2.Position.Y = 50;
ImageY2.Position.X = clMath.GenerateRandom(60 , TForm(GameForm).ClientWidth - 60);
RandomUnHealthyIndex = clMath.GenerateRandom(10,20);
GameForm.SetImage(ImageY2 ,ListFoods.GetItem(RandomUnHealthyIndex));
FillBasket;
}
}
void CreateGameForm
{
GameForm = TclGameForm.Create(Self);
GameForm.SetFormBGImage(' https://clomosy.com/demos/FooodBg.png" rel="nofollow - https://clomosy.com/demos/FooodBg.png ');
GameForm.AddNewEvent(GameForm,tbeOnFormCloseQuery,'CloseForm');
Vibrate = TclDeviceManager.Create;
Time = 60;
Score = 0;
ImageY1Speed = 6;
ImageY2Speed = 5;
PlayerSpeed = 6;
ListFoods = TclArrayString.Create;
//Sağlıklılar
ListFoods.Add(' https://clomosy.com/demos/cheese.png" rel="nofollow - https://clomosy.com/demos/cheese.png ');
ListFoods.Add(' https://clomosy.com/demos/meat.png" rel="nofollow - https://clomosy.com/demos/meat.png ');
ListFoods.Add(' https://clomosy.com/demos/milk.png" rel="nofollow - https://clomosy.com/demos/milk.png ');
ListFoods.Add(' https://clomosy.com/demos/fish.png" rel="nofollow - https://clomosy.com/demos/fish.png ');
ListFoods.Add(' https://clomosy.com/demos/sweetcorn.png" rel="nofollow - https://clomosy.com/demos/sweetcorn.png ');
ListFoods.Add(' https://clomosy.com/demos/watermelon.png" rel="nofollow - https://clomosy.com/demos/watermelon.png ');
ListFoods.Add(' https://clomosy.com/demos/apple.png" rel="nofollow - https://clomosy.com/demos/apple.png ');
ListFoods.Add(' https://clomosy.com/demos/carrot.png" rel="nofollow - https://clomosy.com/demos/carrot.png ');
ListFoods.Add(' https://clomosy.com/demos/strawberry.png" rel="nofollow - https://clomosy.com/demos/strawberry.png ');
ListFoods.Add(' https://clomosy.com/demos/aubergine.png" rel="nofollow - https://clomosy.com/demos/aubergine.png ');
//Sağlıksızlar :
ListFoods.Add(' https://clomosy.com/demos/noddle.png" rel="nofollow - https://clomosy.com/demos/noddle.png ');
ListFoods.Add(' https://clomosy.com/demos/toast.png" rel="nofollow - https://clomosy.com/demos/toast.png ');
ListFoods.Add(' https://clomosy.com/demos/hamburger.png" rel="nofollow - https://clomosy.com/demos/hamburger.png ');
ListFoods.Add(' https://clomosy.com/demos/chips.png" rel="nofollow - https://clomosy.com/demos/chips.png ');
ListFoods.Add(' https://clomosy.com/demos/fruitJuice.png" rel="nofollow - https://clomosy.com/demos/fruitJuice.png ');
ListFoods.Add(' https://clomosy.com/demos/iceCream.png" rel="nofollow - https://clomosy.com/demos/iceCream.png ');
ListFoods.Add(' https://clomosy.com/demos/chocolate.png" rel="nofollow - https://clomosy.com/demos/chocolate.png ');
ListFoods.Add(' https://clomosy.com/demos/pie.png" rel="nofollow - https://clomosy.com/demos/pie.png ');
ListFoods.Add(' https://clomosy.com/demos/cake.png" rel="nofollow - https://clomosy.com/demos/cake.png ');
ListFoods.Add(' https://clomosy.com/demos/topitop.png" rel="nofollow - https://clomosy.com/demos/topitop.png ');
RandomHealthyIndex = clMath.GenerateRandom(0 , 9);
RandomUnHealthyIndex = clMath.GenerateRandom(10,20);
PanelTop = GameForm.AddNewProPanel(GameForm , 'PanelTop');
PanelTop.Align = alMostTop;
PanelTop.Margins.Left = 10;
PanelTop.Margins.Right = 10;
PanelTop.Margins.top = -10;
PanelTop.Height = TForm(GameForm).ClientHeight / 6;
PanelCenter = GameForm.AddNewProPanel(GameForm , 'PanelCenter');
PanelCenter.Align = alCenter;
PanelCenter.Margins.Left = 10;
PanelCenter.Margins.Right = 10;
PanelCenter.Margins.Top = 250;
PanelCenter.Height = TForm(GameForm).ClientHeight / 8;
PanelCenter.Width = TForm(GameForm).ClientWidth;
ImageBack = GameForm.AddNewProImage(PanelTop, 'ImageBack');
ImageBack.Align = alMostLeft;
ImageBack.Width = TForm(GameForm).ClientWidth / 7;
ImageBack.Height = TForm(GameForm).ClientHeight / 7;
ImageBack.Margins.Left = 5;
GameForm.SetImage(ImageBack , ' https://clomosy.com/demos/XoXback.png" rel="nofollow - https://clomosy.com/demos/XoXback.png ');
GameForm.AddNewEvent(ImageBack , tbeOnClick , 'CloseForm');
ImageNutrients = GameForm.AddNewProImage(GameForm , 'ImageNutrients');
ImageNutrients.Align = alClient;
GameForm.SetImage(ImageNutrients , ' https://clomosy.com/demos/FoodPointsTable.png" rel="nofollow - https://clomosy.com/demos/FoodPointsTable.png ');
ImageNutrients.Margins.Left = 20;
ImageNutrients.Margins.Right = 20;
ImageNutrients.Visible = False;
ImageNutrients.clProSettings.IsFill = True;
ImageNutrients.clProSettings.IsRound = True;
ImageNutrients.clProSettings.RoundHeight = 10;
ImageNutrients.clProSettings.RoundWidth = 10;
ImageNutrients.SetclProSettings(ImageNutrients.clProSettings);
GameForm.AddNewEvent(ImageNutrients , tbeOnClick , 'OpenFoodImage');
ImageBesinTikla = GameForm.AddNewProImage(PanelTop , 'ImageBesinTikla');
ImageBesinTikla.Align = alMostRight;
GameForm.SetImage(ImageBesinTikla , ' https://clomosy.com/demos/RopeQuestionMark.png" rel="nofollow - https://clomosy.com/demos/RopeQuestionMark.png ');
ImageBesinTikla.Width = PanelTop.Width / 8;
ImageBesinTikla.Height = PanelTop.Height / 4;
GameForm.AddNewEvent(ImageBesinTikla , tbeOnClick , 'OpenFoodImage');
ImageBasket = GameForm.AddNewProImage(GameForm , 'ImageBasket');
ImageBasket.Align = alNone;
ImageBasket.Position.Y = TForm(GameForm).ClientHeight - 100;
ImageBasket.Position.X = TForm(GameForm).ClientWidth / 3;
ImageBasket.Width = TForm(GameForm).ClientWidth / 4;
ImageBasket.Height = TForm(GameForm).ClientHeight / 8;
GameForm.SetImage(ImageBasket , ' https://clomosy.com/demos/foodBasket.png" rel="nofollow - https://clomosy.com/demos/foodBasket.png ');
clRTMethod(ImageBasket, 'BringToFront');
ImageTime = GameForm.AddNewProImage(PanelTop , 'ImageTime');
GameForm.SetImage(ImageTime , ' https://clomosy.com/demos/foodInformationBox.png" rel="nofollow - https://clomosy.com/demos/foodInformationBox.png ');
ImageTime.Align = alCenter;
ImageTime.Width = PanelTop.Width / 3.25;
ImageTime.Height = PanelTop.Height;
ImageTime.Margins.Right = 25;
ImageScore = GameForm.AddNewProImage(PanelTop , 'ImageScore');
GameForm.SetImage(ImageScore , ' https://clomosy.com/demos/foodInformationPointBox.png" rel="nofollow - https://clomosy.com/demos/foodInformationPointBox.png ');
ImageScore.Align = alMostRight;
ImageScore.Width = PanelTop.Width / 6;
ImageScore.Height = PanelTop.Height;
ImageScore.Margins.Right = 25;
ImageLeft = GameForm.AddNewProImage(PanelCenter , 'ImageLeft');
ImageLeft.Align = alLeft;
ImageLeft.Margins.Left = 10;
GameForm.SetImage(ImageLeft , ' https://clomosy.com/demos/RopeLeft.png" rel="nofollow - https://clomosy.com/demos/RopeLeft.png ');
GameForm.AddNewEvent(ImageLeft , tbeOnClick , 'PlayerMoveLeft');
ImageRight = GameForm.AddNewProImage(PanelCenter , 'ImageRight');
ImageRight.Align = alRight;
ImageRight.Margins.Right = 10;
GameForm.SetImage(ImageRight , ' https://clomosy.com/demos/RopeRight.png" rel="nofollow - https://clomosy.com/demos/RopeRight.png ');
GameForm.AddNewEvent(ImageRight , tbeOnClick , 'PlayerMoveRight');
ImageY1 = GameForm.AddNewProImage(GameForm , 'ImageY1');
ImageY1.Align = alNone;
ImageY1.Width = TForm(GameForm).ClientWidth / 6;
ImageY1.Height = TForm(GameForm).ClientHeight / 12;
ImageY1.Position.Y = 50;
clRTMethod(ImageY1, 'SendToBack');
RandomHealthyIndex = clMath.GenerateRandom(0,9);
GameForm.SetImage(ImageY1 , ListFoods.GetItem(RandomHealthyIndex));
ImageY2 = GameForm.AddNewProImage(GameForm , 'ImageY2');
ImageY2.Align = alNone;
ImageY2.Width = TForm(GameForm).ClientWidth / 6;
ImageY2.Height = TForm(GameForm).ClientHeight / 12;
ImageY2.Position.Y = 50;
clRTMethod(ImageY2, 'SendToBack');
RandomUnHealthyIndex = clMath.GenerateRandom(10,20);
GameForm.SetImage(ImageY2, ListFoods.GetItem(RandomUnHealthyIndex));
LblTime = GameForm.AddNewProLabel(ImageTime , 'LblTime' , ''+IntToStr(Time)+'');
LblTime.Align = alCenter;
LblTime.clProSettings.TextSettings.Font.Style = [fsBold];
LblTime.clProSettings.FontSize = 25;
LblTime.clProSettings.FontHorzAlign = palcenter;
LblTime.clProSettings.FontVertAlign = palcenter;
LblTime.SetclProSettings(LblTime.clProSettings);
LblScore = GameForm.AddNewProLabel(ImageScore , 'LblScore' , ''+IntToStr(Score)+'');
LblScore.Align = alCenter;
LblScore.Properties.AutoSize = True;
LblScore.clProSettings.TextSettings.Font.Style = [fsBold];
LblScore.clProSettings.FontSize = 20;
LblScore.SetclProSettings(LblScore.clProSettings);
TimerGame = GameForm.AddNewTimer(GameForm , 'TimerGame' , 4);
TimerGame.Interval = 5;
TimerGame.Enabled = True;
GameForm.AddNewEvent(TimerGame , tbeOnTimer , 'GameOperations');
TimerClock = GameForm.AddNewTimer(GameForm , 'TimerClock' , 1000);
GameForm.AddNewEvent(TimerClock , tbeOnTimer , 'TimePass');
TimerClock.Enabled = True;
LblConnection = GameForm.AddNewProLabel(GameForm , 'LblConnection' , 'NOT CONNECTED');
LblConnection.Align = alMostTop;
LblConnection.clProSettings.FontSize = 20;
LblConnection.clProSettings.TextSettings.Font.Style = [fsBold];
LblConnection.clProSettings.FontColor = clAlphaColor.clHexToColor('#FFFFFF');
LblConnection.clProSettings.FontHorzAlign = palcenter;
LblConnection.SetclProSettings(LblConnection.clProSettings);
LblPlayerName = GameForm.AddNewProLabel(ImageBasket , 'LblPlayerName' , Clomosy.AppUserDisplayName);
LblPlayerName.Align = alCenter;
LblPlayerName.Margins.Bottom = 100;
LblPlayerName.clProSettings.FontSize = 20;
LblPlayerName.clProSettings.TextSettings.Font.Style = [fsBold];
LblPlayerName.clProSettings.FontColor = clAlphaColor.clHexToColor('#FFFFFF');
LblPlayerName.clProSettings.FontHorzAlign = palcenter;
LblPlayerName.clProSettings.FontVertAlign = palcenter;
LblPlayerName.SetclProSettings(LblPlayerName.clProSettings);
LblImageY1 = GameForm.AddNewProLabel(ImageY1 , 'LblImageY1' , '');
LblImageY1.Align = alCenter;
LblImageY1.Margins.Bottom = 90;
LblImageY1.Height = 200;
LblImageY1.clProSettings.FontSize = 35;
LblImageY1.clProSettings.TextSettings.Font.Style = [fsBold];
LblImageY1.clProSettings.FontColor = clAlphaColor.clHexToColor('#539165');
LblImageY1.clProSettings.FontHorzAlign = palcenter;
LblImageY1.clProSettings.FontVertAlign = palcenter;
LblImageY1.SetclProSettings(LblImageY1.clProSettings)
LblImageY2 = GameForm.AddNewProLabel(ImageY2 , 'LblImageY2' , '');
LblImageY2.Align = alCenter;
LblImageY2.Margins.Bottom = 90;
LblImageY2.Height = 200;
//HEREM
/*
LblImageY2.clProSettings = LblImageY1.clProSettings;
LblImageY2
*/
LblImageY2.clProSettings.FontSize = 35;
LblImageY2.clProSettings.TextSettings.Font.Style = [fsBold];
LblImageY2.clProSettings.FontColor = clAlphaColor.clHexToColor('#C51605');
LblImageY2.clProSettings.FontHorzAlign = palcenter;
LblImageY2.clProSettings.FontVertAlign = palcenter;
LblImageY2.SetclProSettings(LblImageY2.clProSettings)
ImageAnm = GameForm.AddNewProImage(GameForm , 'ImageAnm');
ImageAnm.Align = alNone;
ImageAnm.Visible = False;
ImageAnm.Position.Y = 250;
ImageAnm.Position.X = 250;
ImageAnm.Width = TForm(GameForm).ClientWidth / 10;
ImageAnm.Height = TForm(GameForm).ClientHeight / 20;
MqttGame = GameForm.AddNewMQTTConnection(GameForm , 'MqttGame');
GameForm.AddNewEvent(MqttGame , tbeOnMQTTStatusChanged , 'MqttGameChanged');
MqttGame.Channel = 'Room';
MqttGame.Connect;
LblEndScore = GameForm.AddNewProLabel(GameForm , 'LblEndScore' , 'DENEME');
LblEndScore.clProSettings.FontSize = 30;
LblEndScore.clProSettings.TextSettings.Font.Style = [fsBold];
LblEndScore.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
LblEndScore.clProSettings.FontHorzAlign = palcenter;
LblEndScore.clProSettings.FontVertAlign = palcenter;
LblEndScore.SetclProSettings(LblEndScore.clProSettings)
LblEndScore.Align = alCenter;
LblEndScore.Visible = False;
LblEndScore.Width = TForm(GameForm).ClientWidth;
LblEndScore.Height = TForm(GameForm).ClientHeight / 6;
GameForm.Run;
}
void FoodPosition;
{
if (ImageY1.Position.Y > TForm(GameForm).ClientHeight)
{
ImageY1.Position.Y = 50;
ImageY1.Position.X = clMath.GenerateRandom(80 , TForm(GameForm).ClientWidth - 80);
RandomHealthyIndex = clMath.GenerateRandom(0,9);
GameForm.SetImage(ImageY1 ,ListFoods.GetItem(RandomHealthyIndex));
}
else
{
ImageY1.Position.Y = ImageY1.Position.Y + ImageY1Speed;
}
if (ImageY2.Position.Y > TForm(GameForm).ClientHeight)
{
ImageY2.Position.Y = 50;
ImageY2.Position.X = clMath.GenerateRandom(80 , TForm(GameForm).ClientWidth - 80);
RandomUnHealthyIndex = clMath.GenerateRandom(10,20);
GameForm.SetImage(ImageY2 ,ListFoods.GetItem(RandomUnHealthyIndex));
}
else
{
ImageY2.Position.Y = ImageY2.Position.Y + ImageY2Speed;
}
}
void PlayerMoveLeft;
{
PlayerDirection = -1;
}
void PlayerMoveRight;
{
PlayerDirection = 1;
}
void PlayerMove;
{
if(TimerGame.Enabled == true)
{
if(PlayerDirection == -1)
{
ImageBasket.Position.X = ImageBasket.Position.X - PlayerSpeed;
if(ImageBasket.Position.X < 0)
{
ImageBasket.Position.X = 0;
}
}
else if(PlayerDirection == 1)
{
ImageBasket.Position.X = ImageBasket.Position.X + PlayerSpeed;
if((ImageBasket.Position.X + ImageBasket.Width) > TForm(GameForm).ClientWidth)
{
ImageBasket.Position.X = TForm(GameForm).ClientWidth - ImageBasket.Width;
}
}
}
}
void TimePass;
{
if(Time > 0)
{
Time = Time - 1;
LblTime.Text = IntToStr(Time);
}
else
{
//MqttGame.Send(Clomosy.AppUserDisplayName + '+' + IntToStr(Score) + '+' + Clomosy.AppUserGUID);
TimerGame.Enabled = False;
TimerClock.Enabled = False;
ImageY1.Visible = False;
ImageY2.Visible = False;
ImageAnm.Visible = False;
//ShowMessage('Süreniz Doldu ! ');
Vibrate.Vibrate(300);
ImageBasket.Visible = False;
PanelCenter.Visible = False;
LblEndScore.Visible = True;
LblEndScore.Text = 'Skorunuz : ' + IntToStr(Score);
//Score = 0;
LblScore.Text = IntToStr(Score);
ImageNutrients.Visible = False;
sendTimer = GameForm.AddNewTimer(GameForm,'sendTimer',1000);
sendTimer.Enabled = True;
GameForm.AddNewEvent(sendTimer,tbeOnTimer,'SendMsj');
}
}
void SendMsj;
{
if MqttGame.ReceivedMessage == Clomosy.AppUserGUID
{
ShowMessage('Gönderen:PC ----- Skorunuz Alındı');
sendTimer.Enabled = False;
}
else
{
MqttGame.Send(Clomosy.AppUserDisplayName + '+' + IntToStr(Score) + '+' + Clomosy.AppUserGUID);
}
}
void GameOperations;
{
PlayerMove;
FoodPosition;
FoodCollection;
FoodPoint;
ScoreAnimation;
}
void MqttScreenChanged;
{
if(not MqttScreen.Connected)
{
MqttScreen.Connect;
LabelConnection.Text = 'Not Connected';
LabelConnection.clProSettings.FontColor = clAlphaColor.clHexToColor('#DA1212');
}
else
{
LabelConnection.Text = 'Connected';
LabelConnection.clProSettings.FontColor = clAlphaColor.clHexToColor('#0079FF');
}
LabelConnection.SetclProSettings(LabelConnection.clProSettings);
}
void SortArr;
var
X, Y: Integer;
TempName,TempScore,TempGuid: string;
{
try
for (X = 0 to ScoreArray.Count - 1)
{
for (Y = X + 1 to ScoreArray.Count - 1)
{
// sıralama: Büyükten küçüğe doğru sıralama yapacak
if StrToInt(ScoreArray.GetItem(X)) < StrToInt(ScoreArray.GetItem(Y))
{
// Swap scores
TempScore = ScoreArray.GetItem(X);
ScoreArray.SetItem(X, ScoreArray.GetItem(Y));
ScoreArray.SetItem(Y, TempScore);
// Swap names
TempName = NameArray.GetItem(X);
NameArray.SetItem(X, NameArray.GetItem(Y));
NameArray.SetItem(Y, TempName);
// Swap GUIDs
TempGuid = GuidArray.GetItem(X);
GuidArray.SetItem(X, GuidArray.GetItem(Y));
GuidArray.SetItem(Y, TempGuid);
}
}
}
except
ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
}
void Dnm;
var
J : Integer;
{
ShowMessage(IntToStr(NameArray.Count));
For (J = 0 to NameArray.Count - 1)
{
ShowMessage(NameArray.GetItem(J));
}
}
void MqttScreenPublish;
var
J , X: Integer;
OldScore : String;
ScoreState : Boolean;
{
try
if(MqttScreen.ReceivedAlRight)
{
ListContainer.Delimiter = '+';
ListContainer.StrictDelimiter = True;
ListContainer.DelimitedText = MqttScreen.ReceivedMessage;
GelenIsim = ListContainer[0];
CapturedScore = ListContainer[1];
GelenGUID = ListContainer[2];
MqttScreen.Send(GelenGUID);
//ShowMessage('GelenIsim :'+ GelenIsim);
//ShowMessage('CapturedScore :'+ CapturedScore);
//ShowMessage('GelenGUID :'+ GelenGUID);
ScoreState = True; //oyuncu kontrolü
//ShowMessage(ScoreState);
For (X = 0 to ScoreArray.Count - 1)
{
if(GuidArray.GetItem(X) == GelenGUID)
{
OldScore = ScoreArray.GetItem(X);
// ShowMessage('OldScore: '+ OldScore);
// ShowMessage('eşitler girdi');
ScoreState = False;
if StrToInt(CapturedScore) > StrToInt(OldScore)
{
//ShowMessage('CapturedScore > OldScore');
ScoreArray.SetItem(X,CapturedScore);
break;
}
}
}
if ScoreState
{
NameArray.Add(GelenIsim);
GuidArray.Add(GelenGUID);
ScoreArray.Add(CapturedScore);
}
JsonStr = '';
JsonStr = '[';
SortArr;
For (J = 0 to NameArray.Count - 1)
{
JsonStr = JsonStr + '{"BtnQueue":'+IntToStr(J + 1)+'';
JsonStr = JsonStr + ',"BtnPlayerName":"'+NameArray.GetItem(J)+'"';
if (J == NameArray.Count - 1)
{
JsonStr = JsonStr + ',"BtnPlayerScore":'+ScoreArray.GetItem(J)+'}';
}
else
{
JsonStr = JsonStr + ',"BtnPlayerScore":'+ ScoreArray.GetItem(J)+'},';
}
}
JsonStr = JsonStr + ']';
Qry = Clomosy.ClDataSetFromJSON(JsonStr);
UsersList.clLoadProListViewDataFromDataset(Qry);
}
except
ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
}
void CloseForm2;
{
CallerForm.clShow;
ButtonPlay.Enabled = True;
TClProButton(FormExe.clFindComponent('BtnGoBack')).Click;
}
void CreateExeForm;
{
FormExe = TclGameForm.Create(Self);
FormExe.SetFormBGImage(' https://clomosy.com/demos/FooodBg.png" rel="nofollow - https://clomosy.com/demos/FooodBg.png ');
LabelConnection = FormExe.AddNewProLabel(FormExe , 'LabelConnection' , 'NOT CONNECTED');
LabelConnection.clProSettings.FontSize = 20;
LabelConnection.clProSettings.TextSettings.Font.Style = [fsBold];
LabelConnection.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
LabelConnection.clProSettings.FontHorzAlign = palTrailing;
LabelConnection.clProSettings.FontVertAlign = palcenter;
LabelConnection.SetclProSettings(LabelConnection.clProSettings);
LabelConnection.Align = alTop;
LabelConnection.Margins.Top = 25;
LabelConnection.Margins.right = 20;
FormExe.AddNewEvent(LabelConnection , tbeOnClick , '');
UsersList = FormExe.AddNewProListView(FormExe , 'UsersList');
UsersList.Align = alTop;
UsersList.Height = TForm(FormExe).ClientHeight / 1.25;
UsersList.Properties.ItemSpace = 10;
UsersList.Margins.Bottom = 20;
UsersList.Margins.Top = 20;
UsersList.Margins.Left = 20;
UsersList.Margins.Right = 20;
UsersList.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#557C55');
UsersList.clProSettings.IsFill = True;
UsersList.clProSettings.IsRound = True;
UsersList.clProSettings.RoundWidth = 15;
UsersList.clProSettings.RoundHeight = 15;
UsersList.clProSettings.ItemHeight = 75;
UsersList.clProSettings.ItemWidth = 75;
UsersList.SetclProSettings(UsersList.clProSettings);
DesignerListPanel = FormExe.AddNewProListViewDesignerPanel(UsersList , 'DesignerListPanel');
DesignerListPanel.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#A6CF98');
DesignerListPanel.clProSettings.IsFill = True;
DesignerListPanel.clProSettings.IsRound = True;
DesignerListPanel.clProSettings.RoundHeight = 10;
DesignerListPanel.clProSettings.RoundWidth = 10;
DesignerListPanel.SetclProSettings(DesignerListPanel.clProSettings);
UsersList.SetDesignerPanel(DesignerListPanel);
Qry = TCLJSONQuery.Create(nil);
BtnPlayerName = FormExe.AddNewProButton(DesignerListPanel , 'BtnPlayerName' , '');
BtnPlayerName.Align = alCenter;
BtnPlayerName.Width = 200;
BtnPlayerName.Height = 65;
BtnPlayerName.clProSettings.FontSize = 20;
BtnPlayerName.clProSettings.TextSettings.Font.Style = [fsBold];
BtnPlayerName.clProSettings.PictureSource = ' https://clomosy.com/demos/foodInformationBox.png" rel="nofollow - https://clomosy.com/demos/foodInformationBox.png ';
BtnPlayerName.SetclProSettings(BtnPlayerName.clProSettings);
DesignerListPanel.AddPanelObject(BtnPlayerName , clText1);
BtnQueue = FormExe.AddNewProButton(DesignerListPanel , 'BtnQueue' , '');
BtnQueue.Margins.Top = 3;
BtnQueue.Margins.Bottom = 3;
BtnQueue.Margins.Left = 10;
BtnQueue.Margins.Right = 10;
BtnQueue.Align = alLeft;
BtnQueue.clProSettings.PictureSource = ' https://clomosy.com/demos/foodInformationPointBox.png" rel="nofollow - https://clomosy.com/demos/foodInformationPointBox.png ';
BtnQueue.clProSettings.FontSize = 30;
BtnQueue.clProSettings.TextSettings.Font.Style = [fsBold];
BtnQueue.SetclProSettings(BtnQueue.clProSettings);
DesignerListPanel.AddPanelObject(BtnQueue , clText3);
BtnPlayerScore = FormExe.AddNewProButton(DesignerListPanel , 'BtnPlayerScore' , '');
BtnPlayerScore.Align = alRight;
BtnPlayerScore.Margins.Right = 10;
BtnPlayerScore.Margins.Left = 10;
BtnPlayerScore.Margins.Top = 3;
BtnPlayerScore.Margins.Bottom = 3;
BtnPlayerScore.clProSettings.FontSize = 30;
BtnPlayerScore.clProSettings.PictureSource = ' https://clomosy.com/demos/foodInformationBox.png" rel="nofollow - https://clomosy.com/demos/foodInformationBox.png ';
BtnPlayerScore.clProSettings.TextSettings.Font.Style = [fsBold];
BtnPlayerScore.SetclProSettings(BtnPlayerScore.clProSettings);
DesignerListPanel.AddPanelObject(BtnPlayerScore , clText2);
NameArray = TclArrayString.Create;
ScoreArray = TclArrayString.Create;
GuidArray = TclArrayString.Create;
ListContainer = Clomosy.StringListNew;
MqttScreen = FormExe.AddNewMQTTConnection(FormExe , 'MqttScreen');
FormExe.AddNewEvent(MqttScreen , tbeOnMQTTStatusChanged , 'MqttScreenChanged');
FormExe.AddNewEvent(MqttScreen , tbeOnMQTTPublishReceived , 'MqttScreenPublish');
MqttScreen.Channel = 'Room';
MqttScreen.Connect;
ImgBack = FormExe.AddNewProImage(FormExe , 'ImgBack');
ImgBack.Align = alNone;
FormExe.SetImage(ImgBack , ' https://clomosy.com/demos/XoXback.png" rel="nofollow - https://clomosy.com/demos/XoXback.png ');
ImgBack.Width = TForm(FormExe).ClientWidth / 6;
ImgBack.Height = TForm(FormExe).ClientHeight / 12;
FormExe.AddNewEvent(ImgBack , tbeOnClick , 'CloseForm2');
ImgBack.Position.X = -10;
ImgBack.Position.Y = 10;
FormExe.Run;
}
// ---------------------MAIN CODE BLOCK------------------------------------------------------------
{
if(Clomosy.PlatformIsMobile)
{
CreateGameForm;
}
else
{
CreateExeForm;
//CreateGameForm
}
}
// ---------------------------------------------------------------------------------------------------