1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714 |
- <!doctype html>
- <html class="no-js" lang="">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="x-ua-compatible" content="ie=edge">
- <title>心理胜任能力评估系统</title>
- <meta name="description"
- content="A website that learns to predict where you are looking at. Written in TensorFlow.js">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <link rel="stylesheet" href="normalize.css">
- <link rel="stylesheet" href="style.css">
- <style>
- .buttonArr button {
- position: fixed;
- width: 10px;
- height: 1px;
- /* opacity: 0.0; */
- z-index: 2000;
- color: #000000;
- border-radius: 10px;
- border: 0px;
- }
- .buttonArr {
- position: unset !important;
- width: 1px;
- height: 0px;
- opacity: 0.0;
- z-index: 2000;
- border-radius: 10px;
- border: 0px;
- }
- #num1 {
- position: absolute;
- left: 20px;
- top: 20px;
- }
- #num2 {
- position: absolute;
- left: 33%;
- top: 20px;
- }
- #num3 {
- position: absolute;
- left: 66%;
- top: 20px;
- }
- #num4 {
- position: absolute;
- right: 80px;
- top: 20px;
- }
- #num5 {
- position: absolute;
- left: 20px;
- top: 33%;
- }
- #num6 {
- position: absolute;
- left: 33%;
- top: 33%;
- }
- #num7 {
- position: absolute;
- left: 66%;
- top: 33%;
- }
- #num8 {
- position: absolute;
- right: 80px;
- top: 33%;
- }
- #num9 {
- position: absolute;
- left: 20px;
- top: 66%;
- }
- #num10 {
- position: absolute;
- left: 33%;
- top: 66%;
- }
- #num11 {
- position: absolute;
- left: 66%;
- top: 66%;
- }
- #num12 {
- position: absolute;
- right: 80px;
- top: 66%;
- }
- #num13 {
- position: absolute;
- left: 20px;
- bottom: 0px;
- }
- #num14 {
- position: absolute;
- left: 33%;
- bottom: 0px;
- }
- #num15 {
- position: absolute;
- left: 66%;
- bottom: 0px;
- }
- #num16 {
- position: absolute;
- right: 80px;
- bottom: 0px;
- }
- #targetMini {
- background-color: #00FF00;
- position: absolute;
- border-radius: 50%;
- height: 55px;
- width: 55px;
- /* z-index: 0; */
- opacity: 0.5;
- left: 0;
- bottom: 0;
- top: 0;
- right: 0;
- margin: auto;
- z-index: 999;
- transition: 1s;
- transition-timing-function: steps(1000, start);
- border: 2.5px solid #000000;
- }
- #target {
- /* text-align: center; */
- justify-content: center;
- background-image: url('calibrate.png');
- background-size: 120px 120px;
- /* background-color: lightgreen; */
- position: fixed;
- /* position: absolute; */
- border-radius: 50%;
- height: 120px;
- width: 120px;
- left: 0px;
- top: 0px;
- transition: left 0.01s, top 0.01s;
- box-shadow: 0 0 10px 5px white;
- opacity: 0.5;
- display: inline-block;
- z-index: 999;
- }
- #targetMini1 {
- background-color: #00FF00;
- /* position: absolute; */
- position: absolute;
- border-radius: 50%;
- height: 54px;
- width: 54px;
- /* z-index: 0; */
- opacity: 0.6;
- left: 0;
- bottom: 0;
- top: 0;
- right: 0;
- margin: auto;
- z-index: 999;
- transition: 1s;
- transition-timing-function: steps(1000, start);
- border: 3px solid #000000;
- }
- #target1 {
- /* text-align: center; */
- justify-content: center;
- background-image: url('calibrate.png');
- background-size: 60px 60px;
- /* background-color: lightgreen; */
- position: relative;
- /* position: absolute; */
- border-radius: 50%;
- height: 60px;
- width: 60px;
- left: 0px;
- top: 0px;
- transition: left 1s, top 1s;
- box-shadow: 0 0 10px 5px white;
- opacity: 0.9;
- display: inline-block;
- z-index: 999;
- }
- #refresh {
- width: 60px;
- font-size: 10px;
- position: fixed;
- top: 0px;
- left: 90%;
- display: inline-block;
- z-index: 999;
- margin-left: -40px;
- top: 2%;
- background-color: rgb(127, 178, 255);
- line-height: 30px;
- color: aliceblue;
- /* border: 1px solid; */
- text-align: center;
- border-radius: 5px;
- cursor: pointer;
- }
- #exit {
- width: 60px;
- font-size: 10px;
- position: fixed;
- top: 0px;
- left: 98%;
- display: inline-block;
- z-index: 999;
- margin-left: -40px;
- top: 2%;
- background-color: rgb(127, 178, 255);
- line-height: 30px;
- color: aliceblue;
- /* border: 1px solid; */
- text-align: center;
- border-radius: 5px;
- cursor: pointer;
- /* padding: 5px; */
- }
- #startCalibration {
- position: fixed;
- top: 0px;
- left: 50%;
- display: inline-block;
- margin-left: -40px;
- top: 30%;
- color: aliceblue;
- background-color: rgb(127, 178, 255);
- width: 80px;
- line-height: 40px;
- /* border: 1px solid; */
- text-align: center;
- border-radius: 5px;
- cursor: pointer;
- padding: 5px;
- }
- #came {
- position: fixed;
- top: 5%;
- left: 50%;
- margin-left: -100px;
- color: #ffffff;
- /* font-size: 16px;
- right:0px;
- bottom:0; */
- background-color: #666666;
- padding-top: 5px;
- padding-left: 5px;
- padding-right: 5px;
- padding-bottom: 5px;
- border-radius: 5px;
- ;
- z-index: 9999
- }
- </style>
- </head>
- <body>
- <div id="content">
- <div class="buttonArr">
- <button id='num1'> </button><button id="num2"> </button><button id="num3"> </button><button
- id='num4'> </button><br>
- <button id='num5'> </button><button id='num6'> </button><button id='num7'> </button><button
- id='num8'> </button><br>
- <button id='num9'> </button> <button id='num10'> </button> <button id='num11'> </button> <button
- id='num12'> </button><br>
- <button id='num13'> </button> <button id='num14'> </button> <button id='num15'> </button> <button
- id='num16'> </button>
- </div>
- <div id="target">
- <div id="targetMini"></div>
- </div>
- <div id="target1">
- <div id="targetMini1"></div>
- </div>
- <canvas id="solar" width="900" height="auto" style="background:#000000;position: fixed; z-index:998"></canvas>
- <div id="came">摄像头初始化中稍后再试...</div>
- <!-- <div id="finishcalibration" margin-left:300px;position: fixed;top:60px
- style="position: fixed;top:20px;left:20px;display: inline-block;width: 80px;height: 17px;border:1px solid;text-align: center;border-radius: 5px;cursor: pointer;padding: 5px;">
- 关闭校正</div> onclick="startCal()" -->
- <!-- <div id="startCalibration">
- 开始校准</div> -->
- <div id="exit">
- 切换游戏</div>
- <div id="refresh">
- 重新校验</div>
- <canvas id="tracker-canvas"
- style="position: fixed;top:0px;left:50%;width:250px;height:200px;margin-left:-125px;"></canvas>
- </div>
- <!-- <script src="js/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
- crossorigin="anonymous"></script> -->
- <script src="js/jquery-3.3.1.min.js"></script>
- <script src="js/gazefilter.js"></script>
- <script src="js/aes.js" type="text/javascript" charset="utf-8"></script>
- <!--script src="js/calibration.js"></script-->
- <script>
- var pre_path = window.location.origin;
- $('#came').hide()
- var soundSrc = 'sound/fruitMus1.mp3'
- var mp3Url = soundSrc;
- var soundFlag = true;
- var cameraFlag = true
- //点击按钮声音
- var soundButtonSrc = 'sound/button.mp3'
- var mp3Button = soundButtonSrc
- var playerButton = new Audio(mp3Button);
- //切水果音效
- var soundHitSrc = 'sound/fruitHit.mp3'
- var mp3Hit = soundHitSrc
- var playerHit = new Audio(mp3Hit)
- //背景音乐
- var soundBgSrc = 'sound/fruitMusicBg.mp3'
- var mp3Bg = soundBgSrc
- var playerBg = new Audio(mp3Bg)
- //Total score
- var totalScore = 0;
- var player = new Audio(mp3Url);
- var key = CryptoJS.enc.Utf8.parse("Sp5biS+gX+#CqAFF");//密钥
- var iv = CryptoJS.enc.Utf8.parse('ud2E8l6wchltwIDA');
- //传输参数为字符串
- function Encrypt(word) {
- let srcs = CryptoJS.enc.Utf8.parse(word);
- let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
- return encrypted.ciphertext.toString().toUpperCase();
- }
- function Decrypt(word) {
- let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
- let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
- let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
- let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
- return decryptedStr.toString();
- }
- // levelFun(2, 20)
- //
- //传输关卡和得分的字符串
- function levelFun(level, score) {
- //1----获取userId
- // let userMi = sessionStorage.getItem('B922C64EC97B4FF08485886B2AAEF40C')
- // //解密userMi
- // let user = Decrypt(userMi)
- // //需要传输的参数
- // let userId = JSON.parse(user).id
- // //2----获取唯一标识
- // let associatedFlag = new Date().getTime() + '';
- // var params = {
- // userId: userId,
- // associatedFlag: associatedFlag,
- // gameFlag: 'g_ydrzxlqsg',
- // checkPoint: level.toString(),
- // level: level.toString(),
- // score: score.toString(),
- // performance: {
- // correct: 0.9, //当前难度等级正确率
- // reactionTime: 400, //当前难度等级平均反应时间
- // clickTime: 1231
- // },
- // data: {
- // index: 1, //序号
- // needResponse: 0, //是否需要反应 0无需反应,1需反应
- // responseTrue: true, //反应是否正确 true false
- // responseTime: 766
- // }
- // }
- // // Encrypt(JSON.stringify(params))
- // // console.log(Encrypt(JSON.stringify(params)))
- // //给参数加密
- // let paramsMi = Encrypt(JSON.stringify(params))
- // //config.headers.Authorization = oSessionStorage.getItem("token") ? `Bearer ${oSessionStorage.getItem('token')}` : '';
- // let tokenLin = Decrypt(sessionStorage.getItem(Encrypt('token'))) || '';
- // $.ajax({
- // url: "https://gengnao.cn:8070/gameLevelRecord/saveResult", //请求接口的地址
- // type: "POST",
- // contentType: "json/application",
- // dataType: 'json', //请求的方法GET/POST
- // data: JSON.stringify({ data: paramsMi }),
- // headers: {
- // 'Authorization': "Bearer " + tokenLin,
- // }, //需要传递的参数
- // success: function (res) {
- // res = Decrypt(res)
- // //调用解密方法 //请求成功后的操作 //在控制台输出返回结果
- // },
- // error: function (err) { //请求失败后的操作 //请求失败在控制台输出22
- // }
- // })
- }
- function getQueryString(name) {
- const url_string = window.location.href; // window.location.href
- const url = new URL(url_string);
- return url.searchParams.get(name);
- }
- // saveResult(20)
- function saveResult(score) {
- //1----获取userId
- let userMi = sessionStorage.getItem('b80bb7740288fda1f201890375a60c8f')
- //解密userMi
- // let user = Decrypt(userMi)
- //需要传输的参数
- let userId = userMi
- //2----获取唯一标识
- let associatedFlag = new Date().getTime() + '';
- var params = {
- userId: userId,
- // associatedFlag: associatedFlag,
- // gameFlag: 'g_ydrzxlqsg',
- score: score,
- testPlanId: getQueryString('testPlanId')
- }
- let paramsMi = Encrypt(JSON.stringify(params))
- let paramsLin =userId+'token'
- let tokenLin = localStorage.getItem(paramsLin);
- //http://cognitive.wistcm.com
- //pre_path +
- $.ajax({
- // url: "http://cognitive.wistcm.com:8090/cognize/CutFruit", //请求接口的地址
- url: "http://localhost:8099/cognize/CutFruit", //请求接口的地址
- type: "POST",
- contentType: "json/application",
- dataType: 'json',
- headers: {
- 'Authorization': "Bearer " + tokenLin,
- }, //请求的方法GET/POST
- data: JSON.stringify({ data: paramsMi }), //需要传递的参数
- success: function (res) {
- // window.history.back()
- // res = Decrypt(res)
- //调用解密方法 //请求成功后的操作 //在控制台输出返回结果
- },
- error: function (err) { //请求失败后的操作 //请求失败在控制台输出22
- }
- })
- }
- //切水果游戏变量
- let apple;
- let appleLeft;
- let appleRight;
- let banana;
- let bananaLeft;
- let bananaRight;
- let sandia;
- let sandiaLeft;
- let sandiaRight;
- let basaha;
- let basahaLeft;
- let basahaRight;
- let bg;
- let ctx;
- let widthLeft;
- //退出按钮
- let button1;
- let button2;
- //等于1时代表在水果游戏页面
- //等于2时代表在抓虫子页面
- let fruitFlag = 1;
- //水果下降的速度
- let y = [20, 20, 20, 20];
- let speed = [1, 1.5, 1.3, 1.4];
- let x = [100, 300, 500, 700]
- let rondom;
- let timer;
- //设置水果的起点
- let fruitStart = 10
- //设置说过的结尾
- let fruitEnd = 900;
- //是否隐藏
- let flag = [true, true, true, true]
- //苹果左右碎片
- let apple_x_left = x[0];
- let apple_x_right = x[0];
- let banana_x_left = x[1];
- let banana_x_right = x[1]
- let sandia_x_left = x[2];
- let sandia_x_right = x[2]
- let basaha_x_left = x[3];
- let basaha_x_right = x[3];
- let targ = [0, 0]
- let tempCanvasFruit;
- let tempCtxFruit;
- let patternFruit;
- //水果倒计时初始时间
- let startTimeFruit;
- //设置倒计时结束时间
- let endTimeFruit;
- let canvas = document.getElementById('solar');
- ctx = canvas.getContext("2d");
- window.addEventListener("resize", resizeCanvas, false);
- let countdownFlag = false;
- let diff = 1;
- let count = 0
- //第几关进行提示
- let diffFlag = false;
- //通关提示
- //当passFlag默认为1为正常状态
- //当passFlag为2时为超时未通过状态
- //当passFlag为3时为已通关状态
- let passFlag = 1;
- //训练提示页flag
- let trainingFlag = 1
- //第一张训练图片
- let trainOne;
- let trainTwo;
- let trainThree;
- let trainFour;
- let onStep;
- let underStep;
- let startGame;
- let backMa;
- //通关图片
- let success;
- //声音的图片
- let soundImgClose;
- let soundImgOpen;
- //canvas监听事件
- canvas.addEventListener("mouseup", clickButton);
- function resizeCanvas() {
- canvas.width = window.innerWidth;
- x = [canvas.width / 5, canvas.width / 5 * 2, canvas.width / 5 * 3, canvas.width / 5 * 4]
- xWorm = [canvas.width / 5, canvas.width / 5 * 2, canvas.width / 5 * 3, canvas.width / 5 * 4]
- // canvas.height = window.innerHeight;
- canvas.height = window.innerHeight;
- fruitEnd = canvas.height
- wormStart = canvas.height
- //canvas.height = '100vh';
- apple_x_left = x[0];
- apple_x_right = x[0];
- banana_x_left = x[1];
- banana_x_right = x[1]
- sandia_x_left = x[2];
- sandia_x_right = x[2]
- basaha_x_left = x[3];
- basaha_x_right = x[3];
- }
- //获取
- // init()
- //初始化切水果的图
- //第几关2秒显示
- function middleFont() {
- diffFlag = true;
- setTimeout(() => {
- diffFlag = false;
- }, 2000);
- }
- function soundChange() {
- if (soundFlag) {
- soundOpen()
- } else {
- soundClose()
- }
- }
- function clickButton(event) {
- //鼠标在当前画布的位置
- // let x1 = event.clientX;
- // let y1 = event.clientY;
- let x = event.clientX - canvas.getBoundingClientRect().left;
- let y = event.clientY - canvas.getBoundingClientRect().top;
- //判断点是否在长方形内
- //当在第一步训练时 只有一个按钮下一步的按钮
- if (trainingFlag == 1) {
- if (x > (canvas.width / 2 - 80) && x < (canvas.width / 2 + 80) && y > (canvas.height / 2 + 100) && y < (canvas.height / 2 + +100 + 80)) {
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- soundButtonOpen()
- soundSrc = 'sound/fruitMus1.mp3'
- soundClose()
- if (soundFlag) {
- soundOpen()
- }
- trainingFlag = 2
- }
- } else if (trainingFlag == 2) { //当在第二步训练时 有上一步下一步按钮
- //当是在点击声音播放声音时
- //ctx.drawImage(soundImgOpen, canvas.width -widthLeft- 90, 30, 58, 46);
- if (x > (canvas.width - widthLeft - 90) && x < (canvas.width - widthLeft - 58) && y > (30) && y < (76)) {
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- soundButtonOpen()
- soundFlag = !soundFlag
- soundChange()
- }
- // 上一步按钮
- if (x > (canvas.width / 2 - 200) && x < (canvas.width / 2 + 40) && y > (canvas.height / 2 + 220) && y < (canvas.height / 2 + 220 + 80)) {
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- soundButtonOpen()
- trainingFlag = 1
- soundClose()
- }
- // ctx.drawImage(onStep, canvas.width / 2 - 200, canvas.height / 2 + 100, 160, 80);
- // 上一步按钮
- if (x > (canvas.width / 2 + 40) && x < (canvas.width / 2 + 200) && y > (canvas.height / 2 + 220) && y < (canvas.height / 2 + 220 + 80)) {
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- soundButtonOpen()
- trainingFlag = 3
- soundClose()
- soundSrc = 'sound/fruitMus2.mp3'
- if (soundFlag) {
- soundOpen()
- }
- }
- // ctx.drawImage(underStep, canvas.width / 2 + 40, canvas.height / 2 + 100, 160, 80);
- } else if (trainingFlag == 3) {
- //当是在点击声音播放声音时
- if (x > (canvas.width - widthLeft - 90) && x < (canvas.width - widthLeft - 58) && y > (30) && y < (76)) {
- soundButtonOpen()
- soundFlag = !soundFlag
- soundChange()
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- // soundOpen()
- }
- // 上一步按钮
- if (x > (canvas.width / 2 - 200) && x < (canvas.width / 2 + 40) && y > (canvas.height / 2 + 220) && y < (canvas.height / 2 + 220 + 80)) {
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- soundButtonOpen()
- trainingFlag = 2
- soundSrc = 'sound/fruitMus1.mp3'
- soundClose()
- if (soundFlag) {
- soundOpen()
- }
- }
- // ctx.drawImage(onStep, canvas.width / 2 - 200, canvas.height / 2 + 100, 160, 80);
- // 上一步按钮
- if (x > (canvas.width / 2 + 40) && x < (canvas.width / 2 + 200) && y > (canvas.height / 2 + 220) && y < (canvas.height / 2 + 220 + 80)) {
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- //判断是否摄像头初始化完成,如果初始化完成则继续往下走,如果未初始化完成则停止且进行提示
- soundButtonOpen()
- soundBgOpen()
- if (cameraFlag) {
- soundClose()
- calibrationAccuracy()
- } else {
- $('#came').show()
- setTimeout(() => {
- $('#came').hide()
- }, 2000);
- }
- }
- } else if (trainingFlag == 4) {
- if (x > (canvas.width / 2 - 80) && x < (canvas.width / 2 + 80) && y > (canvas.height / 2 + 220) && y < (canvas.height / 2 + 220 + 80)) {
- soundButtonOpen()
- soundBgClose();
- // ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- trainingFlag = 1
- $('#target').hide()
- // init()
- }
- }
- //ctx.drawImage(startGame, canvas.width / 2 -80 , canvas.height / 2 + 100, 160, 80);
- // if (x > (canvas.width / 2 - 100) && x < (canvas.width / 2) && y > (canvas.height / 2 + 100) && y < (canvas.height / 2 + 140)) {
- // if (trainingFlag == 1) {
- // trainingFlag = 2
- // } else if (trainingFlag == 2) {
- // trainingFlag = 3
- // } else if (trainingFlag == 3) {
- // calibrationAccuracy()
- // }
- // }
- //ctx.drawImage(backMa, 20, 20, 40, 30);
- // ctx.drawImage(backMa, widthLeft+40, 30, 58, 46);
- if (x > widthLeft + 40 && x < widthLeft + 98 && y > 30 && y < 76) {
- soundButtonOpen()
- //点击退出按钮就返回到感统综合页面即可
- //window.location.href = 'http://49.232.79.112:8088/home'
- // window.location.href = 'https://gengnao.cn/home'
- // window.location.href = 'https://org.jue-ming.com/welcome/mainTable'
- window.location.href = pre_path + '/welcome/mainTable'
- }
- }
- function soundClose() {
- player.pause()
- }
- function soundOpen() {
- mp3Url = soundSrc;
- player = new Audio(mp3Url);
- player.play()
- }
- //按钮点击音效
- function soundButtonOpen() {
- playerButton.play()
- }
- //切水果音效
- function soundHitOpen() {
- playerHit.play()
- }
- //背景音乐音效
- function soundBgOpen() {
- playerBg.play()
- playerBg.loop = true;
- }
- function soundBgClose() {
- playerBg.pause()
- }
- function init() {
- middleFont()
- //第一张训练图片
- trainOne = new Image();
- trainTwo = new Image();
- trainThree = new Image();
- trainFour = new Image();
- onStep = new Image();
- underStep = new Image()
- startGame = new Image();
- backMa = new Image();
- soundImgClose = new Image();
- soundImgOpen = new Image();
- success = new Image();
- button1 = new Image;
- //苹果
- apple = new Image();
- //苹果碎片
- appleLeft = new Image();
- appleRight = new Image();
- //香蕉
- banana = new Image();
- bananaLeft = new Image();
- bananaRight = new Image();
- //西瓜
- sandia = new Image();
- sandiaLeft = new Image();
- sandiaRight = new Image();
- //草莓
- basaha = new Image();
- basahaLeft = new Image();
- basahaRight = new Image();
- bg = new Image();
- success.src = './image/success.png'
- trainOne.src = './image/fruit1.png'
- trainTwo.src = './image/fruit2.png'
- trainThree.src = './image/fruit3.png'
- trainFour.src = './image/fruit4.png'
- onStep.src = './image/onStep.png'
- underStep.src = './image/underStep.png'
- startGame.src = './image/startGame.png'
- backMa.src = './image/backMa.png'
- soundImgClose.src = './image/close.png'
- soundImgOpen.src = './image/open.png'
- button1.src = './image/button1.png'
- apple.src = "./image/apple.png";
- appleLeft.src = './image/apple-1.png';
- appleRight.src = './image/apple-2.png';
- banana.src = './image/banana.png';
- bananaLeft.src = './image/banana-1.png';
- bananaRight.src = './image/banana-2.png';
- sandia.src = './image/sandia.png'
- sandiaLeft.src = './image/sandia-2.png'
- sandiaRight.src = './image/sandia-1.png'
- basaha.src = './image/basaha.png'
- basahaLeft.src = './image/basaha-2.png'
- basahaRight.src = './image/basaha-1.png'
- bg.src = './image/background.png'
- //canvas =
- //let canvas = document.querySelector("#solar");
- apple.onload = function () {
- //设置初始时间
- //countdown()
- draw()
- }
- // bg.onload = imgFn;
- }
- //初始化虫子的变量
- //虫子1
- let wormOne;
- //虫子二
- let wormTwo;
- //虫子3
- let wormThree;
- //虫子4
- let wormFour;
- let bgtree;
- let timerWorm;
- //水果下降的速度
- let yWorm = [600, 600, 600, 600];
- let speedWorm = [1, 1.5, 1.3, 1.4];
- let xWorm = [100, 300, 500, 700]
- //设置虫子的起点
- let wormStart = 600
- //设置说过的结尾
- let wormEnd = 20;
- let tempCanvas;
- let tempCtx;
- let pattern
- //初始化抓虫子的图
- function initWorm() {
- wormOne = new Image();
- wormTwo = new Image();
- wormThree = new Image();
- wormFour = new Image();
- bgtree = new Image();
- wormOne.src = './image/bug1.png';
- wormTwo.src = './image/bug2.png';
- wormThree.src = './image/bug3.png';
- wormFour.src = './image/bug4.png';
- bgtree.src = './image/tree.png'
- wormFlag = [true, true, true, true]
- bgtree.onload = function () {
- //先把加载好的图片绘制在一个临时的画布上
- drawWorm()
- }
- }
- //画虫子
- function drawWorm() {
- ctx.clearRect(0, 0, canvas.width, canvas.height); //清空所有的内容
- // let a = ctx.createPattern(bgtree, 'repeat')
- // ctx.fillStyle = a;
- // ctx.fillRect(0, 0, canvas.width, canvas.height)
- tempCanvas = document.createElement('canvas');
- tempCanvas.width = canvas.width;
- tempCanvas.height = canvas.height;
- tempCtx = tempCanvas.getContext('2d');
- tempCtx.drawImage(bgtree, 0, 0, canvas.width, canvas.height);
- pattern = ctx.createPattern(tempCanvas, 'repeat');
- ctx.fillStyle = pattern;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.font = "40px Arial";
- ctx.strokeText("Hello World", 10, 50);
- // ctx.fillText("Hello World", 10, 50);
- //虫子1
- ctx.drawImage(wormOne, xWorm[0], yWorm[0], 60, 60);
- ctx.drawImage(wormTwo, xWorm[1], yWorm[1], 60, 60);
- //虫子三
- ctx.drawImage(wormThree, xWorm[2], yWorm[2], 60, 60);
- //虫子4
- ctx.drawImage(wormFour, xWorm[3], yWorm[3], 60, 60);
- if (wormFlag[0]) {
- yWorm[0] = yWorm[0] - speedWorm[0] * random
- } else {
- yWorm[0] = yWorm[0] + speedWorm[0] * random * 1.5
- }
- if (yWorm[0] < wormEnd || yWorm[0] > wormStart) {
- yWorm[0] = wormStart
- wormFlag[0] = true
- random = Math.random() + 1
- }
- if (wormFlag[1]) {
- yWorm[1] = yWorm[1] - speedWorm[1] * random
- } else {
- yWorm[1] = yWorm[1] + speedWorm[1] * random * 1.5
- }
- //yWorm[1] = yWorm[1] - speedWorm[1] * random
- if (yWorm[1] < wormEnd || yWorm[1] > wormStart) {
- yWorm[1] = wormStart
- wormFlag[1] = true;
- random = Math.random() + 1
- }
- if (wormFlag[2]) {
- yWorm[2] = yWorm[2] - speedWorm[2] * random
- } else {
- yWorm[2] = yWorm[2] + speedWorm[2] * random * 1.5
- }
- //yWorm[2] = yWorm[2] - speedWorm[2] * random
- if (yWorm[2] < wormEnd || yWorm[2] > wormStart) {
- yWorm[2] = wormStart
- wormFlag[2] = true;
- random = Math.random() + 1
- }
- if (wormFlag[3]) {
- yWorm[3] = yWorm[3] - speedWorm[3] * random
- } else {
- yWorm[3] = yWorm[3] + speedWorm[3] * random * 1.5
- }
- if (yWorm[3] < wormEnd || yWorm[3] > wormStart) {
- yWorm[3] = wormStart
- wormFlag[3] = true;
- random = Math.random() + 1
- }
- let first = [xWorm[0] + 30, yWorm[0] + 30]
- //第二列中心点坐标
- let second = [xWorm[1] + 30, yWorm[1] + 30]
- let third = [xWorm[2] + 30, yWorm[2] + 30]
- let four = [xWorm[3] + 30, yWorm[3] + 30]
- wormCollision(first, second, third, four)
- timerWorm = requestAnimationFrame(drawWorm);
- if (fruitFlag !== 2) {
- window.cancelAnimationFrame(timerWorm)
- ctx.clearRect(0, 0, 900, 900); //清空所有的内容
- }
- }
- function draw() {
- widthLeft = (canvas.width - (1270 / 714 * canvas.height)) / 2
- ctx.clearRect(0, 0, canvas.width, canvas.height); //清空所有的内容
- // // let a = ctx.createPattern(bg, 'repeat')
- // // ctx.fillStyle = a;
- // // ctx.fillRect(0, 0, canvas.width, canvas.height)
- // /*绘制 太阳*/
- // tempCanvasFruit = document.createElement('canvas');
- // tempCanvasFruit.width = 814;
- // tempCanvasFruit.height = canvas.height;
- // tempCtxFruit = tempCanvasFruit.getContext('2d');
- // // tempCtxFruit.drawImage(bg, 0, 0, canvas.width, canvas.height);
- // tempCtxFruit.drawImage(bg, 0, 0, canvas.width, canvas.height);
- // patternFruit = ctx.createPattern(tempCanvasFruit, 'repeat');
- // ctx.fillStyle = patternFruit;
- // //ctx.fillRect(0, 0, canvas.width, canvas.height);
- // ctx.fillRect(0, 0, 814, canvas.height);
- // 1270/714*
- if (trainingFlag == 1) {
- tempCanvasFruit = document.createElement('canvas');
- tempCanvasFruit.width = canvas.width;
- tempCanvasFruit.height = canvas.height;
- tempCtxFruit = tempCanvasFruit.getContext('2d');
- //tempCtxFruit.drawImage(trainOne, 0, 0, 814/608*canvas.height, canvas.height);
- tempCtxFruit.drawImage(trainOne, widthLeft, 0, 1270 / 714 * canvas.height, canvas.height);
- patternFruit = ctx.createPattern(tempCanvasFruit, 'repeat');
- ctx.fillStyle = patternFruit;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- //增加下一步的按钮。点击后将trainningFlag设置2
- ctx.drawImage(underStep, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- //返回按钮 //(canvas.width - (1270/714*canvas.height)) / 2
- ctx.drawImage(backMa, widthLeft + 40, 30, 58, 46);
- }
- if (trainingFlag == 2) {
- tempCanvasFruit = document.createElement('canvas');
- tempCanvasFruit.width = canvas.width;
- tempCanvasFruit.height = canvas.height;
- tempCtxFruit = tempCanvasFruit.getContext('2d');
- tempCtxFruit.drawImage(trainTwo, widthLeft, 0, 1270 / 714 * canvas.height, canvas.height);
- patternFruit = ctx.createPattern(tempCanvasFruit, 'repeat');
- ctx.fillStyle = patternFruit;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.drawImage(trainThree, (canvas.width - (canvas.width / 2 + 200)) / 2, 80, canvas.width / 2 + 200, canvas.height / 2 + 130);
- //上一步按钮
- ctx.drawImage(onStep, canvas.width / 2 - 200, canvas.height / 2 + 220, 160, 80);
- //下一步按钮
- ctx.drawImage(underStep, canvas.width / 2 + 40, canvas.height / 2 + 220, 160, 80);
- //返回按钮
- ctx.drawImage(backMa, widthLeft + 40, 30, 58, 46);
- if (soundFlag) {
- ctx.drawImage(soundImgOpen, canvas.width - widthLeft - 90, 30, 58, 46);
- } else {
- ctx.drawImage(soundImgClose, canvas.width - widthLeft - 90, 30, 58, 46);
- }
- }
- if (trainingFlag == 3) {
- tempCanvasFruit = document.createElement('canvas');
- tempCanvasFruit.width = canvas.width;
- tempCanvasFruit.height = canvas.height;
- tempCtxFruit = tempCanvasFruit.getContext('2d');
- tempCtxFruit.drawImage(trainTwo, widthLeft, 0, 1270 / 714 * canvas.height, canvas.height);
- patternFruit = ctx.createPattern(tempCanvasFruit, 'repeat');
- ctx.fillStyle = patternFruit;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.drawImage(trainFour, (canvas.width - (canvas.width / 2 + 200)) / 2, 80, canvas.width / 2 + 200, canvas.height / 2 + 130);
- //上一步按钮
- ctx.drawImage(onStep, canvas.width / 2 - 200, canvas.height / 2 + 220, 160, 80);
- //下一步按钮
- ctx.drawImage(underStep, canvas.width / 2 + 40, canvas.height / 2 + 220, 160, 80);
- //返回按钮
- ctx.drawImage(backMa, widthLeft + 40, 30, 58, 46);
- if (soundFlag) {
- // ctx.drawImage(soundImgOpen, canvas.width - 60, 20, 40, 30);
- ctx.drawImage(soundImgOpen, canvas.width - widthLeft - 90, 30, 58, 46);
- } else {
- // ctx.drawImage(soundImgClose, canvas.width - 60, 20, 40, 30);
- ctx.drawImage(soundImgClose, canvas.width - widthLeft - 90, 30, 58, 46);
- }
- }
- if (trainingFlag == 4) {
- tempCanvasFruit = document.createElement('canvas');
- tempCanvasFruit.width = canvas.width;
- tempCanvasFruit.height = canvas.height;
- tempCtxFruit = tempCanvasFruit.getContext('2d');
- tempCtxFruit.drawImage(trainTwo, 0, 0, canvas.width, canvas.height);
- patternFruit = ctx.createPattern(tempCanvasFruit, 'repeat');
- ctx.fillStyle = patternFruit;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- var gradient = ctx.createLinearGradient(0, 0, 100, 0);
- //返回按钮
- ctx.drawImage(backMa, widthLeft + 40, 30, 58, 46);
- if (countdownFlag) {
- gradient.addColorStop("1.0", "#D1BBFF");
- // Fill with gradient
- ctx.strokeStyle = gradient;
- ctx.font = "30px Arial";
- ctx.strokeText("倒计时:" + countdown(), canvas.width - 240, 100);
- gradient.addColorStop("1.0", "#D1BBFF");
- // Fill with gradient
- ctx.strokeStyle = gradient;
- ctx.font = "30px Arial";
- ctx.strokeText("第" + diff + '关', 100, 100);
- ctx.font = "30px Arial";
- ctx.strokeText("得分:" + count, canvas.width - 240, 150);
- // ctx.fillText("Hello World", 10, 50);
- //切水果倒计时三分钟
- //初始化
- }
- if (diffFlag) {
- gradient.addColorStop("1.0", "yellow");
- // Fill with gradient
- ctx.strokeStyle = gradient;
- ctx.font = "80px Arial";
- ctx.strokeText("第 " + diff + ' 关', canvas.width / 2 - 120, canvas.height / 2 - 100);
- }
- if (passFlag == 2) {
- gradient.addColorStop("1.0", "red");
- // Fill with gradient
- ctx.strokeStyle = gradient;
- ctx.font = "20px Arial";
- ctx.strokeText("很遗憾您已超时,继续加油!", canvas.width / 2 - 100, canvas.height / 2 - 100);
- //ctx.drawImage(startGame, canvas.width / 2 - 80, canvas.height / 2 + 100, 160, 80);
- ctx.drawImage(startGame, canvas.width / 2 - 80, canvas.height / 2 + 220, 160, 80);
- countdownFlag = false;
- diffFlag = false;
- //重新开始按钮 //或返回主页
- // ctx.drawImage(button1, canvas.width / 2 - 200, canvas.height / 2 + 100, 60, 30);
- }
- //
- if (passFlag == 3) {
- gradient.addColorStop("1.0", "yellow");
- // Fill with gradient
- ctx.strokeStyle = gradient;
- // ctx.font = "50px Arial";
- // ctx.strokeText("您已通关!!!", canvas.width / 2 - 120, canvas.height / 2 - 100);
- ctx.drawImage(success, canvas.width / 2 - 325, 10);
- ctx.drawImage(startGame, canvas.width / 2 - 80, canvas.height / 2 + 220, 160, 80);
- countdownFlag = false;
- diffFlag = false;
- //重新开始按钮 //或返回主页
- // ctx.drawImage(button1, canvas.width / 2 - 200, canvas.height / 2 + 100, 60, 30);
- }
- // ctx.drawImage(button1, canvas.width / 2 - 100, canvas.height / 2 + 100, 100, 40);
- // ctx.drawImage(button1, canvas.width / 2 + 100, canvas.height / 2 + 100, 100, 40);
- if (flag[0]) {
- ctx.drawImage(apple, x[0], y[0], 60, 60);
- getColl()
- } else {
- apple_x_left += 0.5
- apple_x_right -= 0.5
- ctx.drawImage(appleLeft, apple_x_right, y[0], 60, 60);
- ctx.drawImage(appleRight, apple_x_left, y[0], 60, 60);
- }
- if (flag[1]) {
- ctx.drawImage(banana, x[1], y[1], 60, 30);
- getColl()
- } else {
- banana_x_left += 0.5
- banana_x_right -= 0.5
- ctx.drawImage(bananaLeft, banana_x_left, y[1], 60, 30);
- ctx.drawImage(bananaRight, banana_x_right, y[1], 60, 30);
- }
- if (flag[2]) {
- ctx.drawImage(sandia, x[2], y[2], 60, 60);
- getColl()
- } else {
- sandia_x_left += 0.5
- sandia_x_right -= 0.5
- ctx.drawImage(sandiaLeft, sandia_x_left, y[2], 60, 60);
- ctx.drawImage(sandiaRight, sandia_x_right, y[2], 60, 60);
- }
- if (flag[3]) {
- ctx.drawImage(basaha, x[3], y[3], 60, 60);
- getColl()
- } else {
- basaha_x_left += 0.5
- basaha_x_right -= 0.5
- ctx.drawImage(basahaLeft, basaha_x_left, y[3], 60, 60);
- ctx.drawImage(basahaRight, basaha_x_right, y[3], 60, 60);
- }
- random = Math.random() + 1
- y[0] = y[0] + speed[0] * random
- if (y[0] > fruitEnd) {
- y[0] = fruitStart
- flag[0] = true
- apple_x_left = x[0]
- apple_x_right = x[0]
- }
- random = Math.random() + 1
- y[1] = y[1] + speed[1] * random
- if (y[1] > fruitEnd) {
- y[1] = fruitStart
- flag[1] = true;
- banana_x_left = x[1];
- banana_x_right = x[1]
- }
- random = Math.random() + 1
- y[2] = y[2] + speed[2] * random
- if (y[2] > fruitEnd) {
- y[2] = fruitStart;
- flag[2] = true;
- sandia_x_left = x[2];
- sandia_x_right = x[2]
- }
- random = Math.random() + 1
- y[3] = y[3] + speed[3] * random
- if (y[3] > fruitEnd) {
- y[3] = fruitStart
- flag[3] = true;
- basaha_x_left = x[3]
- basaha_x_right = x[3]
- }
- }
- timer = requestAnimationFrame(draw);
- if (fruitFlag !== 1) {
- //取消循环
- window.cancelAnimationFrame(timer)
- ctx.clearRect(0, 0, 900, 900); //清空所有的内容
- }
- //
- }
- //在合适的时机调用碰撞检测方法
- function getColl() {
- let first = [x[0] + 30, y[0] + 30]
- //第二列中心点坐标
- let second = [x[1] + 30, y[1] + 15]
- let third = [x[2] + 30, y[2] + 30]
- let four = [x[3] + 30, y[3] + 30]
- //碰撞检测方法
- collision(first, second, third, four)
- }
- //分数判断方法
- function countComputer() {
- if (diff == 1) {
- if (passFlag == 1) {
- count += 5
- }
- }
- if (diff == 2) {
- // resetTime()
- if (passFlag == 1) {
- count += 5
- }
- }
- if (diff == 3) {
- // resetTime()
- if (passFlag == 1) {
- count += 5
- }
- }
- }
- //水果的相交方法
- function collision(first, second, third, four) {
- //判断是否与第一个相交
- if (flag[0]) {
- if ((Math.abs(targ[0] - (first[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (first[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了\
- soundHitOpen()
- flag[0] = false
- countComputer()
- }
- }
- //第二条线相交
- if (flag[1]) {
- if ((Math.abs(targ[0] - (second[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (second[1])) <= (60 / 2 + 30 / 2))) {
- //两个面积相交了
- soundHitOpen()
- flag[1] = false
- countComputer()
- }
- }
- //第三条线相交
- if (flag[2]) {
- if ((Math.abs(targ[0] - (third[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (third[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了
- soundHitOpen()
- flag[2] = false
- countComputer()
- }
- }
- //第四条线相交
- //第三条线相交
- if (flag[3]) {
- if ((Math.abs(targ[0] - (four[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (four[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了
- soundHitOpen()
- flag[3] = false
- countComputer()
- }
- }
- }
- //虫子的相交方法
- function wormCollision(first, second, third, four) {
- //判断是否与第一个相交console
- if ((Math.abs(targ[0] - (first[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (first[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了
- wormFlag[0] = false
- }
- //第二条线相交
- if ((Math.abs(targ[0] - (second[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (second[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了
- wormFlag[1] = false
- }
- //第三条线相交
- if ((Math.abs(targ[0] - (third[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (third[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了
- wormFlag[2] = false
- }
- //第四条线相交
- //第三条线相交
- if ((Math.abs(targ[0] - (four[0])) <= (60 / 2 + 60 / 2)) && (Math.abs(targ[1] - (four[1])) <= (60 / 2 + 60 / 2))) {
- //两个面积相交了
- wormFlag[3] = false
- }
- }
- //倒计时方法
- function countdown() {
- startTimeFruit = new Date().getTime();
- let surplusTime = endTimeFruit - startTimeFruit;
- let th = Math.floor(surplusTime / (1000 * 60 * 60) % 24);
- let tm = Math.floor(surplusTime / (1000 * 60) % 60);
- let ts = Math.floor(surplusTime / 1000 % 60);
- if (ts < 10) {
- ts = '0' + ts
- }
- if (surplusTime >= 0) {
- if (!(passFlag == 2 || passFlag == 3)) {
- countdownFlag = true
- }
- return '0' + th + ':' + '0' + tm + ':' + ts
- } else {
- //当计时为小于0时
- //如果是第一关
- //判断当前的分数是否超过90分
- //当分数是第一关且分数超过90分执行保存命令且进入第二关
- //然后重新计时
- if (diff == 1) {
- if (count >= 90) {
- //执行保存结果
- levelFun(diff, count)
- totalScore += count
- middleFont()
- speed = [1.5, 2.0, 2.3, 2.4];
- //且进行将关卡设置为2
- diff = 2;
- count = 0
- //将时间重置为3分钟
- resetTime()
- } else {
- if (passFlag != 2) {
- levelFun(diff, count)
- }
- passFlag = 2
- //很遗憾失败了
- }
- } else if (diff == 2) {
- if (count >= 60) {
- middleFont()
- levelFun(diff, count)
- totalScore += count
- speed = [2.0, 2.5, 2.8, 3.1];
- diff = 3;
- count = 0
- //将时间重置为3分钟
- resetTime()
- } else {
- if (passFlag != 2) {
- levelFun(diff, count)
- }
- passFlag = 2
- }
- } else if (diff == 3) {
- if (count >= 45) {
- if (passFlag != 3) {
- totalScore += count
- levelFun(diff, count)
- saveResult(totalScore)
- }
- passFlag = 3
- } else {
- if (passFlag != 2) {
- levelFun(diff, count)
- }
- passFlag = 2
- }
- }
- return '00' + ':' + '00' + ':' + '00'
- // levelFun(diff, count)
- // saveResult(count)
- // countdownFlag = false
- }
- }
- //捉虫子游戏变量
- $('#solar').hide();
- $('#exit').hide();
- $('#refresh').hide();
- let WASM_URL = "js/gazefilter.wasm";
- var buttonList = []
- $('#target').hide();
- $('#target1').hide();
- var record = {
- beforePoint: -1,
- currentPoint: 0,
- }
- //校准方法
- function calibrationAccuracy() {
- $('#solar').hide();
- handleFullScreen();
- getFun()
- $('#target1').show();
- $('#startCalibration').hide();
- switchTime()
- //初始化游戏
- $('#target1').hide()
- // $('#target').show()
- //clearInterval(time)
- //$('#solar').show();
- //$('#exit').show();
- // $('#refresh').show();
- }
- $("#startCalibration").click(function () {
- // handleFullScreen(); //全屏
- handleFullScreen();
- getFun()
- $('#target1').show();
- $('#startCalibration').hide();
- //switchTime()
- //初始化游戏
- //
- $('#target1').hide()
- $('#target').show()
- clearInterval(time)
- $('#solar').show();
- //$('#exit').show();
- // $('#refresh').show();
- init();
- // $('.enterClass').css('display','none');
- // $('.returnClass').css('display','block');
- });
- //切换游戏
- $('#exit').click(function () {
- //隐藏画布一
- // $('#exit').innerHtml()
- if (fruitFlag == 1) {
- setTimeout(() => {
- initWorm()
- fruitFlag = 2
- }, 30);
- } else {
- setTimeout(() => {
- init()
- fruitFlag = 1
- }, 30);
- }
- })
- $('#refresh').click(function () {
- location.reload()
- })
- function handleFullScreen() {
- var de = document.documentElement;
- if (de.requestFullscreen) {
- de.requestFullscreen();
- } else if (de.msRequestFullscreen) {
- de.msRequestFullscreen();
- } else if (de.webkitRequestFullScreen) {
- de.webkitRequestFullScreen();
- } else if (de.mozRequestFullScreen) {
- de.mozRequestFullScreen();
- } else {
- wtx.info("当前浏览器不支持全屏!");
- }
- }
- //重置通过状态
- function resetStatus() {
- //重置是否通过的状态
- passFlag = 1;
- //重置速度
- speed = [1, 1.5, 1.3, 1.4];
- }
- //重置计时函数
- function resetTime() {
- startTimeFruit = new Date().getTime();
- endTimeFruit = startTimeFruit + 180000;
- countdownFlag = true
- }
- //重置难度重置关数
- function resetCount(val, value) {
- //设置难度为多少
- diff = val;
- //设置分数为多少
- count = value;
- }
- //轮询当前的图表
- var time = null;
- function switchTime() {
- let a = 0
- time = setInterval(() => {
- $('#target1').show()
- $('#targetMini').show()
- if (a == 16) {
- $('#target1').hide()
- $('#target').show()
- clearInterval(time)
- $('#solar').show();
- // $('#exit').show();
- // $('#refresh').show();
- trainingFlag = 4
- //重置计时函数
- resetTime()
- //重置分数和参数
- resetCount(1, 0)
- //都重置到初始状态
- resetStatus();
- } else {
- $('#targetMini1').css('transition', '0s');
- $('#targetMini1').css('width', 54 + 'px');
- $('#targetMini1').css('height', 54 + 'px');
- let x = buttonList[a].x1;
- x = Math.floor(x)
- let y = buttonList[a].y1;
- y = Math.floor(y)
- $('#target1').css('left', x + 'px');
- $('#target1').css('top', y + 'px');
- // init();
- setTimeout(() => {
- $('#targetMini1').css('transition', '1s');
- $('#targetMini1').css('width', 20 + 'px');
- $('#targetMini1').css('height', 20 + 'px');
- }, 1000);
- setTimeout(() => {
- coordinates(x + 30, y + 30)
- }, 1500);
- setTimeout(() => {
- coordinates(x + 30, y + 30)
- }, 1840);
- setTimeout(() => {
- coordinates(x + 30, y + 30)
- }, 1940);
- a = a + 1
- }
- }, 2000)
- }
- function coordinates(x, y) {
- gazefilter.tracker.calibrate( //校正,发送当前点击位置进行校正
- //event.timeStamp,
- window.performance.now(),
- //window.performance.now(),
- //mill,
- //1000, // relative to performance.timeOrigin
- x, // in pixels
- y, // in pixels
- 1.0 // see note below
- );
- }
- //获取各个按钮的left和top
- /**
- * 在屏幕上画出注视点
- * 是否画点,以及画点方式均可自定义
- **/
- function drawTargetOnScreen(position) {
- if (position != null && position.length == 2) {
- //判断是否是NAN如果是NAN则不执行
- //如果不是则需要判断当前点是否在第一个点中,如果在则执行settimeout函数1秒后改变改块状态
- //如果在第一个点中但第二次坐标出来的时候还在第一个坐标里那就没问题
- // $('#target').css('display', 'block');
- targ[0] = position[0] + 60;
- targ[1] = position[1] + 60;
- $('#target').css('left', position[0] + 'px');
- $('#target').css('top', position[1] + 'px');
- // $('#target').css('z-index', 100);
- //judge(position[0], position[1])
- // judge(position[0], position[1])
- }
- }
- //判断是否在第一个点中
- //获取全部的校验点
- function getFun() {
- for (let i = 0; i < 16; i++) {
- let a = document.getElementById('num' + (i + 1));
- buttonList.push({
- x1: a.getBoundingClientRect().left,
- y1: a.getBoundingClientRect().top
- })
- }
- }
- async function initGazefilter() {
- cameraFlag = false
- await gazefilter.init(WASM_URL); //初始化
- console.log(1)
- await gazefilter.tracker.connect(); //连接摄像头
- let canvas = document.getElementById("tracker-canvas");
- console.log(12)
- await gazefilter.visualizer.setCanvas(canvas); //绘制图像
- console.log(123)
- cameraFlag = true
- await gazefilter.tracker.addListener("calib", response => {
- //console.log(response.errorCode, event.errorValue); //校验结果 errorCode 0: calibration is successfull;1: screen dimentions should be set;2: calibration sample cannot be created;3: not enough data to fit calibration model.
- });
- }
- function startTrace() {
- gazefilter.tracker.addListener("filter", event => { //注视点
- drawTargetOnScreen(event.bestGazePoint()); //Best gaze point of left or right eye. 其他取点可参考https://beehiveor.gitlab.io/gazefilter/data.html,有不同类型的点 fixationPoint
- });
- }
- function hideSence() {
- //隐藏目标物
- $('#target').hide()
- $('#target1').hide()
- $('#targetMini').hide()
- //隐藏摄像头
- $('#solar').show()
- }
- $("#finishcalibration").click(function () {
- window.removeEventListener("click", onmouseclick); //九点校正完成,取消鼠标事件,并开始绘制轨迹点
- $("#finishcalibration").hide();
- })
- $(document).ready(function () {
- //将canvas自适应屏幕
- resizeCanvas()
- init()
- hideSence()
- //将该隐藏的隐藏然后初始化游戏场景
- //初始华摄像头
- initGazefilter();
- startTrace();
- });
- </script>
- </body>
- </html>
|