注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你想快速掌握安卓编程吗

 
 
 

日志

 
 

[例程]九宫图解锁源码  

2015-08-19 14:31:55|  分类: B.图形 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
作者:风 *******916


[例程]九宫图解锁源码 - 沉默蜂 - 沉默蜂B4A安卓编程实战资料
例程运行效果图



#Region  Project Attributes 
#ApplicationLabel: 九宫图解锁
#VersionCode: 1
#VersionName: 
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
#FullScreen: False
#IncludeTitle: True
#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.
Dim iv(9) As ImageView
Dim key As String
Dim c As Canvas
Dim ivselect 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("Layout1")

c.Initialize(Activity)
Dim rect1 As Rect
rect1.Initialize(0,0,100%x,100%y)
c.DrawRect(rect1,Colors.Gray,True,1dip)
Dim w,wb,h,hb As Float
wb = 100%x /10
w = 100%x/5
h = w
Dim mod1,mod2 As Int
For i = 0 To 8
iv(i).Initialize("iv")
iv(i).Tag = i
If i = 0 OR i = 3 OR i = 6 Then mod1 = 0
If i = 1 OR i = 4 OR i = 7 Then mod1 = 1
If i = 2 OR i = 5 OR i = 8 Then mod1 = 2
mod2 = 0
If i >= 3 Then mod2 = 1
If i >= 6 Then mod2 = 2
Activity.AddView(iv(i),wb+(wb+w)*mod1,wb+(wb+h)*mod2,w,h)
iv(i).Bitmap = LoadBitmapSample(File.DirAssets,"key.png",w/2,h/2)
iv(i).SendToBack
Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub activity_Touch (Action As Int, X As Float, Y As Float)
If Action = 0 Then '按下
For i = 0 To 8
key = ""
Next
End If
If Action = 1 Then '松开
If key.Length<1 Then Return
If key = "01258" Then
Msgbox("解锁成功","消息")
Else
Msgbox("解锁失败","消息")
End If
For i = 0 To  8
iv(i).Bitmap = LoadBitmapSample(File.DirAssets,"key.png",iv(i).Width/2,iv(i).Height/2)
Dim rect1 As Rect
rect1.Initialize(0,0,100%x,100%y)
c.DrawRect(rect1,Colors.Gray,True,1dip)
Activity.Invalidate
Next
End If
If Action = 2 Then '移动
For i = 0 To  8
If key.IndexOf(i) = -1 Then
inSide(iv(i),X,Y,i)
End If
Next
End If
End Sub


Sub inSide(iv1 As ImageView,x As Float,y As Float,ii As Int) '检测是否移到图片上
If x>iv1.Left AND x<iv1.Left+iv1.Width Then
If y>iv1.Top AND y<iv1.Top+iv1.Height Then
Log(ii)
iv1.Bitmap = LoadBitmapSample(File.DirAssets,"key1.png",iv1.Width/2,iv1.Height/2)
key = key&ii
If key.Length = 1 Then
ivselect = iv(ii)
Else
If ivselect <> iv(ii) Then
Log(ii)
drawline(ivselect,iv(ii))
ivselect = iv(ii)
End If 
End If
End If
End If
End Sub

Sub drawline(iv1 As ImageView,iv2 As ImageView)
Dim x1,y1,x2,y2 As Float
x1 = iv1.Left + iv1.Width/2
y1 = iv1.Top + iv1.Height/2
x2 = iv2.Left + iv2.Width/2
y2 = iv2.Top + iv2.Height/2
c.drawline(x1,y1,x2,y2,Colors.Red,20dip)
Activity.Invalidate
End Sub
 
  评论这张
 
阅读(66)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017