eda
disusedtodetermi
eifamoveshould记录上次移动的确
bemadebasedo
mMoveDelay切时间。
同mMoveDelay一起处理与用户的异步操privatelo
gmLastMove
作的协同问题。states
mStatusTexttextshowstotheuseri
someru
用来显示游戏状态的TextView
privateTextViewmStatusText
mS
akeTrail
alistofCoordi
atesthatmakeupthes
akesbodymAppleListthesecretlocatio
ofthejuicyapplesthes
akecraves子的坐标。
两个链表,分别用来存储蛇体和果每次蛇体的运动,蛇体的增长,产生新的
f苹果,被吃掉苹果,都会在这里记录。ArrayListmS
akeTrail
ewArrayListArrayListmAppleList
ewArrayList
private
private随机
Everyo
e
eedsalittlera
dom
essi
theirlife
数生成器。用来产生随机的苹果。在addRa
domApple中使用。Ra
domprivatestaticfi
alRa
domRNG
ewCreateasimpleha
dlerthatweWeset
ca
usetocausea
imatio
tohappe
ourselvesasatargeta
dweca
usethesleep
fu
ctio
tocausea
updatei
validatetooccuratalaterdate用Ha
dler机制实现定时刷新。为什么
使用Ha
dler呢?大家可以参考a
droid的线程模型(注意UI线程不是线程安全的~)源很多,在此不赘述~具体使用方法网上的资privateRefreshHa
dlerclass
mRedrawHa
dler
ewRefreshHa
dlerRefreshHa
dlerexte
dsHa
dlerOverridemsg
获取消息并处理
publicvoidha
dleMessageMessageS
akeViewthisupdate
S
akeViewthisi
validate刷新view为基类的界面新的效果。定时发送消息给UI线程,以此达到更publicvoidsleeplo
gdelayMillis
thisremoveMessages0清空消息队列,Ha
dler进入
f对新消息的等待se
dMessageDelayedobtai
Message0delayMillis定时发送新消息激活ha
dlerpublic
S
akeViewCo
textco
textAttributeSetattrssuperco
textattrsi
itS
akeViewpublic
构造函数中,别忘了,初始化游戏~
S
akeViewCo
textco
textAttributeSetattrsi
tdefStylesuperco
textattrsdefStylei
itS
akeView初始化S
akeView类,注意,privatevoid
这根初始化游戏是不一样的。i
itS
akeView
setFocusabletrue设置焦点,
由于存在文字界面和游戏界面的跳转。这个focus是不可或缺的。取得资源中的图片,加载到砖块字典中。
ResourcesrthisgetCo
textgetResourcesresetTiles4loadTileRED_STAR
rgetDrawableRdrawableredstarloadTileYELLOW_STARrgetDrawableRdrawableyellowstarloadTileGREEN_STARrgetDrawableRdrawablegree
star
如果不是从暂停中回复,就绪要初始化游戏了。privatevoidi
itNewGame清空保存蛇体和果
f子的数据结构。mAppleListclear
mS
akeTrailclearFor
owwerer