Type=Activity
Version=4.3
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: False
#End Region
'در این بازی کودک باید کوچکترین عدد یا بزرگترین عدد را در مجموعه پیاد کند
Sub Process_Globals
	Dim tmr1,tmr2 As Timer
End Sub

Sub Globals
Dim sNumber(10) As String
Dim intShowCount,sTimeout As Int
	Dim img2 As ImageView
	Dim img0 As ImageView
	Dim img5 As ImageView
	Dim img7 As ImageView
	Dim img8 As ImageView
	Dim img9 As ImageView
	Dim img3 As ImageView
	Dim img4 As ImageView
	Dim img6 As ImageView
	Dim img1 As ImageView
	Dim showNubmer As List
	Dim lblscore As Label
	Dim lblseconds As Label
	Dim lblsecond As Label
	Dim lbltitle As Label
	Dim sStage As Int
    Dim sPostionTop(10),sPostionLeft(10) As Int
	Dim lblstage As Label
	Dim imgbackground As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim sRes,j As Int
Dim map1 As Map
sRes = 0
settings.loadDefaultSetting("1")
sTimeout = settings.getData("settingGame1.app","timeout")
Activity.LoadLayout("game1")
common.changeTheme(imgbackground)
lblstage.Text = settings.getData("settingGame1.app","stage")
map1.Initialize
showNubmer.Initialize
showNubmer.Clear
'Create number array and shuffle it
For i = 0 To 9
 sNumber(i) = i
Next
common.ShuffleArray(sNumber)
loadPosition
'------------------------------------------------
'If user pass all stage then again go to 1 stage
sStage = settings.getData("settingGame1.app","stage")
'------------------------------------------------
Select Case sStage
 Case 1
  intShowCount = Rnd(2,3)
 Case 2
  intShowCount = Rnd(2,3)
 Case 3
  intShowCount = Rnd(3,4)
 Case 4
  intShowCount = Rnd(3,4)
 Case 5
  intShowCount = Rnd(5,6)
 Case 6
  intShowCount = Rnd(5,6)
 Case 7
  intShowCount = Rnd(6,7)
 Case 8
  intShowCount = Rnd(6,7)
 Case 9
  intShowCount = Rnd(7,8)
 Case 10
  intShowCount = Rnd(7,9)
 Case 11
  intShowCount = Rnd(8,9)
 Case 12
  intShowCount = Rnd(8,9)  
End Select
For i = 1 To intShowCount
 sRes = sNumber(i-1)
  Select Case sRes
   Case 0
    showNubmer.Add("0")
    img0.Visible = True
	common.playAnimation(img0,"scale1",1000)   
   Case 1
    showNubmer.Add("1")
    img1.Visible = True
	common.playAnimation(img1,"scale1",1000)
   Case 2
    showNubmer.Add("2")
    img2.Visible = True
	common.playAnimation(img2,"scale1",1000)
   Case 3
    showNubmer.Add("3")
    img3.Visible = True
	common.playAnimation(img3,"scale1",1000)	
   Case 4
    showNubmer.Add("4")
    img4.Visible = True
	common.playAnimation(img4,"scale1",1000)	
   Case 5
    showNubmer.Add("5")
    img5.Visible = True
	common.playAnimation(img5,"alpha",1000)	
   Case 6
    showNubmer.Add("6")
    img6.Visible = True
	common.playAnimation(img6,"alpha",1000)	
   Case 7
    showNubmer.Add("7")
    img7.Visible = True
	common.playAnimation(img7,"alpha",1000)	
   Case 8
    showNubmer.Add("8")
    img8.Visible = True
	common.playAnimation(img8,"alpha",1000)	
   Case 9
    showNubmer.Add("9")
    img9.Visible = True
	common.playAnimation(img9,"alpha",1000)	
 End Select
Next
lblsecond.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblseconds.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblscore.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lbltitle.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblscore.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblstage.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
j = Rnd(1,6)
If j > 3 Then
 lbltitle.Tag = "small"
 lbltitle.Text = "عزیزم کوچکترین عدد رو پیدا کن"
 ToastMessageShow("عزیزم کوچکترین عدد رو پیدا کن",False)
Else
 lbltitle.Tag = "big"
 lbltitle.Text = "عزیزم بزرگترین عدد رو پیدا کن"
 ToastMessageShow("عزیزم بزرگترین عدد رو پیدا کن",False)
End If
tmr1.Initialize("tmr1",3000)
tmr2.Initialize("tmr2",1)
tmr1.Enabled = True
common.playbgGame1
loadMenu
End Sub
Sub loadMenu
Activity.AddMenuItem2("تنظیمات","btnsetting",LoadBitmap(File.DirAssets,"setting.png"))
Activity.AddMenuItem2("درباره ما","btnabout",LoadBitmap(File.DirAssets,"about.png"))
Activity.AddMenuItem2("خروج","exit1",LoadBitmap(File.DirAssets,"exit.png"))
End Sub
Sub btnsetting_Click
Activity.Finish
StartActivity(setting)
End Sub
Sub btnabout_Click
Activity.Finish
StartActivity(frmabout)
End Sub
Sub exit1_Click
Dim i As Int
i = Msgbox2("آیا مایل به خروج هستید؟","خروج","آری","خیر","",Null)
If i = DialogResponse.POSITIVE Then
 ExitApplication
End If
End Sub
Sub loadPosition
sPostionLeft(0) = img0.Left
sPostionTop(0) = img0.Top

sPostionLeft(1) = img1.Left
sPostionTop(1) = img1.Top

sPostionLeft(2) = img2.Left
sPostionTop(2) = img2.Top

sPostionLeft(3) = img3.Left
sPostionTop(3) = img3.Top

sPostionLeft(4) = img4.Left
sPostionTop(4) = img4.Top

sPostionLeft(5) = img5.Left
sPostionTop(5) = img5.Top

sPostionLeft(6) = img6.Left
sPostionTop(6) = img6.Top

sPostionLeft(7) = img7.Left
sPostionTop(7) = img7.Top

sPostionLeft(8) = img8.Left
sPostionTop(8) = img8.Top

sPostionLeft(9) = img9.Left
sPostionTop(9) = img9.Top
For i = 0 To sNumber.Length -1
 Select Case i
  Case 0
   img0.Left = sPostionLeft(sNumber(i))
   img0.Top  = sPostionTop(sNumber(i))
  Case 1
   img1.Left = sPostionLeft(sNumber(i))
   img1.Top  = sPostionTop(sNumber(i))
  Case 2
   img2.Left = sPostionLeft(sNumber(i))
   img2.Top  = sPostionTop(sNumber(i))
  Case 3
   img3.Left = sPostionLeft(sNumber(i))
   img3.Top  = sPostionTop(sNumber(i))
  Case 4
   img4.Left = sPostionLeft(sNumber(i))
   img4.Top  = sPostionTop(sNumber(i))
  Case 5
   img5.Left = sPostionLeft(sNumber(i))
   img5.Top  = sPostionTop(sNumber(i))
  Case 6
   img6.Left = sPostionLeft(sNumber(i))
   img6.Top  = sPostionTop(sNumber(i))
  Case 7
   img7.Left = sPostionLeft(sNumber(i))
   img7.Top  = sPostionTop(sNumber(i))
  Case 8
   img8.Left = sPostionLeft(sNumber(i))
   img8.Top  = sPostionTop(sNumber(i))
  Case 9
   img9.Left = sPostionLeft(sNumber(i))
   img9.Top  = sPostionTop(sNumber(i))
 End Select
Next
End Sub
 
Sub tmr1_Tick
 hideImage
 tmr1.Enabled = False
 tmr2.Enabled = True
End Sub
Sub tmr2_Tick
Dim k1,rnd1 As Int
If lblsecond.Text > sTimeout Then
   tmr2.Enabled = False
   frmGame1_result.sStage = sStage
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   frmGame1_result.sState = "unwin"
   frmGame1_result.sGameNumber = "1"
   frmGame1_result.sScore = lblscore.Text
   common.stopAudio
   Activity.Finish
   StartActivity(frmGame1_result)
End If
'Create Timer
k1 = lblseconds.Text + 1
lblseconds.Text = k1
If lblseconds.Text > 60 Then
 lblseconds.Text = 0
 k1 = lblsecond.Text + 1
 lblsecond.Text = k1
End If
'----------------------------------------------------------------------
If showNubmer.Size = 0 Then
 tmr2.Enabled = False
End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#Region Check Number BIG SMALL
Sub isBigger(sNumberClick As Int) As Boolean
Dim sTemps As String
showNubmer.Sort(True)
sTemps = showNubmer.Get(showNubmer.Size-1)
	 If sNumberClick > sTemps OR sNumberClick = sTemps Then
	  showNubmer.RemoveAt(showNubmer.Size - 1)
	  Return True
	 Else
	  Return False
	 End If
End Sub

Sub isSmallest(sNumberClick As Int) As Boolean
Dim sTemps As String
showNubmer.Sort(True)
sTemps = showNubmer.Get(0)
	 If sNumberClick < sTemps OR sNumberClick = sTemps Then
	  showNubmer.RemoveAt(0)
	  Return True
	 Else
	  Return False
	 End If
End Sub

Sub CheckState(c1 As View,sNumbers As String)
Dim i1 As Int
If lbltitle.Tag = "big" Then
 If isBigger(sNumbers) = False Then
  common.vibrePhone
  common.playAudio("wrong.wav")
  i1 = lblscore.Text - 10
  lblscore.Text = i1
 Else
  i1 = lblscore.Text + 10
  lblscore.Text = i1
  c1.SetBackgroundImage(LoadBitmap(File.DirAssets,c1.Tag & ".gif"))
  common.playAnimation(c1,"scale",1000)
  c1.Visible = False
  If showNubmer.Size < 1 Then
   frmGame1_result.sState = "win"
   common.stopAudio
   frmGame1_result.sScore = lblscore.Text
   frmGame1_result.sScore = lblscore.Text
   frmGame1_result.sStage = sStage
   frmGame1_result.sGameNumber = "1"
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   Activity.Finish
   StartActivity(frmGame1_result)
  End If
 End If
Else If lbltitle.Tag = "small" Then
 If isSmallest(sNumbers) = False Then
  common.vibrePhone
  common.playAudio("wrong.wav")
  i1 = lblscore.Text - 10
  lblscore.Text = i1
 Else
  i1 = lblscore.Text + 10
  lblscore.Text = i1
  common.playAnimation(c1,"scale",1000)
  c1.Visible = False
  If showNubmer.Size < 1 Then
   frmGame1_result.sState = "win"
   frmGame1_result.sScore = lblscore.Text
   common.stopAudio
   frmGame1_result.sStage = sStage
   frmGame1_result.sGameNumber = "1"
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   Activity.Finish
   StartActivity(frmGame1_result)
  End If  
 End If
End If
End Sub

#End Region

#Region Item Clicked
Sub img0_Click
  CheckState(img0,"0")
End Sub
Sub img1_Click
  CheckState(img1,"1")
End Sub
Sub img2_Click
  CheckState(img2,"2")
End Sub

Sub img3_Click
  CheckState(img3,"3")
End Sub
Sub img4_Click
  CheckState(img4,"4")
End Sub
Sub img5_Click
  CheckState(img5,"5")	
End Sub
Sub img6_Click
  CheckState(img6,"6")
End Sub
Sub img7_Click
  CheckState(img7,"7")
End Sub
Sub img8_Click
  CheckState(img8,"8")
End Sub

Sub img9_Click
  CheckState(img9,"9")
End Sub
#End Region

Sub hideImage
img0.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img1.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img2.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img3.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img4.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img5.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img6.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img7.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img8.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
img9.Bitmap = LoadBitmap(File.DirAssets,"no.gif")
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
  If KeyCode = KeyCodes.KEYCODE_BACK Then
   Activity.Finish
   common.stopAudio
   StartActivity(Main)
  End If
  If KeyCode = KeyCodes.KEYCODE_MENU Then
   Activity.OpenMenu
  End If
End Sub