色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

jsp實(shí)現(xiàn)剪子石頭布小游戲

瀏覽:145日期:2022-06-07 15:11:10

本文實(shí)例為大家分享了jsp實(shí)現(xiàn)剪子石頭布游戲的具體代碼,供大家參考,具體內(nèi)容如下

老師前兩天除了一道小游戲的題目要大家做做,其實(shí)不太難,用了接近兩個(gè)小時(shí)才做出來,先看一下題目。

問題描述:實(shí)現(xiàn)兩個(gè)頁面,第一個(gè)頁面要求用圖片或radio或select,第二個(gè)頁面顯示輸贏的結(jié)果并把所有的結(jié)果保存輸出。剪子石頭布小游戲,跟常理一樣,不必多說。

實(shí)現(xiàn)過程:使用form表單進(jìn)行跳轉(zhuǎn)處理,難點(diǎn)在圖片傳值這部分和數(shù)據(jù)統(tǒng)計(jì)部分,以下是代碼:

游戲界面代碼:

<html> <head> <base href="<%=basePath%>" >  <title>歡迎來到剪刀石頭布游戲大廳</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0">  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" > --> </head>  <body> <!-- 獲得當(dāng)前web project的名字 --> <%String pa = request.getContextPath(); %> <!-- form表單頁面跳轉(zhuǎn) --> <form action="result.jsp" method="post"> <input type="radio" name="option" value="jiandao"><img src="<%=pa%>/images/jiandao.jpg"> <input type="radio" name="option" value="shitou"><img alt=石頭" src="<%=pa%>/images/shitou.jpg"> <input type="radio"name="option" value="bu"><img src="<%=pa%>/images/bu.jpg"> <input type="submit"value="確定"/> </form> </body></html>

游戲界面:

游戲結(jié)果頁面代碼:

<html> <head> <base href="<%=basePath%>" >  <title>My JSP "result.jsp" starting page</title>  <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0">  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" > -->  </head>  <body> <% String pathnew=request.getContextPath(); //獲取游戲參與者的選項(xiàng)值 String res=request.getParameter("option"); String reslong=res+".jpg"; //產(chǎn)生隨機(jī)數(shù)進(jìn)行匹配圖片  int com=(int)Math.random()*3; String computer=String.valueOf(com); //computer=0 jiandao  //computer=1 shiyou //computer=2 bu if(computer.equals("0")){ computer="jiandao"; }  else if(computer.equals("1")){ computer="shitou"; } else{ computer="bu"; } String computerlong=computer+".jpg"; int win=0; int lost=0; int ping=0; Object objwin=session.getAttribute("win"); Object objlost=session.getAttribute("lost"); Object objping=session.getAttribute("ping"); if(objwin==null){ session.setAttribute("win",String.valueOf(win)); } if(objlost==null){ session.setAttribute("lost",String.valueOf(lost)); } if(objping==null){ session.setAttribute("ping",String.valueOf(ping)); } %> <h3>結(jié)果是</h3> <!-- 圖片傳值 --> 您出的是:<img src="<%=pathnew %>/images/<%=reslong %>"> <span color="red">vs</span> 電腦出的是:<img src="<%=pathnew %>/images/<%=computerlong %>"> <% //邏輯判斷,session更新統(tǒng)計(jì)值, if(res.equals(computer)){ out.println("平局!"); //session.setAttribute("ping",String.valueOf(Integer.valueOf((String)session.getAttribute("ping"))+1)); session.setAttribute("ping",String.valueOf(Integer.valueOf((String)session.getAttribute("ping"))+1)); }  else if((res.equals("jiandao")&&computer.equals("bu"))||(res.equals("shitou")&&computer.equals("jiandao"))||(res.equals("bu")&&computer.equals("shiyou"))){ out.println("您贏了!"); //session.setAttribute("win",String.valueOf(Integer.valueOf((String)session.getAttribute("win"))+1)); session.setAttribute("win",String.valueOf(Integer.valueOf((String)session.getAttribute("win"))+1)); }  else{ out.println("您輸了!"); session.setAttribute("lost",String.valueOf(Integer.valueOf((String)session.getAttribute("lost"))+1)); //session.setAttribute("lost",String.valueOf(Integer.valueOf((String)session.getAttribute("lost"))+1)); }  %>  <h3>統(tǒng)計(jì)結(jié)果,待寫入數(shù)據(jù)庫</h3> 您一共玩了<%=String.valueOf( Integer.valueOf((String)session.getAttribute("win"))+Integer.valueOf((String)session.getAttribute("lost"))+Integer.valueOf((String)session.getAttribute("ping")) )%>局<br/> 您贏了<%=String.valueOf( Integer.valueOf((String)session.getAttribute("win"))) %>局<br/> 您輸了<%=String.valueOf( Integer.valueOf((String)session.getAttribute("lost"))) %>局<br/> 打平了<%=String.valueOf( Integer.valueOf((String)session.getAttribute("ping"))) %>局<br/> </body></html>

游戲結(jié)果:

這個(gè)絕對(duì)沒作弊,因?yàn)槲逸斄?局哪!老師還提過下次要寫個(gè)類似老虎機(jī)的游戲,估計(jì)在這個(gè)程序上做作弊就可以了。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。

標(biāo)簽: JSP
相關(guān)文章:
主站蜘蛛池模板: 欧美一级特黄做 | 亚洲精品久久久久中文字幕一区 | 国产亚洲一区二区精品 | 99视频在线精品免费 | 亚洲网址在线观看 | 久久久国产精品福利免费 | 欧美一区二区三区久久综合 | 天天五月天丁香婷婷深爱综合 | 久久99精品久久久久久久不卡 | 久久国产一级毛片一区二区 | 精品午夜寂寞影院在线观看 | 97国产在线视频公开免费 | 99je全部都是精品视频在线 | 久久色精品 | 亚洲成a人在线播放www | 亚洲国产成人久久一区www | 九九免费在线视频 | 香港激情黄三级在线视频 | 亚洲91精品| 国产一级毛片午夜 | 免费国产成人高清在线观看不卡 | 99久热在线精品视频播放6 | 日韩美女免费线视频 | 欧美成人三级网站 | 国产精品久久久久国产精品 | 精品日韩欧美一区二区三区 | 在线免费公开视频 | 一区二区三区四区免费视频 | 国产福利社区 | 国产欧美综合精品一区二区 | 在线观看国产精品一区 | 高清成人爽a毛片免费网站 高清大学生毛片一级 | 久久99精品久久只有精品 | 欧美极品欧美精品欧美视频 | 久久精品久久精品国产大片 | 日本韩国一级毛片中文字幕 | 最新国产成人综合在线观看 | 日韩一区二区免费看 | 老师张开腿让我爽了一夜视频 | 成人免费公开视频 | 国产九九免费视频网站 |