jsp+session拼图游戏原理分析

标题:jsp+session拼图游戏原理分析
摘要: 通过排字游戏学习理解session对象
难度:


通过排字游戏学习理解session对象



index..jsp


<%
int[][]ges=newint[3][3];
intshu=0;
for(inth=0;h<3;h++)
{
for(intl=0;l<3;l++)
{
ges[h][l]=shu;
shu++;
}
}

for(intci=0;ci<10;ci++)
{
inth1=(int)(3*Math.random());
intl1=(int)(3*Math.random());

inth2=(int)(3*Math.random());
intl2=(int)(3*Math.random());

intlinshi=ges[h1][l1];
ges[h1][l1]=ges[h2][l2];
ges[h2][l2]=linshi;
}

session.setAttribute("ges",ges);
response.sendRedirect("see.jsp");
%>


see.jsp

<%
intges[][]=newint[3][3];
ges=(int[][])session.getAttribute("ges");
%>
<tablewidth="300"align="center"border="1"height="300">
<%
for(inth=0;h<3;h++)
{
%>
<tr>
<%
for(intl=0;l<3;l++)
{
%>
<tdalign="center">
<%
if(ges[h][l]!=0){
%>
<ahref="move.jsp?h=<%=h%>&l=<%=l%>">
<fontstyle="FONT-WEIGHT:bold;FONT-SIZE:50px;COLOR:#FF0000;;FONT-FAMILY:Georgia">
<b><i><%=ges[h][l]%></b></i>
</font>
</a>
<%
}else{
%>
&nbsp;
<%}%>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>

move.jsp

<%
int[][]ges=newint[3][3];
ges=(int[][])session.getAttribute("ges");

inth=Integer.parseInt(request.getParameter("h"));
intl=Integer.parseInt(request.getParameter("l"));

if((h>0)&&(ges[h-1][l]==0))
{
ges[h-1][l]=ges[h][l];
ges[h][l]=0;
}
if(h<2&&ges[h+1][l]==0)
{
ges[h+1][l]=ges[h][l];
ges[h][l]=0;
}

if(l>0&&ges[h][l-1]==0)
{
ges[h][l-1]=ges[h][l];
ges[h][l]=0;
}
if(l<2&&ges[h][l+1]==0)
{
ges[h][l+1]=ges[h][l];
ges[h][l]=0;
}

session.setAttribute("ges",ges);
response.sendRedirect("see.jsp");

%>


作者:吕海鹏
来自:it学习网原创
更新日志:
参考文档:
致谢:
讨论网址: http://bbs.deepteach.com
标签(Tags):jsp+session
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值