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 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 lblnum1 As Label
	Dim lblnum2 As Label
	Dim lblresult As Label
	Dim btn1 As Button
	Dim btn2 As Button
	Dim btn3 As Button
	Dim btn4 As Button
	Dim btn5 As Button
	Dim lblscore As Label
	Dim lblstage As Label
	Dim lblseconds As Label
	Dim lblsecond As Label
	Dim sTimeout As Int
	Dim num1,num2,res As Int
	Dim operating As String
	Dim lblop As Label
	Dim lbldivid As Label
	Dim imgbackground As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim op1 As Int
common.playbgGame1
Activity.LoadLayout("game2")
common.changeTheme(imgbackground)
lblnum1.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblnum2.Typeface = Typeface.LoadFromAssets("BNazanin.ttf")
lblresult.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")
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")
settings.loadDefaultSetting("3")
sTimeout = settings.getData("settingGame3.app","timeout")
lblstage.Text = settings.getData("settingGame3.app","stage")
If tmr2.IsInitialized = False Then
 tmr2.Initialize("tmr2",1)
End If
tmr2.Enabled = True
Select Case lblstage.Text
 Case 1
 Case 0
	lblnum1.Text = Rnd(0,5)
	lblnum2.Text = Rnd(0,5)
 Case 2
	lblnum1.Text = Rnd(0,10)
	lblnum2.Text = Rnd(0,10)
 Case 3
	lblnum1.Text = Rnd(0,20)
	lblnum2.Text = Rnd(0,20)
 Case 4
	lblnum1.Text = Rnd(0,25)
	lblnum2.Text = Rnd(0,25)
 Case 5
	lblnum1.Text = Rnd(0,35)
	lblnum2.Text = Rnd(0,35)
 Case 6
	lblnum1.Text = Rnd(0,45)
	lblnum2.Text = Rnd(0,45)
 Case 7
	lblnum1.Text = Rnd(0,65)
	lblnum2.Text = Rnd(0,65)
 Case 8
	lblnum1.Text = Rnd(0,75)
	lblnum2.Text = Rnd(0,75)
 Case 9
	lblnum1.Text = Rnd(0,85)
	lblnum2.Text = Rnd(0,85)
 Case 10
	lblnum1.Text = Rnd(0,95)
	lblnum2.Text = Rnd(0,95)
 Case 11
	lblnum1.Text = Rnd(0,150)
	lblnum2.Text = Rnd(0,150)
 Case 12
	lblnum1.Text = Rnd(0,250)
	lblnum2.Text = Rnd(0,250)
End Select
num1 = lblnum1.Text
num2 = lblnum2.Text
If lblstage.Text > 5 Then
 op1 = Rnd(1,4)
Else
 op1 = Rnd(1,2)
End If
Select Case op1
 Case 1
  res = num1+num2
  lblop.Text = "+"
  operating = "+"
 Case 2
  res = num1-num2
  lblop.Text = "-"
  operating = "-"
 Case 3
  res = num1*num2
  lblop.Text = "*"
  operating = "*"
 Case 4
  res = num1/num2
  lblop.Text = "/"
  operating = "/"
End Select
loadResultAction
'common.playAnimation(lblnum1,"alpha",1200)
'common.playAnimation(lblnum2,"alpha",1200)
'common.playAnimation(lblresult,"alpha",1200)
'common.playAnimation(lblop,"alpha",1200)
'common.playAnimation(lbldivid,"alpha",1200)
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 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.sScore = lblscore.Text
   frmGame1_result.sGameNumber = "3"
   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 loadResultAction
Dim k1(5) As String
k1(0) = Rnd(0,99)
If num1 > 0 Then
 k1(1) = Rnd(0,num1)
Else
 k1(1) = Rnd(0,num1+10)
End If
If num2 > 0 Then
 k1(2) = Rnd(0,num2)
Else
  k1(2) = Rnd(0,num2+10)
End If
Select Case operating
 Case "+"
  k1(3) = num1 + num2
 Case "-"
  k1(3) = num1 - num2
 Case "/"
  k1(3) = num1 / num2
 Case "*"
  k1(3) = num1 * num2
 End Select
 k1(4) = Rnd(num1,99+num1)
common.ShuffleArray(k1)
btn1.Text = k1(0)
btn2.Text = k1(1)
btn3.Text = k1(2)
btn4.Text = k1(3)
btn5.Text = k1(4)
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
 
End Sub

Sub btn5_Click
 If res <> btn5.Text Then
  wrongItem(btn5)
 Else
  stateGame("win")
 End If	
End Sub
Sub btn4_Click
 If res <> btn4.Text Then
  wrongItem(btn4)
 Else
  stateGame("win")
 End If	
End Sub
Sub btn3_Click
 If res <> btn3.Text Then
  wrongItem(btn3)
 Else
  stateGame("win")
 End If	
End Sub
Sub btn2_Click
 If res <> btn2.Text Then
  wrongItem(btn2)
 Else
  stateGame("win")
 End If	
End Sub
Sub btn1_Click
 If res <> btn1.Text Then
  wrongItem(btn1)
 Else
  stateGame("win")
 End If
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 = "3"
   common.stopAudio
   Activity.Finish
   StartActivity(frmGame1_result)
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
  If KeyCode = KeyCodes.KEYCODE_BACK Then
   common.stopAudio   
   Activity.Finish
   StartActivity(Main)
  End If
  If KeyCode = KeyCodes.KEYCODE_MENU Then
   Activity.OpenMenu
  End If
End Sub