久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

jsp實現剪子石頭布小游戲

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

本文實例為大家分享了jsp實現剪子石頭布游戲的具體代碼,供大家參考,具體內容如下

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

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

實現過程:使用form表單進行跳轉處理,難點在圖片傳值這部分和數據統計部分,以下是代碼:

游戲界面代碼:

<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> <!-- 獲得當前web project的名字 --> <%String pa = request.getContextPath(); %> <!-- form表單頁面跳轉 --> <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>

游戲界面:

游戲結果頁面代碼:

<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(); //獲取游戲參與者的選項值 String res=request.getParameter("option"); String reslong=res+".jpg"; //產生隨機數進行匹配圖片  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>結果是</h3> <!-- 圖片傳值 --> 您出的是:<img src="<%=pathnew %>/images/<%=reslong %>"> <span color="red">vs</span> 電腦出的是:<img src="<%=pathnew %>/images/<%=computerlong %>"> <% //邏輯判斷,session更新統計值, 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>統計結果,待寫入數據庫</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>

游戲結果:

這個絕對沒作弊,因為我輸了5局哪!老師還提過下次要寫個類似老虎機的游戲,估計在這個程序上做作弊就可以了。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。

標簽: JSP
相關文章:
主站蜘蛛池模板: 亚洲国产高清在线 | 一区二区三区在线不卡 | 亚洲精品在线视频观看 | 99久久夜色精品国产亚洲1000部 | 国产97在线播放 | 欧美日韩在线一区二区三区 | 欧美另类综合 | 四季久久免费一区二区三区四区 | 午夜国产视频 | a久久久 | 午夜精品偷拍 | 国产精品一区二区三区在线免费观看 | 欧美成人一区二区三区片免费 | 国产视频久久久 | 久久99精品久久久久蜜臀 | 国产91麻豆视频 | 人人种亚洲 | 天天操综 | 日韩精品视频在线观看免费 | 毛片网在线观看 | 欧美日韩亚洲视频 | 日韩在线视频观看 | 久久久.com | 中国一级毛片 | 视频1区 | 久久久蜜桃一区二区人 | a级毛片免费高清视频 | 日韩中文字幕在线播放 | 91亚洲国产精品 | 久久99精品久久久久久园产越南 | 美女在线一区 | 成人免费视频观看视频 | 日韩欧美在线视频播放 | 久久久成人精品 | 黄色精品视频 | 亚洲国产精品成人综合色在线婷婷 | 亚洲成人免费 | 国产成人涩涩涩视频在线观看 | 久久久久国产 | 91婷婷射| 国产一区中文字幕 |