Android Question How to calculate the game score

Htar Htar Lwin

Member
Licensed User
Longtime User
I'm developing an english learning game project.
When a player overlap an item (horizontal word) over another item (vertical word), we will check whether one character of lower item is same to one character of upper one. If those are same, we will pay one score per character.
For example, if player overlap 'son' (horizontal) on `brother´ (vertical) he will get 9 marks.
Because `o´ of son and `o´ of `brother´ is same and total number of character is 9 (3+7-overlap 1) of both items.
I want to know how to calculate game score.

Player can add same word more than one time.
She/he can remove any item already added.
//Main Moduld
#Region Project Attributes
#ApplicationLabel: Barry's Word Train
#VersionCode: 100
#VersionName: 1.0.0
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region

#Region Activity Attributes
#FullScreen: True
#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 TTS As TTS
Dim MP As MediaPlayer
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.

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
If FirstTime Then
TTS.Initialize("TTS")
MP.Initialize2("MP")
End If
End Sub

Sub Activity_Resume
MP.Load(File.DirAssets,"Kalimba.mp3")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
MP.Release
End Sub

Sub btnGo_Click
StartActivity(Level1)
End Sub

Sub btnQuit_Click
Activity.Finish
End Sub

//Level1 Module
#Region Activity Attributes
#FullScreen: True
#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.

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.


Private imgLevel1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Level1Menu")

imgLevel1.Width = 100%x
imgLevel1.Height = 100%y

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnMyFamily_Click
StartActivity(Family)
End Sub

//Family Module
#Region Activity Attributes
#FullScreen: True
#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 lstH, lstV As List
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.
Private imgBanner As ImageView
Private imgGrid As ImageView
Dim idx, idy As Int
Private imgAuntHH As ImageView
Private imgBoyHH As ImageView
Private imgBrotherHH As ImageView
Private imgDaughterHH As ImageView
Private imgFamilyHH As ImageView
Private imgFatherHH As ImageView
Private imgFriendHH As ImageView
Private imgGirlHH As ImageView
Private imgMotherHH As ImageView
Private imgSisterHH As ImageView
Private imgSonHH As ImageView
Private imgUncleHH As ImageView

Private imgEnd As ImageView
Private imgTitle As ImageView

Dim H1, H2 , H3 , H4, H5, H6 , H7, H8, H9, H10, H11, H12 As DraggableView
Dim H13, H14 , H15 , H16, H17, H18, H19, H20, H21, H22, H23, H24 As DraggableView
Dim H25, H26 , H27 , H28, H29, H30, H31, H32, H33, H34, H35, H36 As DraggableView
Dim H37, H38 , H39 , H40, H41, H42, H43, H44, H45, H46, H47, H48 As DraggableView
Dim V1, V2 , V3 , V4, V5, V6 , V7, V8, V9, V10, V11, V12 As DraggableView
Dim V13, V14 , V15 , V16, V17, V18, V19, V20, V21, V22, V23, V24 As DraggableView
Dim V25, V26 , V27 , V28, V29, V30, V31, V32, V33, V34, V35, V36 As DraggableView
Dim V37, V38 , V39 , V40, V41, V42, V43, V44, V45, V46, V47, V48 As DraggableView
Dim End1 As DraggableView

Dim ArH(), ArV() As DraggableView
idx = 0
idy = 0

Dim ani As Animation
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
If FirstTime Then
lstH.Initialize
lstV.Initialize
End If

lstH.AddAll(Array As DraggableView(H1, H2 , H3 , H4, H5, H6 , H7, H8, H9, H10, H11, H12,H13, H14 , H15 , H16, H17, H18, H19, H20, H21, H22, H23, H24,H25, H26 , H27 , H28, H29, H30, H31, H32, H33, H34, H35, H36,H37, H38 , H39 , H40, H41, H42, H43, H44, H45, H46, H47, H48))
lstV.AddAll(Array As DraggableView(V1, V2 , V3 , V4, V5, V6 , V7, V8, V9, V10, V11, V12,V13, V14 , V15 , V16, V17, V18, V19, V20, V21, V22, V23, V24,V25, V26 , V27 , V28, V29, V30, V31, V32, V33, V34, V35, V36,V37, V38 , V39 , V40, V41, V42, V43, V44, V45, V46, V47, V48))
Activity.LoadLayout("MyFamily")

imgBanner.Width = 360dip
imgBanner.Height =100dip

imgTitle.Width = 360dip
imgTitle.Height = 200dip
imgTitle.Top = 460dip

imgAuntHH.Width = 120dip
imgBoyHH.Width = 90dip
imgBrotherHH.Width = 210dip
imgDaughterHH.Width = 240dip
imgFamilyHH.Width = 180dip
imgFatherHH.Width = 180dip
imgFriendHH.Width = 180dip
imgGirlHH.Width = 120dip
imgMotherHH.Width = 180dip
imgSisterHH.Width = 180dip
imgSonHH.Width = 90dip
imgUncleHH.Width = 150dip

For i = 2 To 13
Activity.GetView(i).Height = 30dip
Next

imgSonHH.Top = 490dip
imgBoyHH.Top = 460dip
imgAuntHH.Top = 520dip
imgGirlHH.Top = 550dip
imgUncleHH.Top = 610dip
imgFamilyHH.Top = 520dip
imgFatherHH.Top = 550dip
imgFriendHH.Top = 580dip
imgMotherHH.Top = 610dip
imgSisterHH.Top = 580dip
imgBrotherHH.Top = 490dip
imgDaughterHH.Top = 460dip

imgFamilyHH.Left = 180dip
imgFatherHH.Left = 180dip
imgFriendHH.Left = 180dip
imgMotherHH.Left = 180dip
imgBrotherHH.Left = 150dip
imgDaughterHH.Left = 120dip

imgGrid.Width = 360dip
imgGrid.Height = 360dip
imgGrid.Top = 100dip

imgEnd.Top = 400dip
imgEnd.Left = 300dip
imgEnd.Width = 60dip
imgEnd.Height = 60dip
imgEnd.BringToFront

'End1.Initialize(Activity,imgEnd)


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub IntToDIP(Integer As Int) As Int
Dim r As Reflector
Dim scale As Float
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics")
scale = r.GetField("density")

Dim DIP As Int
DIP = Integer * scale + 0.5
Return DIP
End Sub

Sub imgEnd_Click
Msgbox(Activity.NumberOfViews,"Hi")
End Sub

Sub imgMove_Click

Dim img, imgH As ImageView
img.Initialize("")
imgH.Initialize("")
Dim imgtag As String
Dim L As Int
Dim Temp As DraggableView

img = Sender

imgtag = img.Tag
L = imgtag.Length * 30

Main.TTS.Speak(imgtag, True)

imgH.Bitmap = LoadBitmap(File.DirAssets,img.tag & "-h.png")
imgH.Gravity = Gravity.FILL

Activity.AddView(imgH, 0dip, 100dip, IntToDIP(L), 30dip)
Temp = lstH.Get(idx)
idx = idx + 1
Temp.Initialize(Activity, imgH)
ani.InitializeRotateCenter("",0,360,imgH)
ani.Duration = 1000
ani.Start(imgH)
End Sub

Sub imgMove_LongClick
Dim img, imgV As ImageView
img.Initialize("")
imgV.Initialize("")
Dim imgtag As String
Dim L As Int
Dim Temp As DraggableView
img = Sender
imgtag = img.Tag
L = imgtag.Length * 30

Main.TTS.Speak(imgtag, True)

imgV.Bitmap = LoadBitmap(File.DirAssets,img.tag & "-v.png")
imgV.Gravity = Gravity.FILL

Activity.AddView(imgV, 0dip, 100dip, 30dip, IntToDIP(L))
Temp = lstV.Get(idy)
idy = idy + 1
Temp.Initialize(Activity, imgV)
ani.InitializeRotateCenter("",0,360,imgV)
ani.Duration = 1000
ani.Start(imgV)
End Sub

//Class Module

'Class module
Sub Class_Globals
Private innerView As View
Private panel1 As Panel
Private downx, downy As Int
Private ACTION_DOWN As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Activity As Activity, v As View)
innerView = v
panel1.Initialize("")
panel1.Color = Colors.Transparent
Activity.AddView(panel1, v.Left,v.Top,v.Width, v.Height)'v.Left, v.Top, v.Width, v.Height)
ACTION_DOWN = Activity.ACTION_DOWN
Dim r As Reflector
r.Target = panel1
r.SetOnTouchListener("Panel1_Touch") 'why reflection instead of the regular Panel_Touch event? Good question which deserves a forum thread of its own (not related to classes)...
End Sub

Private Sub Panel1_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
If ACTION = ACTION_DOWN Then
downx = x
downy = y
'Main.MP.Play
Else
innerView.Left = innerView.Left + x - downx
innerView.Top = innerView.Top + y - downy

If (innerView.Left Mod 120) > 60 Then
innerView.Left =innerView.Left + (120 - innerView.Left Mod 120)
Else If (innerView.Left Mod 120) <= 60 Then
innerView.Left = innerView.Left - innerView.Left Mod 120
End If

If ((innerView.Top - 400) Mod 120) > 60 Then
innerView.Top =innerView.Top + (120 - (innerView.Top - 400) Mod 120)
Else If ((innerView.Top - 400) Mod 120) <= 60 Then
innerView.Top = innerView.Top - (innerView.Top - 400) Mod 120
End If

panel1.Left = innerView.Left
panel1.Top = innerView.Top
If panel1.Top = 460dip Then
innerView.SendToBack
End If
End If

Return True
End Sub
 
Last edited:

Widget

Well-Known Member
Licensed User
Longtime User
Please paste your code between
[CODE ]
... your code goes here...
[/CODE ]

so it is more readable. (Remove all blanks from within the brackets "[ ]") and do a Preview before posting.
Thanks.
 
Upvote 0
Top