function Game() {
const EXPRESSES = [
'img/doctor_od.png',
'img/doctor_od2.png',
'img/doctor_od3.png',
'img/doctor_od4.png',
'img/doctor_od5.png',
'img/doctor_od6.png',
'img/doctor_od7.png'
];
/////////* 横向き強制処理 */////////
var isReverse = false; //正面が逆かどうかのフラグを用意しておく
if (navigator.userAgent.indexOf('Android') > 0) {
//Androidなら正面設定を確認
var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
if (orientation.type === "portrait-secondary" || orientation.type === "landscape-primary") {
isReverse = true;
}
}
function orientCheck() {
if (isReverse) {
//正面が逆の場合
var orientation = window.orientation;
if (orientation === 0) {
/* 縦画面時の処理 */
return 0;
} else {
/* 横画面時の処理 */
return 1;
}
} else {
var orientation = window.orientation;
if (orientation === 0) {
/* 縦画面時の処理 */
return 0;
} else {
/* 横画面時の処理 */
return 1;
}
}
}
function getWindowRatio(flag) {
if (flag != 1) flag = 0;
if (orientCheck() ^ flag) {
return window.innerHeight / window.innerWidth;
}
return window.innerWidth / window.innerHeight;
}
function aspectRatioCheck(flag) {
var result = UAParser();
if (result.device.type == "tablet") {
return 1;
}
return 0;
/*
if (getWindowRatio(flag) < 1.7)
return 1;
return 0;*/
}
$(window).on("orientationchange", function () {
setIsLandscpae(orientCheck());
setIsSquareDevice(aspectRatioCheck(1));
});
// 初期化
let cookies = document.cookie;
let cookiesArray = cookies.split('; ');
let _affinity = 0;
let _isSound = 0; // 新規ユーザorリピータの検知にも使う
for (var c of cookiesArray) {
var cArray = c.split('=');
// 取り出したいkeyと合致したら分岐
if (cArray[0] == 'affinity') {
// 好感度
_affinity = parseInt(decodeURIComponent(
cArray[1]
))
}
else if (cArray[0] == 'isSound') {
// 音を出すかどうか
_isSound = parseInt(decodeURIComponent(
cArray[1]
))
}
}
const [affinity, setAffinity] = React.useState(_affinity);
const [isSound, setIsSound] = React.useState(_isSound)
const [phase, setPhase] = React.useState(0); // 会話段階
const [isClickThinkingMessage, setIsClickThinkingMessage] = React.useState(true);
const [isAskingMessage, setIsAskingMessage] = React.useState(false);
const [isClickAskingMessage, setIsClickAskingMessage] = React.useState(true);
const [isSpeakingMessage, setIsSpeakingMessage] = React.useState(false);
const [isClickSpeakingMessage, setIsClickSpeakingMessage] = React.useState(true);
const [isLovingMessage, setIsLovingMessage] = React.useState(false);
const [isAskMurabanku, setIsAskMurabanku] = React.useState(false);
const [isMenuToggle, setIsMenuToggle] = React.useState(false);
const [isLandscape, setIsLandscpae] = React.useState(orientCheck());
const [isSquareDevice, setIsSquareDevice] = React.useState(aspectRatioCheck(1));
// 処理
document.getElementById("bgm").play();
function onClickedHamburger() {
if (!isMenuToggle) {
setIsMenuToggle(true);
} else {
setIsMenuToggle(false);
};
}
function increaseAffinity() {
document.cookie = "affinity=" + encodeURIComponent(affinity + 1);
setAffinity(affinity + 1);
// console.log(document.cookie);
};
function onClikedDoor(kind) {
switch (kind) {
case 'soundOn':
document.cookie = "isSound=" + encodeURIComponent(1) + "; max-age=300";
document.getElementById("se-door").currentTime = 0;
document.getElementById("se-door").play();
setTimeout(function () { //Start the timer
setIsSound(1);
}.bind(this), 1000);
break;
case 'soundOff':
document.cookie = "isSound=" + encodeURIComponent(-1);
setIsSound(-1);
break;
case 'exit':
document.getElementById("se-exit").currentTime = 0;
document.getElementById("se-exit").play();
window.location.href = 'https://www.youtube.com/watch?v=9otoX9Q3YJg&t=233s';
break;
}
}
function onClikedSpeechBubble(kind) {
// console.log("kind=" + kind);
switch (kind) {
case 'thinking':
if (isClickThinkingMessage) {
setIsClickThinkingMessage(false);
setTimeout(function () { //Start the timer
setPhase(phase + 1);
setIsAskingMessage(true);
}.bind(this), 1000);
}
break;
case 'asking':
if (isClickAskingMessage) {
setIsClickAskingMessage(false);
setTimeout(function () { //Start the timer
setPhase(phase + 1);
setIsSpeakingMessage(true);
}.bind(this), 1000);
}
break;
case 'speaking':
if (isClickSpeakingMessage) {
increaseAffinity();
}
setIsClickSpeakingMessage(false);
setIsLovingMessage(true);
break;
}
}
function renderSpeechBubble(id, kind, clickable, handleClick) {
return (