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
const 文本显示元素 = document.getElementById('文本显示区域');
let 首次触摸横坐标 = 0;
let 首次触摸纵坐标 = 0;
let 上次点击时间 = 0;
let 点击次数 = 0;
const 左右滑动音效音频 = new Audio('yx/1');
const 双击音效音频 = new Audio('yx/3');
const 背景音乐音频 = new Audio('yy/z1.mp3');
const pageConfigs = {
"开始游戏":
{
audioPath: 'dp/1.wav',
href: ""
},
"更新日志":
{
audioPath: 'dp/2.wav',
href: ""
},
"关于":
{
audioPath: 'dp/3.wav',
href: ""
},
"用户协议":
{
audioPath: 'dp/4.wav',
href: ""
},
"隐私政策":
{
audioPath: 'dp/5.wav',
href: ""
}
};
window.onload = function ()
{
背景音乐音频.loop = true;
document.addEventListener('touchstart', handleTouchStart);
document.addEventListener('touchmove', handleTouchMove);
document.addEventListener('touchend', handleTouchEnd);
}
function handleTouchStart(e)
{
if (背景音乐音频.paused)
{
背景音乐音频.play().catch(function (error) {
console.log('背景音乐播放出错:', error);
}
);
}
const 触摸点 = e.touches[0];
首次触摸横坐标 = 触摸点.pageX;
首次触摸纵坐标 = 触摸点.pageY;
}
function handleTouchMove(e) {}
function handleTouchEnd(e)
{
const 触摸点 = e.changedTouches[0];
const 当前横坐标 = 触摸点.pageX;
const 横坐标差值 = 当前横坐标 - 首次触摸横坐标;
const 横坐标移动差值 = 当前横坐标 - 首次触摸横坐标;
const 移动距离 = Math.sqrt(横坐标移动差值 * 横坐标移动差值);
const 当前时间 = Date.now();
if ((Math.abs(横坐标移动差值) > 50 && 移动距离 > 50)
||
(当前时间 - 上次点击时间 < 500 && Math.abs(触摸点.pageX - 首次触摸横坐标) <= 30 && Math.abs(触摸点.pageY - 首次触摸纵坐标) <= 30)) {
const currentText = 文本显示元素.textContent;
const isSlide = Math.abs(横坐标移动差值) > 50 && 移动距离 > 50;
const isDoubleClick = 当前时间 - 上次点击时间 < 500 && Math.abs(触摸点.pageX - 首次触摸横坐标) <= 30 && Math.abs(触摸点.pageY - 首次触摸纵坐标) <= 30;
if (isSlide)
{
let targetText = "";
if (横坐标移动差值 < 0)
{
targetText = getPrevText(currentText);
}
else
{
targetText = getNextText(currentText);
}
if (targetText)
{
handleTextChangeAndAudio(currentText, targetText);
播放左右滑动音效();
}
}
if (isDoubleClick)
{
点击次数++;
if (点击次数 === 2)
{
handleDoubleClick(currentText);
点击次数 = 0;
}
}
上次点击时间 = 当前时间;
}
}
function getPrevText(currentText)
{
const texts = Object.keys(pageConfigs);
const currentIndex = texts.indexOf(currentText);
return currentIndex === 0? texts[texts.length - 1] : texts[currentIndex - 1];
}
function getNextText(currentText)
{
const texts = Object.keys(pageConfigs);
const currentIndex = texts.indexOf(currentText);
return currentIndex === texts.length - 1? texts[0] : texts[currentIndex + 1];
}
function handleTextChangeAndAudio(currentText, targetText)
{
文本显示元素.textContent = targetText;
const audio = new Audio(pageConfigs[targetText].audioPath);
audio.pause();
audio.currentTime = 0;
audio.play();
}
function handleDoubleClick(currentText) {
const 双击音效克隆 = 双击音效音频.cloneNode(true);
双击音效克隆.addEventListener('ended', function () {
window.location.href = pageConfigs[currentText].href;
}
);
双击音效克隆.play();
}
function 播放左右滑动音效()
{
左右滑动音效音频.pause();
左右滑动音效音频.currentTime = 0;
if (左右滑动音效音频.readyState === 4)
{
左右滑动音效音频.play();
}
else
{
左右滑动音效音频.addEventListener('canplaythrough', function () {
左右滑动音效音频.play();
}
);
}
}