新农首页 农业新闻 致富信息 农业技术 农业搜索 农药 电脑 网站地图

用ASP实现聊天室中的在线答题游戏

发布时间:2012-03-25  来源:BK网络学院
摘要:用ASP实现聊天室中的在线答题游戏

  
  主要功能为:在聊天室中,每隔5分钟,向显示对话页面,发送一道题,所有用户都可答题。答对者加相应的分值。 具体实现:在聊天室框架中加入一隐含帧,此帧每5分钟刷新一次。隐含帧内的ASP页内容如下:


  <%@ LANGUAGE=VBScript%><%Response.Expires=0%><%Dim Conn,RsApplication.Lockapplication("CanswerName")=application("answerName") '保存答对题用户的名字application("answerName")=""application("TanswerName")="" '清除答错题用户的名子set Conn=server.createobject("ADODB.Connection")Accessdb="db1.mdb" '题库的连接 myDSN="DRIVER={Microsoft Access Driver (*.mdb)};"myDSN=myDSN  charset=gb2312'><Link Rel='stylesheet' Href='../Style.CSS' Type='text/css'><meta http-equiv="refresh" content="300;url=question.asp"> <title><%=Application("V")%></title><script Language="JavaScript">parent.ShowSays.document.write("******系统消息:******<br>"); //向聊天室显示对话窗口写入问题parent.ShowSays.document.write("**上题答对者为:<%=application"CanswerName")%><br>");parent.ShowSays.document.write("问题::<%=application("questionName")%>");parent.ShowSays.document.write(" <%=application("questionCent")%>分(1分钟之内,回答输入‘#答案’)<%=Time()%><br>");parent.ShowSays.document.write("A::<%=application("answerA")%><br>");parent.ShowSays.document.write("B::<%=application("answerB")%><br>");parent.ShowSays.document.write("C::<%=application("answerC")%><br>");parent.ShowSays.document.write("D::<%=application("answerD")%><br>");</script></head><body bgcolor='#FFFFFF'></Body></html>处理答题部分略!!! 答案处理部分,放在处理发送对话信息的程序中即可。下面是答案处理的代码部分: if mid(FStr,i,1)="#" then 'FStr是保存对话信息的字符串变量TFstr=mid(FStr,i+1,1)if CInt(DateDiff("n",application("questionTime"),Now()))<=1 then '判断时间1分钟内答题有效if LCase(TFstr)=LCase(application("answerTrue")) then '判断答题是否正确if instr(1,application("answerName"),session("USER_USERNAME"))>0 then '判断用户是否已经答过题了TFstr=session("USER_USERNAME")&"已经答过这道了!!!"elseTFstr=session("USER_USERNAME")&"答题正确!"Session("USER_EXP") =Session("USER_EXP")+application("questionCent") '给答对题的用户加分application("answerName")=application("answerName")&session("USER_USERNAME")&" " '保存答对题用户的名字end ifelseif instr(1,application("TanswerName"),session("USER_USERNAME"))>0 then ''判断用户是否已经答过题了 TFstr=session("USER_USERNAME")&"已经答过这道了!!!"elseapplication("TanswerName")=application("TanswerName")&session("USER_USERNAME")&" " '保存答错题用户的名字end ifend ifend if

打印 责任编辑:admin