婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > jsp實(shí)現(xiàn)剪子石頭布小游戲

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

熱門標(biāo)簽:外呼系統(tǒng)使用方法 南通通訊外呼系統(tǒng)產(chǎn)品介紹 電銷機(jī)器人免培訓(xùn) 海外圖書館地圖標(biāo)注點(diǎn) 潤滑油銷售電銷機(jī)器人 給地圖標(biāo)注得傭金 電話機(jī)器人需要使用網(wǎng)絡(luò)嗎 自繪地圖標(biāo)注數(shù)據(jù) 如何看懂地圖標(biāo)注點(diǎn)

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

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

問題描述:實(shí)現(xiàn)兩個頁面,第一個頁面要求用圖片或radio或select,第二個頁面顯示輸贏的結(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 alt="剪刀" 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 alt="布" 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 alt="" src="%=pathnew %>/images/%=reslong %>">
 span style="bold" color="red">vs/span>
 電腦出的是:img alt="" 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é)果:

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

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

您可能感興趣的文章:
  • jsp+servlet實(shí)現(xiàn)猜數(shù)字游戲
  • JSP實(shí)現(xiàn)百萬富翁猜數(shù)字游戲
  • 基于jsp的井字游戲?qū)嵗?/li>
  • jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲

標(biāo)簽:黃石 樂山 南京 銅川 大連 貸款邀約 內(nèi)江 廣州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《jsp實(shí)現(xiàn)剪子石頭布小游戲》,本文關(guān)鍵詞  jsp,實(shí)現(xiàn),剪子,石頭,布,小游戲,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《jsp實(shí)現(xiàn)剪子石頭布小游戲》相關(guān)的同類信息!
  • 本頁收集關(guān)于jsp實(shí)現(xiàn)剪子石頭布小游戲的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 微山县| 成安县| 米易县| 澄迈县| 百色市| 凌海市| 临潭县| 星子县| 进贤县| 东城区| 梓潼县| 新巴尔虎左旗| 韶山市| 安康市| 鲁山县| 上林县| 乌拉特后旗| 南部县| 武强县| 铜陵市| 重庆市| 保德县| 颍上县| 额济纳旗| 广昌县| 富源县| 舟曲县| 凌源市| 丘北县| 德清县| 邹平县| 城口县| 湘潭市| 连云港市| 鄂温| 金沙县| 嘉黎县| 通山县| 曲麻莱县| 彝良县| 通河县|