web版简单三国风云,无图,带数据库

  • u0_753519
    了解作者
  • 407.7KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 04:49
    上传日期
选择武将,然后提交战斗mysql数据库使用,可扩张其功能
Youxi.rar
内容介绍
package com.sanguo.service; import java.io.IOException; import java.util.List; import java.util.Random; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sanguo.database.Dao; import com.sanguo.vo.Renwu; public class ControlServlet extends HttpServlet { /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); Dao dao = new Dao(); List<Renwu> list = dao.findAll(); request.setAttribute("all", list); request.getRequestDispatcher("index.jsp").forward(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String one = request.getParameter("one"); String two = request.getParameter("two"); Integer a = Integer.parseInt(one); Integer b = Integer.parseInt(two); Renwu player = new Dao().findById(a); Renwu enemy = new Dao().findById(b); while(player.getTili()>0&&enemy.getTili()>0) { String crit = ""; if(player.getAttack() == 1) { int r1 = new Random().nextInt(99)+1+player.getWuli()-enemy.getWuli(); int r2 = (new Random().nextInt(99)+1)*enemy.getWuli()/player.getWuli(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean flog = new Random().nextBoolean(); sha = flog?sha*2:sha; crit = flog?"暴击":""; } if(r1>r2) { enemy.setTili(enemy.getTili()-sha); response.getWriter().print(player.getName()+"使用武力"+crit+"给"+enemy.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(player.getName()+"使用武力没有给"+enemy.getName()+"造成伤害<br>"); } } if(player.getAttack() == 2) { int r1 = new Random().nextInt(99)+1+player.getZhili()-enemy.getZhili(); int r2 = (new Random().nextInt(99)+1)*enemy.getZhili()/player.getZhili(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean flog = new Random().nextBoolean(); sha = flog?sha*2:sha; crit = flog?"暴击":""; } if(r1>r2) { enemy.setTili(enemy.getTili()-sha); response.getWriter().print(player.getName()+"使用计谋"+crit+"给"+enemy.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(player.getName()+"使用计谋没有给"+enemy.getName()+"造成伤害<br>"); } } if(player.getAttack() == 3) { boolean flog = new Random().nextBoolean(); if(flog) { int r1 = new Random().nextInt(99)+1+player.getZhili()-enemy.getZhili(); int r2 = (new Random().nextInt(99)+1)*enemy.getZhili()/player.getZhili(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean f = new Random().nextBoolean(); sha = flog?sha*2:sha; crit = flog?"暴击":""; } if(r1>r2) { enemy.setTili(enemy.getTili()-sha); response.getWriter().print(player.getName()+"使用计谋"+crit+"给"+enemy.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(player.getName()+"使用计谋没有给"+enemy.getName()+"造成伤害<br>"); } } else { int r1 = new Random().nextInt(99)+1+player.getWuli()-enemy.getWuli(); int r2 = (new Random().nextInt(99)+1)*enemy.getWuli()/player.getWuli(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean f = new Random().nextBoolean(); sha = flog?sha*2:sha; crit = flog?"暴击":""; } if(r1>r2) { enemy.setTili(enemy.getTili()-sha); response.getWriter().print(player.getName()+"使用武力"+crit+"给"+enemy.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(player.getName()+"使用武力没有给"+enemy.getName()+"造成伤害<br>"); } } } if(enemy.getTili()<=0) { break; } crit = ""; if(enemy.getAttack() == 1) { float r1 = new Random().nextInt(99)+1-player.getWuli()+enemy.getWuli(); float r2 = (new Random().nextInt(99)+1)*player.getWuli()/enemy.getWuli(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean f = new Random().nextBoolean(); sha = f?sha*2:sha; crit = f?"暴击":""; } if(r1>r2) { player.setTili(player.getTili()-sha); response.getWriter().print(enemy.getName()+"使用武力"+crit+"给"+player.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(enemy.getName()+"使用武力没有给"+player.getName()+"造成伤害<br>"); } } if(enemy.getAttack() == 2) { float r1 = new Random().nextInt(99)+1+enemy.getZhili()-player.getZhili(); float r2 = (new Random().nextInt(99)+1)*player.getZhili()/enemy.getZhili(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean f = new Random().nextBoolean(); sha = f?sha*2:sha; crit = f?"暴击":""; } if(r1>r2) { player.setTili(player.getTili()-sha); response.getWriter().print(enemy.getName()+"使用计谋"+crit+"给"+player.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(enemy.getName()+"使用计谋没有给"+player.getName()+"造成伤害<br>"); } } if(enemy.getAttack() == 3) { boolean flog = new Random().nextBoolean(); if(flog) { int r1 = new Random().nextInt(99)+1-player.getZhili()+enemy.getZhili(); int r2 = (new Random().nextInt(99)+1)*player.getZhili()/enemy.getZhili(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean f = new Random().nextBoolean(); sha = f?sha*2:sha; crit = f?"暴击":""; } if(r1>r2) { player.setTili(player.getTili()-sha); response.getWriter().print(enemy.getName()+"使用计谋"+crit+"给"+player.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(enemy.getName()+"使用计谋没有给"+player.getName()+"造成伤害<br>"); } } else { int r1 = new Random().nextInt(99)+1-player.getWuli()+enemy.getWuli();; int r2 = (new Random().nextInt(99)+1)*player.getWuli()/enemy.getWuli(); Integer sha = new Random().nextInt(10)+10; if(r1-r2>=40) { boolean f = new Random().nextBoolean(); sha = f?sha*2:sha; crit = f?"暴击":""; } if(r1>r2) { player.setTili(player.getTili()-sha); response.getWriter().print(enemy.getName()+"使用武力"+crit+"给"+player.getName()+"造成"+ sha +"点伤害<br>"); } else { response.getWriter().print(enemy.getName()+"使用武力没有给"+player.getName()+"造成伤害<br>"); } } } } response.getWriter().print("最终结果:<br>"); response.getWriter().print(player.getName()+" 体力:"+playe
评论
    相关推荐