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 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 sCorrect As Int : sCorrect = 0
	Dim lblscore As Label
	Dim lblstage As Label
	Dim lblseconds As Label
	Dim lblsecond As Label
	Dim sTimeout As Int
	Dim sAnswer,sQuestion As String
	Dim b1 As Button
	Dim b2 As Button
	Dim b3 As Button
	Dim b4 As Button
	Dim b5 As Button
	Dim b6 As Button
	Dim b7 As Button
	Dim a1 As Button
	Dim a10 As Button
	Dim a11 As Button
	Dim a12 As Button
	Dim a13 As Button
	Dim a14 As Button
	Dim a15 As Button
	Dim a16 As Button
	Dim a17 As Button
	Dim a18 As Button
	Dim a19 As Button
	Dim a2 As Button
	Dim a20 As Button
	Dim a21 As Button
	Dim a22 As Button
	Dim a23 As Button
	Dim a24 As Button
	Dim a25 As Button
	Dim a26 As Button
	Dim a27 As Button
	Dim a28 As Button
	Dim a29 As Button
	Dim a3 As Button
	Dim a30 As Button
	Dim a31 As Button
	Dim a32 As Button
	Dim a4 As Button
	Dim a5 As Button
	Dim a6 As Button
	Dim a7 As Button
	Dim a8 As Button
	Dim a9 As Button
	Dim imgbackground As ImageView
	Dim lbltitle As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("game9")
common.changeTheme(imgbackground)
Dim bs1 As Button
Dim l1 As Label
settings.loadDefaultSetting("9")
For i = 0 To Activity.NumberOfViews - 1
 If Activity.GetView(i) Is Button Then
  bs1 = Activity.GetView(i)
  bs1.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
  bs1.TextSize = 15
 Else If Activity.GetView(i) Is Label Then
  l1 = Activity.GetView(i)
  l1.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
 End If
Next
sTimeout = settings.getData("settingGame9.app","timeout")
sTimeout = sTimeout - 1
lblstage.Text = settings.getData("settingGame9.app","stage")
Dim lst1 As List
lst1.Initialize
lst1 = common.getItemSql
sAnswer = lst1.Get(1)
sQuestion = lst1.Get(0)
lbltitle.Text = sQuestion
defineBtnstate(sAnswer.Length)
common.playbgGame1
tmr1.Initialize("tmr1",1)
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 defineBtnstate(sLenght As Int)
Select Case sLenght
 Case 7 
  b1.Visible = True
  b2.Visible = True
  b3.Visible = True
  b4.Visible = True
  b5.Visible = True
  b6.Visible = True
  b7.Visible = True
 Case 6
  b1.Visible = True
  b2.Visible = True
  b3.Visible = True
  b4.Visible = True
  b5.Visible = True
  b6.Visible = True
 Case 5
  b1.Visible = True
  b2.Visible = True
  b3.Visible = True
  b4.Visible = True
  b5.Visible = True
 Case 4
  b1.Visible = True
  b2.Visible = True
  b3.Visible = True
  b4.Visible = True
 Case 3
  b1.Visible = True
  b2.Visible = True
  b3.Visible = True
 Case 2
  b1.Visible = True
  b2.Visible = True
 End Select
End Sub

Sub Activity_Resume

End Sub

Sub btnWord(sb As Button)
Dim l1 As List
Dim s1 As String
Dim t2 As Int
l1.Initialize
If sAnswer.IndexOf(sb.Text) = -1 Then
  common.playAudio("wrong.wav")
  t2 = lblscore.Text
  lblscore.Text = t2 - 10   
  common.playAnimation(sb,"scale",1000)
  sb.Visible = False
  common.vibrePhone
  ToastMessageShow("اشتباه بود",False)
  Return
End If
l1 = getPositionWord(sAnswer,sb.Text)
For i=0 To l1.Size-1
 s1 = l1.Get(i)
 Select Case s1
  Case "0"
   b1.Text = sb.Text
  Case 1
   b2.Text = sb.Text
  Case 2
   b3.Text = sb.Text
  Case 3
   b4.Text = sb.Text
  Case 4
   b5.Text = sb.Text
  Case 5
   b6.Text = sb.Text
  Case 6
   b7.Text = sb.Text
 End Select
Next
If sCorrect >= sAnswer.Length Then
   tmr1.Enabled = False
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   frmGame1_result.sState = "win"
   frmGame1_result.sStage = lblstage.Text
   frmGame1_result.sGameNumber = "9"
   frmGame1_result.sScore = lblscore.Text
   common.stopAudio
   Activity.Finish
   StartActivity(frmGame1_result)
End If
t2 = lblscore.Text
lblscore.Text = t2 + 10
common.playAudio("star.mp3")
common.playAnimation(sb,"scale",1000)
End Sub

Sub getPositionWord(sA As String,sChar As String) As List
Dim l1 As List
Dim i As Int
Dim sTemp As String
sTemp = sAnswer
l1.Initialize
i = 0
Do While i <> -1
 i = sTemp.IndexOf2(sChar,i)
 If i <> -1 Then
  l1.Add(i)
  i = i + 1
  sCorrect = sCorrect + 1
 End If
Loop
Return l1
End Sub

Sub tmr1_Tick
Dim k1 As Int
If lblsecond.Text > sTimeout Then
   tmr1.Enabled = False
   frmGame1_result.sTime = "زمان سپری شده "  & lblsecond.Text & " : " & lblseconds.Text & " ثانیه"
   frmGame1_result.sState = "unwin"
   frmGame1_result.sGameNumber = "9"
   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 Activity_Pause (UserClosed As Boolean)

End Sub


Sub a1_Click
 btnWord(a1)
End Sub
Sub a2_Click
 btnWord(a2)	
End Sub
Sub a3_Click
 btnWord(a3)	
End Sub
Sub a4_Click
 btnWord(a4)	
End Sub
Sub a5_Click
 btnWord(a5)	
End Sub
Sub a6_Click
 btnWord(a6)	
End Sub
Sub a7_Click
 btnWord(a7)	
End Sub
Sub a8_Click
 btnWord(a8)	
End Sub
Sub a9_Click
 btnWord(a9)	
End Sub
Sub a10_Click
 btnWord(a10)	
End Sub
Sub a11_Click
 btnWord(a11)	
End Sub
Sub a12_Click
 btnWord(a12)
End Sub
Sub a13_Click
 btnWord(a13)	
End Sub
Sub a14_Click
 btnWord(a14)	
End Sub
Sub a15_Click
 btnWord(a15)	
End Sub
Sub a16_Click
 btnWord(a16)	
End Sub
Sub a17_Click
 btnWord(a17)	
End Sub
Sub a18_Click
 btnWord(a18)	
End Sub
Sub a19_Click
 btnWord(a19)	
End Sub
Sub a20_Click
 btnWord(a20)	
End Sub
Sub a21_Click
 btnWord(a21)	
End Sub
Sub a22_Click
 btnWord(a22)	
End Sub
Sub a23_Click
 btnWord(a23)	
End Sub
Sub a24_Click
 btnWord(a24)	
End Sub
Sub a25_Click
 btnWord(a25)	
End Sub
Sub a26_Click
 btnWord(a26)	
End Sub
Sub a27_Click
 btnWord(a27)	
End Sub
Sub a28_Click
 btnWord(a28)	
End Sub
Sub a29_Click
 btnWord(a29)	
End Sub
Sub a30_Click
 btnWord(a30)	
End Sub
Sub a31_Click
 btnWord(a31)	
End Sub
Sub a32_Click
 btnWord(a32)	
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
  If KeyCode = KeyCodes.KEYCODE_BACK Then
   tmr1.Enabled = False
   Activity.Finish
   common.stopAudio   
   StartActivity(Main)
  End If
  If KeyCode = KeyCodes.KEYCODE_MENU Then
   Activity.OpenMenu
  End If
End Sub