asp如何在聊天室实现趣味答题并计分功能?

时间:2010-06-18 20:00:00 

如何在聊天室实现趣味答题并计分功能?

这个创意确实很好,我们可用在聊天室框架中加入一隐含帧(5分钟刷新一次)的做法来实现这一功能。

question.asp

' 隐含帧内的页面
<%@ language=vbscript%>
<%response.expires=0%>
<%
dim conn,rs
application.lock
application("canswername")=application("answername")
' 保存答对题聊友的昵称
application("answername")=""
application("tanswername")=""                        
' 清除答错题聊友昵称
set conn=server.createobject("adodb.connection")
accessdb="db1.mdb"                                  
' 连接题库
mydsn="driver={microsoft access driver (*.mdb)};"
mydsn=mydsn & "dbq=" &server.mappath(accessdb)
conn.open  mydsn 
set rs = server.createobject("adodb.recordset")
rs.cursorlocation=3
rs.open "select * from question ",conn
randomize                                    
' 随机取得一道题的id
r=rs.recordcount
id=int((r-1)*rnd)+1
rs.close 
set rs=nothing
set rs = server.createobject("adodb.recordset") 
rs.open "select * from question where questionid="&id,conn
application("questionname")=rs("questionname")  
' 问题
application("questionid")=rs("questionid")      
' 题的id 
application("questioncent")=rs("questioncent")  
' 题的分数
application("questionclass")=rs("questionnotes")
' 题的说明
rs.close
set rs = nothing
set ra = server.createobject("adodb.recordset")
ra.open "select * from answer where questionid="&id,conn
application("answera")=ra("answera")            
' 题的选项            
application("answerb")=ra("answerb")
application("answerc")=ra("answerc")
application("answerd")=ra("answerd")
application("answertrue")=ra("answertrue")      
' 题的正确答案
ra.close
set ra=nothing
conn.close
set conn=nothing
application("questiontime")=now()
application.unlock
%>
<html>
<head>
<meta http-equiv='content-type' content='text/html; 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("asp之家聊天室系统消息:<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>

answer.asp

' 答案处理部分.位于处理发送对话信息的程序中
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")&"噢,您已经答过这道题了!"
          else
          tfstr=session("user_username")&"恭喜,回答正确!"
          session("user_exp") =session("user_exp")+application("questioncent")  
' 给答题正确的聊友加分
          application("answername")=application("answername")&session("user_username")&" "  
' 保存答题正确的聊友的昵称
          end if
        else
          if instr(1,application("tanswername"),session("user_username"))>0 then
' 判断聊友是否已答过题
          tfstr=session("user_username")&"噢,您已经答过这道题!"
          else
          application("tanswername")=application("tanswername")&session("user_username")&" " 
' 保存答错题聊友的昵称
          end if
        end if
        end if

标签:聊天室,计分,asp
0
投稿

猜你喜欢

  • Python 使用csv库处理CSV文件的方法

    2023-03-16 21:37:24
  • Python通过30秒就能学会的漂亮短程序代码(过程全解)

    2022-08-22 13:54:50
  • Python 实现取矩阵的部分列,保存为一个新的矩阵方法

    2023-07-17 23:22:30
  • 交互设计实用指南系列(9)—一次点击

    2010-02-08 12:42:00
  • Python几种绘制时间线图的方法

    2021-08-16 10:43:05
  • python 计算两个列表的相关系数的实现

    2021-10-07 10:43:57
  • Python3.6中Twisted模块安装的问题与解决

    2022-05-29 15:45:02
  • 使用Golang的Context管理上下文的方法

    2023-06-29 06:37:23
  • Python变量基础知识

    2021-10-11 02:13:12
  • 利用Python编写的实用运维脚本分享

    2022-07-15 21:32:46
  • 浅析vue-router原理

    2023-07-02 17:09:19
  • Python使用Dijkstra算法实现求解图中最短路径距离问题详解

    2022-07-31 02:40:33
  • Python爬虫实战之虎牙视频爬取附源码

    2021-04-02 01:23:27
  • MySQL8设置自动创建时间和自动更新时间的实现方法

    2024-01-17 08:02:44
  • PyTorch中view()与 reshape()的区别详析

    2023-11-16 05:45:23
  • PHP ob缓存以及ob函数原理实例解析

    2023-11-18 17:36:14
  • SQL Server 2005:数据类型最大值

    2009-06-04 09:55:00
  • 做新产品?悠着点

    2009-03-01 13:10:00
  • Form Post提交容量大的数据

    2011-03-31 10:53:00
  • Python简单网络编程示例【客户端与服务端】

    2023-12-07 10:26:55
  • asp之家 网络编程 m.aspxhome.com