Type=Activity
Version=4.3
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: False
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim tmr1,tmr2 As Timer
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
Dim arrPic(10) As ImageView
Dim arrOffset(10) As Int
Dim sTimeout As Int
	Dim lblscore As Label
	Dim lblstage As Label
	Dim lblsecond As Label
	Dim lblseconds As Label
	Dim imgbg1 As ImageView
	Dim countItem As Int : countItem = 0
	Dim btn1 As Button
	Dim btn2 As Button
	Dim btn3 As Button
	Dim btn4 As Button
	Dim btn5 As Button
	Dim lst1 As List
	Dim activeItem As Int
	Dim imgbackground As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("game8")
common.changeTheme(imgbackground)
settings.loadDefaultSetting("8")
btn1.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
btn2.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
btn3.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
btn4.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
btn5.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblscore.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblsecond.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblseconds.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblscore.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblstage.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
sTimeout = settings.getData("settingGame8.app","timeout")
sTimeout = sTimeout - 1
lblstage.Text = settings.getData("settingGame8.app","stage")
common.playbgGame1
randomPicture
lst1.Initialize
tmr1.Initialize("tmr1",1500)
tmr1.Enabled = True
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 randomPicture
For i=0 To 9
 arrPic(i).Initialize("")
Next
arrPic(0).Bitmap = LoadBitmap(File.DirAssets,"cat.jpg")
arrPic(1).Bitmap = LoadBitmap(File.DirAssets,"chicken.jpg")
arrPic(2).Bitmap = LoadBitmap(File.DirAssets,"cow.jpg")
arrPic(3).Bitmap = LoadBitmap(File.DirAssets,"dog.jpg")
arrPic(4).Bitmap = LoadBitmap(File.DirAssets,"duck.jpg")
arrPic(5).Bitmap = LoadBitmap(File.DirAssets,"elephant.jpg")
arrPic(6).Bitmap = LoadBitmap(File.DirAssets,"horse.jpg")
arrPic(7).Bitmap = LoadBitmap(File.DirAssets,"joghd.jpg")
arrPic(8).Bitmap = LoadBitmap(File.DirAssets,"khar.jpg")
arrPic(9).Bitmap = LoadBitmap(File.DirAssets,"lion.jpg")
settings.loadDefaultSetting("8")
End Sub

Sub tmr1_Tick
Dim th1 As Thread
Dim offset As Int
Select Case lblstage.Text
 Case "1"
  If countItem > 2 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,4)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")
 Case "2"
   If countItem > 2 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,4)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")  
 Case "3"
  If countItem > 3 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,5)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")   
 Case "4"
  If countItem > 3 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,5)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")   
 Case "5"
  If countItem > 4 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,6)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")    
 Case "6"
  If countItem > 4 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,6)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")    
 Case "7"
  If countItem > 5 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,7)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")  
 Case "8"
  If countItem > 7 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,7)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")   
 Case "9"
  If countItem > 7 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,8)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")   
 Case "10"
  If countItem > 8 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,8)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")   
 Case "11"
  If countItem > 9 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,9)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")  
 Case "12"
  If countItem > 9 Then
   ToastMessageShow("حالا تعداد تصویر نمایش داده شده را انتخاب کنید",False)
   tmr1.Enabled = False   
   showRandomPicture
   tmr2.Initialize("tmr2",1)
   tmr2.Enabled = True   
   Return
  End If
  offset = Rnd(0,9)
  imgbg1.Bitmap = arrPic(offset).Bitmap
  arrOffset(offset) = arrOffset(offset) + 1
  If existItemarray(offset) = False Then
   lst1.Add(offset)
  End If
  countItem = countItem + 1
  DoEvents
  th1.Sleep(1100)
  DoEvents
  imgbg1.Bitmap = LoadBitmap(File.DirAssets,"question.jpg")  
End Select
End Sub
Sub tmr2_Tick
Dim k1 As Int
If lblsecond.Text > sTimeout Then
   tmr2.Enabled = False
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   frmGame1_result.sState = "unwin"
   frmGame1_result.sGameNumber = "8"
   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
'----------------------------------------------------------------------
End Sub
Sub showRandomPicture
Dim i As Int
i = Rnd(0,lst1.Size-1)
imgbg1.Bitmap = arrPic(lst1.Get(i)).Bitmap
activeItem = arrOffset(lst1.Get(i)) 
btn1.Text = Rnd(0,1)
btn2.Text = Rnd(1,2)
btn3.Text = Rnd(3,4)
btn4.Text = Rnd(5,6)
btn5.Text = Rnd(7,8)
If btn1.Text <> activeItem AND btn2.Text <> activeItem AND btn3.Text <> activeItem AND btn4.Text <> activeItem AND btn5.Text <> activeItem Then
 btn4.Text = activeItem
End If
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub existItemarray(sItem As String) As Boolean
For i=0 To lst1.Size-1
 If lst1.Get(i) = sItem Then
  Return True
 End If
Next
Return False
End Sub
Sub wrongItem(c1 As Button)
Dim t1 As Int
common.playAudio("wrong.wav")
common.playAnimation(c1,"scale",1000)
c1.Visible = False
t1 = lblscore.Text
lblscore.Text = t1 - 10
common.vibrePhone
End Sub
Sub stateGame(sState1 As String)
   tmr2.Enabled = False
   frmGame1_result.sStage = lblstage.Text
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   frmGame1_result.sState = sState1
   frmGame1_result.sScore = lblscore.Text
   frmGame1_result.sGameNumber = "8"
   common.stopAudio
   Activity.Finish
   StartActivity(frmGame1_result)
End Sub
Sub btn1_Click
If btn1.Text <> activeItem Then
 wrongItem(btn1)
Else
 stateGame("win")
End If
End Sub
Sub btn2_Click
If btn2.Text <> activeItem Then
 wrongItem(btn2)
Else
 stateGame("win")
End If	
End Sub
Sub btn3_Click
If btn3.Text <> activeItem Then
 wrongItem(btn3)
Else
 stateGame("win")
End If	
End Sub
Sub btn4_Click
If btn4.Text <> activeItem Then
 wrongItem(btn4)
Else
 stateGame("win")
End If	
End Sub
Sub btn5_Click
If btn5.Text <> activeItem Then
 wrongItem(btn5)
Else
 stateGame("win")
End If	
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
End Sub