如何建立游戏室 [英] How to create game rooms

查看:90
本文介绍了如何建立游戏室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建只有一个玩家可以进入的游戏室?
我知道,我可以设置存储玩家是否在其中的应用程序.
但是问题出在他用[x]关闭浏览器时,然后我需要更改应用程序值.
我想将计时器设置为2分钟,如果用户这次没有刷新页面,那么我知道应用程序应该更改值.关闭浏览器后,有没有办法让计时器保持运行?
我也尝试过使用数据库Table,当发生JavaScript时,它会转到更改表值的web方法.

有些事情可能会有所帮助,
如何创建仅在关闭浏览器后才会发生的JavaScript函数?
如何以其他方式创建房间.

这是我拥有的JavaScript

How to create game rooms that only one player can be in?
I know, I Can set Applications which stores if a player is in it or not.
But the problem comes when he closes the browser with [x], then I need to change the application value.
I thought to set a timer for 2 minutes and if the user does not refresh the page in this time then I know the Application should change value. there is a way to keep the timer running after he closed the browser?
I tried also with database Table and when a javascript happens it goes to a webmethod which changes the table values.

Some things that might help,
How to create a JavaScript function which happend ONLY when the browser is closed?
How to create the rooms in other way.

Here is the javascript I have

function DetectBrowserExit()
{
    alert('Execute task which do you want before exit');
    PageMethods.AppOff();


}

    window.onbeforeunload = function () { DetectBrowserExit(); }



AppOff更改表值,
但是即使用户刷新了页面,脚本也会运行.

有任何想法吗?
谢谢.



AppOff changes the table values,
but the script runs even if a user refreshed the page.

Any Ideas?
Thank you.

推荐答案

在这里,我认为它仅在关闭时发生:

Here it is I think it happens on close only:

<head>
<script type="text/javascript">

    var myclose = false;

    function ConfirmClose() {
        if (event.clientY < 0) {

            event.returnValue = 'Any message you want';



            setTimeout('myclose=false', 100);

            myclose = true;

        }

    }



    function HandleOnClose() {

        if (myclose == true) PageMethods.AppOff();

    }

</script>
</head>





<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">


这篇关于如何建立游戏室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆