一个简洁的点金手,没有模块化的事例。供初学者参考。没有音乐音效可以自己添加。完整版本请到官方群聊

4 落花清雪梦寒希 2小时前 63次点击

require "import"

import "android.app.*"

import "android.os.*"

import "android.widget.*"

import "android.view.*"

import "android.speech.tts.TextToSpeech"

import "java.io.File"

import "android.widget.ScrollView"

import "com.tencent.qq.widget.*"

function 文件是否存在(路径, 写入内容)

local 完整路径 = activity.getLuaDir()..路径

local 文件 = File(完整路径)

local 存在 = 文件.exists()

if not 存在 and 写入内容 then

local 文件句柄 = io.open(完整路径, "w")

if 文件句柄 then

文件句柄:write(写入内容)

文件句柄:flush()

文件句柄:close()

end

end

return 存在

end

function 读取文件(路径)

local 文件 = io.open(activity.getLuaDir()..路径, "r")

if 文件 then

local 内容 = 文件:read("*a")

文件:close()

return 内容

end

return nil

end

function 写入文件(路径, 内容)

local 文件 = io.open(activity.getLuaDir()..路径, "w")

if 文件 then

文件:write(内容)

文件:flush()

文件:close()

end

end

function 语音()

import "android.speech.tts.*"

mTextSpeech = TextToSpeech(activity, TextToSpeech.OnInitListener{ onInit=function(status)

if (status == TextToSpeech.SUCCESS)

then result = mTextSpeech.setLanguage(Locale.CHINESE);

if (result == TextToSpeech.LANG_MISSING_DATA or result == TextToSpeech.LANG_NOT_SUPPORTED) then

result = mTextSpeech.setLanguage(Locale.ENGLISH);

if (result == TextToSpeech.LANG_MISSING_DATA or result == TextToSpeech.LANG_NOT_SUPPORTED) then

else

mTextSpeech.setPitch(1);

mTextSpeech.setSpeechRate(1);

end

else

mTextSpeech.setPitch(1);

mTextSpeech.setSpeechRate(1);

end

end

end

});

end

function 播报(你好)

mTextSpeech.speak(tostring(你好), TextToSpeech.QUEUE_FLUSH, nil);

end

语音()

文件是否存在("/积分.txt",0)

积分=读取文件("/积分.txt")

本局积分=0

时间=60

游戏状态=0

游戏准备时间=5

activity.setContentView

(

loadlayout

(

{

LinearLayout;

orientation='vertical';

layout_width='fill';

layout_height='fill';

{

TextView;

text="点击获得积分";

textSize="25sp";

layout_width="fill";

layout_height="fill";

id='点击区域';

}

}

)

)

剩余时间=Ticker()

剩余时间.Period=1000

剩余时间.onTick=function()

时间=时间-1

if 时间==0 then

游戏状态=0

剩余时间.stop()

剩余时间=nil

播报("本局积分"..本局积分.."点,总积分"..积分.."点,即将退出,请再接再厉。")

task(5000,function()

积分=积分+本局积分

写入文件("/积分.txt",积分)

task(os.exit())

end)

end

end

准备时间=Ticker()

准备时间.Period=1000

准备时间.onTick=function()

游戏准备时间=游戏准备时间-1

if 游戏准备时间==0 and 游戏状态==0 then

播报("开始")

准备时间.stop()

准备时间=nil

剩余时间.start()

游戏状态=1

else

播报(游戏准备时间)

end

end

function 开始游戏()

准备时间.start()

end

点击区域.onClick=function()

if 游戏状态==1 then

本局积分=本局积分+1

点击区域.setText("本局积分"..本局积分.."点,剩余时间"..时间.."秒,总积分"..读取文件("/积分.txt").."点。")

播报("本局积分"..本局积分.."点,剩余时间"..时间.."秒,总积分"..读取文件("/积分.txt").."点。")

elseif 游戏状态==0 and 游戏准备时间==0 then

点击区域.setText("游戏已结束,本局积分"..本局积分.."点,剩余时间"..时间.."秒,总积分"..读取文件("/积分.txt").."点。")

播报("游戏已结束,本局积分"..本局积分.."点,剩余时间"..时间.."秒,总积分"..读取文件("/积分.txt").."点,即将退出。")

end

end

参数=0

首次按下时间=0

function onKeyDown(代码,事件)

if string.find(tostring(事件),"KEYCODE_BACK")~=nil then

参数=参数+1

if 参数==1 then

首次按下时间=os.time()

播报("退出后不会保存你本局所得的积分,再按一次返回键退出。")

elseif 参数==2 then

当前时间=os.time()

if 当前时间-首次按下时间>1 then

参数=0

首次按下时间=0

else

task(os.exit())

end

end

return true

end

end

task(1000,function()

播报("准备!5")

task(1000,function()

开始游戏()

end)

end)

共 3 条评论
今夕何穗 2小时前
0 

是我们亲爱的星梦乐园开发者

落花清雪梦寒希 [楼主] 1小时前
0 
嗯。
今夕何穗 1小时前
0 

说实话,你是比较有辨识度的,这种比较有诗意的名字嗯。并且还非常的。什么什么什么

添加一条新评论

登录后可以发表评论 去登录

作者

积分:4827

6%5EX%5EY%5EA%5ER%5ENT%5ELW%5EZ%5EKT0X%5EA6RRY92U%5EW%5EQD%5EJL%5EC%5ETQ%5EM%5EWFP%5EY2T%5EZ%5ED%5EF%5EW%5EYMJ3%5ES%5ER%5EN67%5ES7%5EN%5EY%5ETH%5EZ1%5EXDO%5EF%5ES%5EVV%5EJ7D2%5EW3Z%5EQ1EF%2B%5EJ%5ELLW%5ELM%5EC%5EBU%5EWS%5ETZVC%5ED%5EH%5EA%5EG%5EE%5ER%5EL1%5ER6N3P1T%5EY3F%5EKB%5EI0SZ%5EU%5ED3%5EYA9LM