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)
是我们亲爱的星梦乐园开发者