⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qi.gml

📁 在线游戏最新服务器端源代码
💻 GML
字号:
#ifndef commsocket
<sys import=desktop,$.\..\..\common\socketc.gml>
#endif
<style>
.CBTplyS:text{
	ifchged(Bchair)={
		CTR.mychair=$[Bchair]
		CTR.player["$[Bchair]"]="$[ownername]";
	}

	OnAskstart={
		if(oldGZ) $GX.Cmd("<:$[id] eve=setGZ,"+oldGZ+";>");
		clearAllBiaoX();
		TIMEALL.value=" ";
		$GX.Cmd("<:$[id] mdata='';>");
		CTR.curchair='?';
		CTR.init();
		GUIredraw();
	}

	Onend={
		CTR.curchair='?';
		GUIredraw();

		alert("$[ep0]");

		CTR.end();
	}

	OnGo={
		CTR.curchair=""+$[eventparam0]
			stepStartTime=(new Date).getTime();
			stepTimer=setTimeout("stepTimeIO()",100);
		var gomsg="$[eventparam2]";
		CTR.addgo(CTR.curchair,gomsg);
		GUIredraw();
	}
	
	onCreate#mdata={
		var d="$[mdata]",dd="$[delData]";
//		alert(dd);
		CTR.mychair=$[Bchair]
		CTR.player["$[Bchair]"]="$[ownername]";
		CTR.E_process_strg=d;
		dd=dd.split(",");
//		alert(dd)
		delmeArray=new Array();
		for(var i=0;i<dd.length;i++){
			if(dd[i]) delmeArray[delmeArray.length]=dd[i];
		}
//		alert(delmeArray)
		init_qipu_List(d);
		CTR.showall(true);

		if($[Bchair]>0) GUIredraw();
	}

	OnCreate#SYS={
		document.MYNETNAME='$[name]';
		document.MYID='$[id]';
	};

}
.CBTplyO:text{
	onCreate#mdata={
		CTR.player["$[Bchair]"]="$[ownername]";
		if($[Bchair]>0) GUIredraw();
	}
}

</style>

<style>
.MCLIENTSOCKET:commsocket{
	debug=1;
	Onconnected#1={
		showconnect(-1)
		var def=(""+document.location).split('#')
		if(def.length<2) {def[1]="H"+((new Date()).getTime())%10000;def[2]=0;def[3]=1;}
		document.MYNAME=def[1]
		document.MYGROUPNAME=def[2]
		document.MYCHAIR0=def[3]
		$GX.Cmd("<:$[id] login="+document.MYNAME+","+document.MYGROUPNAME+","+document.MYCHAIR0+";ParamCtrl#cn=null;ParamCtrl#cnErr=null><:mysocket event=hideinfo>");
	};
}
</style>


<script>
if (top.WDT) top.WDT.WXregisterwnd(self)
document.TMS=0;
var OLGMOVTM=0
function onmousemove(e)
{
	if ( (((new Date()).getTime())-OLGMOVTM)<20) return true;
	OLGMOVTM=((new Date()).getTime())
	if (!CTR) return true;
	e=window.event
	var x=e.x,y=e.y;
	CTR.mousetrace(x,y)
	gametrace(x,y);
}

function onmousedown(e)
{
	window.event.returnValue=false;	
	return false;
}

function onmouseup(e){
	if(!tryDM){
		if (CTR.MYWILLGO){
			CTR.mygo(CTR.mychair,CTR.MYWILLGO)
			CTR.MYWILLGO=null
			//CTR.curchair=null
		}
		CURSOR.style.left=-1000;
		window.event.returnValue=false;
		return false;
	}else{
		var obj=window.event.srcElement;
		if(obj.isQI==1 && obj.qi){
//			alert(obj.myID)
			$GX.Cmd("<:"+document.MYNETNAME+" neteventtos=tryDM,"+obj.myID+">")
		}
	}
}


	function send(msg)
	{
		$GX.Cmd("<:mysocket send="+msg+">")
	}
	
	function onChat(type,chatfrom,chatmsgex)
	{
		chatmsgex=unescape(chatmsgex)
		switch(type)
		{
			case 1:CHATMSG.innerHTML+="<br>我说:"+chatmsgex;break;
			case 2:CHATMSG.innerHTML+="<br>"+chatfrom+"说:"+chatmsgex;break;
		}
		CHATMSG.scrollTop+=10000;
	}
	
	function myEscape(strg)
	{
		if (strg==null) return "";
		var jzStrg="`~!@#$%^&*()_-+=|\\{[}]:;\"',<.>/?\n\r";
		var result='',c;
		for (var i=0;i<strg.length;i++)
		{
			c=strg.charAt(i);
			if (jzStrg.indexOf(c)>=0) c=escape(c);
			result+=c;
		}
		return result;
	}
	
	function chat(o)
	{
		var str=o.value;
		str=myEscape(str)
		$GX.Cmd("<:mysocket sendchat='"+str.substring(0,str.length-1)+"'>")
		o.value="";
	}

	var tmid=null
	function showconnect(i)
	{
		/*if(tmid) clearTimeout(tmid)
		if(i<0) return;
		CURDODIV.innerHTML="请稍候,服务器连接中..."+i++
		tmid=setTimeout("showconnect("+i+")",100)*/
	}

	function chgbutton(obj,type){
		if (obj.nosrc==null) obj.nosrc=obj.src
		obj.src=(type)?obj.srchot:obj.nosrc;
		obj.isShow=(type)?1:0;
	}
	function GUIredraw(){
		var type=true
		if ( ""+CTR.mychair!=""+CTR.curchair) type=false
//		chgbutton(UNDO,type)
//		chgbutton(GMHE,type)
//		chgbutton(GMOVER,type)
		
		if (CTR.curchair=='?' && CTR.mychair>0){
			chgbutton(START,1);
			chgbutton(PLAYSETUP,1);
			
			chgbutton(TRYEND,0);
			chgbutton(AGNGO,0);
			chgbutton(DMEND,0);
		}
		else{
			chgbutton(START)
			chgbutton(PLAYSETUP);
			if(!tryDM){
				if(CTR.curchair>0 && CTR.mychair>0) chgbutton(TRYEND,1);
				else chgbutton(TRYEND,0);
				chgbutton(AGNGO,0);
				chgbutton(DMEND,0);
			}
			else{
				chgbutton(TRYEND,0);
				if(CTR.mychair>0){
					chgbutton(AGNGO,1);
					chgbutton(DMEND,1);
				}else{
					chgbutton(AGNGO,0);
					chgbutton(DMEND,0);
				}
			}
		}

		var c=1,o,p;
		for(var i=0;i<2;i++,c++)
		{
			o=GAMEER[i],p=CTR.player[""+c]
			if(!o) continue;
			if(p) o.innerHTML=p
			else o.innerHTML="等待加入"
		}
	}

function qi_end(){
	this.init()
}

function qi_start(){
	this.init()
}

function qi_init(){
	CURSOR.style.left=-1000;
	this.qibuf=new Array();//棋盘矩阵,保存走棋的信息
	this.E_process_strg='';
	this.showall(true)
}

function nodowmouse()
{
	window.event.returnValue=false;	
	return false;
}

function gametrace(x,y)
{
	if (CTR.MYWILLGO)
	{
		CURSOR.style.left=x-11;
		CURSOR.style.top =y-11;
	}
}

function document.onselectstart()
{
	window.event.returnValue=false;
	return false;
}

function debug(str){
	debugdiv.innerHTML=""+str
}
var lastStepTimer;
function falshLastStep(){
	if(lastStepTimer) {clearTimeout(lastStepTimer);lastStepTimer=null;}
	var o=CTR.objects[CTR.endgoid],t;
	if(o){
			o.border=1;
			o.width=CTR.qiszw-2
			o.height=CTR.qiszh-2
	}
	//lastStepTimer=setTimeout("falshLastStep()",200);
}
function init_qipu_List(data){
	while(QIPULIST.length)
		QIPULIST.remove(0);
	var oOption = document.createElement("OPTION");
	oOption.text="初始棋局";
	oOption.selected=true;
	document.all.QIPULIST.add(oOption);
	for(var i=0;i<data.length;i+=5){
		oOption = document.createElement("OPTION");
		oOption.text="step"+i;
		document.all.QIPULIST.add(oOption);
	}
	setTimeout("seeQipu()",10);
}
function qi_addgo(chair,def)//走一步棋
{
	if (def==0) return
	def=""+def;
	if (def.length!=3) return;

	this.E_process_strg+=def+"zz";
	var e=qi_chang(def)
	var o=this.objects[this.endgoid];
	if(o){
		o.border=0;
		o.width=this.qiszw
		o.height=this.qiszh
	}
	this.endgoid=e[1]+e[2]*this.QISX
	lastStepTimer=setTimeout("falshLastStep()",200);
//	this.addQZ(e);
//	this.showall(true)
	var oOption = document.createElement("OPTION");
	oOption.text=this.qiNdef[e[0]]+this.Nbuf.charAt(e[1])+this.Nbuf.charAt(e[2]);
	oOption.selected=true;
	document.all.QIPULIST.add(oOption);
	seeQipu(document.all.QIPULIST.selectedIndex);
}
function qi_addQZ(o){
	this.qibuf[o[1]+o[2]*this.QISX]=o;
}

function qi_mygo(mchair,mgo){
	if ((""+mgo).length!=3) return 
	$GX.Cmd("<:"+document.MYNETNAME+" neteventtos=zQI,"+mgo+">")
	if(stepTimer) {clearTimeout(stepTimer);stepTimer=null;}
	allStepTimeStart=0;
	//this.addgo(mchair,mgo)
}

//游戏数据
function qi_chang(de)//棋谱转换
{
	var e=new Array()
	e[0]=parseInt(de.charAt(0))
	e[1]=CHARDEF.indexOf(de.charAt(1))
	e[2]=CHARDEF.indexOf(de.charAt(2))
	return e
}

function qi_changqipu(def,len)//转换棋谱为数组
{
	if(!len) len=def.length;
	var def2=new Array();
	if (def==null || def=='') return def2
	def=''+def;
	for (var i=0;i<len;i+=5){
		def2[i/5]=qi_chang(def.substring(i,i+3));
	}
	return def2
}
function delmeQIZI(delme,def3){
	delme+="";
	if(!delme) return def3;
	var xi,yi;
	for(var i=0;i<delme.length;i+=2){
		xi=parseInt(delme.charAt(i),36);
		yi=parseInt(delme.charAt(i+1),36);
		def3[xi+yi*CTR.QISX]=null;
	}
	return def3;
}

function qi_tozhuzheng(goarray,w,len,CTRL)//显示所有对象
{
	len*=5;
	if(!len) len=goarray.length;
	var o,e=new Array(),t

for(var i=0;i<len;i+=5){
	o=qi_chang(goarray.substring(i,i+3));
//	alert(goarray.substring(i,i+3)+"       "+o)
	e[o[1]+o[2]*w]=o;
	t=goarray.substring(i+3,i+5);
	if(t!="zz"){
		e=delmeQIZI(delmeArray[parseInt(t,36)],e);
	}
}

if(CTRL && o){
	var obj=CTRL.objects[CTRL.endgoid];
	if(obj){
		obj.border=0;
		obj.width=CTRL.qiszw
		obj.height=CTRL.qiszh
	}
	CTRL.endgoid=o[1]+o[2]*CTRL.QISX
	falshLastStep();
}
//alert(e.length)
return e;
}

function press(obj){
	if(!obj.isShow) return;
	var strg=""
	switch(obj.id){
		case 'EXITGAME':if (!askexit()) return;return;
		case 'PLAYSETUP':
			var ret=window.showModalDialog ("sel.htm",null,"dialogWidth:360px;dialogHeight:200px;")
			if(ret.charAt(0)=='3') return;
			strg+="<:"+document.MYNETNAME+" neteventtos=cuoS,"+ret+">";break;
		case 'GMHE':strg+="<:"+document.MYNETNAME+" neteventtos=neteventtos=astart,"+CTR.mychair+">";break;
		case 'GMOVER':if (!confirm("您是否真的放弃?")) return;
			 strg+="<:"+document.MYNETNAME+" neteventtos=astart,"+CTR.mychair+">";break;
		case 'START':CTR.curchair=0;strg+="<:"+document.MYNETNAME+" neteventtos=astart,"+CTR.mychair+">";break;
		case 'TRYEND':strg+="<:"+document.MYNETNAME+" neteventtos=dianM>";break;
		case 'DMEND':strg+="<:"+document.MYNETNAME+" neteventtos=dMEnd>";break;
		case 'AGNGO':strg+="<:"+document.MYNETNAME+" neteventtos=aGNGO>";break;
	}
	$GX.Cmd(strg)
	GUIredraw();
}

function askexit(notjz)
{
		if ( CTR.curchair!='?' && CTR.mychair>0)
 			 msg="中途退出将加倍惩罚,您是否确定?";
 		else msg="您是否确定退出游戏";
 		if (!confirm(msg)) return false
	 	return true
}

function getStrTime(p1){
	return myStr(parseInt(p1/60000))+":"+myStr(parseInt((p1%60000)/1000))
}
function writeCurTime(){
	var s1,s2;
	if(CTR.curchair==1){
		s1=stepAllMoreTime-(playerStepMoreTime[1]+stepMoreTime);
		s2=stepAllMoreTime-playerStepMoreTime[2];
	}else{
		s1=stepAllMoreTime-playerStepMoreTime[1];
		s2=stepAllMoreTime-(playerStepMoreTime[2]+stepMoreTime);
	}
	TIMETEST.value=getStrTime(s1);
	TIMETEST2.value=getStrTime(s2);
	TIMESTEP.value=getStrTime(playerStepCurTime[1]);
	TIMESTEP2.value=getStrTime(playerStepCurTime[2]);
//	alert(str1+"        "+str2)
}
function clearAllBiaoX(){
		if(tryEndTimer) {clearTimeout(tryEndTimer);tryEndTimer=null;}
DIVFEN1.value=" ";
DIVFEN2.value=" ";
TIMEALL.value=" ";
TIMESTEP.value=" ";
TIMETEST.value=" ";
while(QIPULIST.length)
	QIPULIST.remove(0);

	var oOption = document.createElement("OPTION");
	oOption.text="初始棋局";
	oOption.selected=true;
	document.all.QIPULIST.add(oOption);
}
function toEndGame(){
	if(stepTimer) {clearTimeout(stepTimer);stepTimer=null;}
	if(tryEndTimer) {clearTimeout(tryEndTimer);tryEndTimer=null;}
	$GX.Cmd("<:"+document.MYNETNAME+" neteventtos=endNow;>");
}
function myStr(p){
	if(p<10) return "0"+p;
	return ""+p;
}
var playerStepCurTime=new Array(0,0,0),stepMaxTime=0,stepStartTime=0,stepMoreTime=0,stepAllMoreTime=0;
var playerStepMoreTime=new Array(0,0,0);
function stepTimeIO(){
	if(stepTimer) {clearTimeout(stepTimer);stepTimer=null;}
	if(timeType!=1) return;
	if(!tryDM){
		var t=(new Date ()).getTime ();
		playerStepCurTime[CTR.curchair]+=t-stepStartTime;
	//		TIMESTEP.innerHTML=myStr(parseInt(playerStepCurTime[CTR.curchair]/60000))+":"+myStr(parseInt((playerStepCurTime[CTR.curchair]%60000)/1000));//单步计时
		stepStartTime=t;
		if(playerStepCurTime[CTR.curchair]>stepMaxTime){
			stepMoreTime=playerStepCurTime[CTR.curchair]-stepMaxTime;
							//playerStepCurTime[CTR.curchair]-stepMaxTime;
			t=playerStepMoreTime[CTR.curchair]+stepMoreTime;
		if(t>stepAllMoreTime){
			return;
		}
		}
		writeCurTime();
	}
	stepTimer=setTimeout("stepTimeIO()",400);
}
function tryEndGame(){
	if(tryEndTimer) {clearTimeout(tryEndTimer);tryEndTimer=null;}
	if(!tryDM){
		if(skipTime!=0){
			skipTime=(new Date()).getTime()-skipTime;
			newJUStartTime+=skipTime;
			skipTime=0;
		}
		var t=(new Date()).getTime()-newJUStartTime;
		if(timeType==2 && t>stepTime){
			return;
		}
		t=myStr(parseInt(t/60000))+":"+myStr(parseInt((t%60000)/1000));
		TIMEALL.value=t;
	}else{
		if(skipTime==0) skipTime=(new Date()).getTime();
	}
	tryEndTimer=setTimeout("tryEndGame()",400);
}
var stepStartTime=0,newJUStartTime=0,allStepTime=0,allStepTimeStart=null;
var stepTime=0,timeType=0,stepTimer,tryEndTimer;
var skipTime=0,skipTimeStep=0,oldGZ=null;
document.SYSJSLOADOK=true
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -