Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <%@page import="java.lang.String"%>
  2. <%@page import="java.util.ArrayList"%>
  3. <%@page import="java.util.Scanner"%>
  4. <%@page import="java.io.File"%>
  5. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  6. <%
  7.  
  8. ArrayList<String> szavak = new ArrayList<>();
  9.  
  10. File txt = new File("C:\\szavak.txt");
  11. Scanner sc = new Scanner(txt);
  12.  
  13. while(sc.hasNextLine()){
  14.    szavak.add(sc.nextLine());
  15. }
  16. int n = 50;
  17. String [] martippelt = new String[n];
  18.  
  19. String gondoltSzo = szavak.get((int)(Math.random() * szavak.size()));
  20. String tipp;
  21.  
  22. if (session.getAttribute("gszo") == null){
  23.    
  24.     session.setAttribute("gszo", gondoltSzo);
  25. }
  26.  
  27.  
  28.  
  29. if (session.getAttribute("rtipp") == null){
  30.     session.setAttribute("rtipp", "");
  31. }
  32. String rossztipp = (String)session.getAttribute("rtipp");
  33. if (session.getAttribute("hkep") == null){
  34.     session.setAttribute("hkep", 0);
  35. }
  36. int kep = (int)session.getAttribute("hkep");
  37.  
  38. StringBuilder vonalka = new StringBuilder("");
  39. if (session.getAttribute("vonal") == null){
  40.     for(int i = 0; i < gondoltSzo.length(); i++){
  41.         vonalka.append("_");
  42.     }
  43.     session.setAttribute("vonal", vonalka);
  44. }else {
  45.     vonalka = (StringBuilder)session.getAttribute("vonal");
  46. }
  47.  
  48.  
  49. String eredmeny = "";
  50. String tippParam = request.getParameter("tipp");
  51.  
  52. if (tippParam!=null && tippParam.length()>0) {
  53.  
  54.  
  55.     try
  56.     {   tipp = tippParam;
  57.      
  58.             if (vonalka.toString().equals(gondoltSzo)) {
  59.                 eredmeny = "<br />Eltalálta!";
  60.                 session.removeAttribute("gszo");
  61.                 session.setAttribute("hkep", null);
  62.             }
  63.             else {
  64.                 boolean b = false;
  65.                 for(int i = 0; i < gondoltSzo.length()-1;i++){
  66.                     if(gondoltSzo.charAt(i) == tipp.charAt(0)){
  67.                         vonalka.setCharAt(i , tipp.charAt(0));
  68.                         b = true;
  69.                     }
  70.                 }
  71.                 if (!b) {
  72.                     rossztipp +=" ";
  73.                     rossztipp += tipp +" ";
  74.                     eredmeny = "Ez a betű nincs benne a gondolt szóban "+rossztipp+".\n";
  75.                     kep++;
  76.                     session.setAttribute("hkep", kep);
  77.                     session.setAttribute("rtipp", rossztipp);
  78.                     if(kep>10){
  79.                         eredmeny = "vége a játéknak!";
  80.                     }
  81.  
  82.                 }
  83.             }
  84.         }
  85.    
  86.     catch (NumberFormatException ex)
  87.     {
  88.         eredmeny="<br /> Helytelen Betü!";
  89.     }
  90.  }
  91.  
  92.     %>
  93. <!DOCTYPE html>
  94. <html>
  95.     <head>
  96.         <script>
  97.             function restart()
  98.             {
  99.                // Session.abondon();
  100.                 //location.reload();
  101.                 document.cookie="JSESSIONID=";
  102.                 location.reload();
  103.             }
  104.         </script>
  105.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  106.     <title>Akasztófa</title>
  107.         <script>
  108.         function ellenor(tipp)
  109.         {
  110.             if (!isNaN(tipp))
  111.             {
  112.                 alert("Nem betűt adott meg!");
  113.                     return false;
  114.                 }
  115.                 else if (tipp.length==0)
  116.                 {
  117.                      alert("Nem adott meg tippet!");
  118.                     return false;
  119.                 }
  120.                 else if (tipp.length>1)
  121.                  {alert("Egyszerre csak egy betűt adjon meg!");
  122.                 return false;
  123.             }
  124.             return true;
  125.         }
  126.         </script>
  127.     </head>
  128.     <h1>Akasztófa</h1>
  129.     <h2>Adja meg a következő betű tippjét (a-z)!</h2>
  130.  
  131.         <form action="index.jsp" onsubmit="return ellenor(tipp.value);">
  132.         <INPUT TYPE="text" NAME="tipp" value="" size="10" maxlength="1" />
  133.         <INPUT TYPE="submit" value="Elküld" title="<%=gondoltSzo%>"/>
  134.         </form>
  135.     <h2><%=eredmeny%></h2>
  136.     <h2><img src="pic/akasztofa<%=kep%>.png"</h2>
  137.    
  138.     <h2><%=vonalka%></h2>
  139.     <br/>
  140.    
  141.                        
  142.                     <% OUT.println(gondoltSzo);
  143.                     if(kep==11)
  144.                          session.invalidate();
  145.                     %>
  146.  
  147.                         <button onclick='restart();<%%> '>Új játék!</button>
  148.                        
  149.  
  150. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement