Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page import="java.lang.String"%>
- <%@page import="java.util.ArrayList"%>
- <%@page import="java.util.Scanner"%>
- <%@page import="java.io.File"%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%
- ArrayList<String> szavak = new ArrayList<>();
- File txt = new File("C:\\szavak.txt");
- Scanner sc = new Scanner(txt);
- while(sc.hasNextLine()){
- szavak.add(sc.nextLine());
- }
- int n = 50;
- String [] martippelt = new String[n];
- String gondoltSzo = szavak.get((int)(Math.random() * szavak.size()));
- String tipp;
- if (session.getAttribute("gszo") == null){
- session.setAttribute("gszo", gondoltSzo);
- }
- if (session.getAttribute("rtipp") == null){
- session.setAttribute("rtipp", "");
- }
- String rossztipp = (String)session.getAttribute("rtipp");
- if (session.getAttribute("hkep") == null){
- session.setAttribute("hkep", 0);
- }
- int kep = (int)session.getAttribute("hkep");
- StringBuilder vonalka = new StringBuilder("");
- if (session.getAttribute("vonal") == null){
- for(int i = 0; i < gondoltSzo.length(); i++){
- vonalka.append("_");
- }
- session.setAttribute("vonal", vonalka);
- }else {
- vonalka = (StringBuilder)session.getAttribute("vonal");
- }
- String eredmeny = "";
- String tippParam = request.getParameter("tipp");
- if (tippParam!=null && tippParam.length()>0) {
- try
- { tipp = tippParam;
- if (vonalka.toString().equals(gondoltSzo)) {
- eredmeny = "<br />Eltalálta!";
- session.removeAttribute("gszo");
- session.setAttribute("hkep", null);
- }
- else {
- boolean b = false;
- for(int i = 0; i < gondoltSzo.length()-1;i++){
- if(gondoltSzo.charAt(i) == tipp.charAt(0)){
- vonalka.setCharAt(i , tipp.charAt(0));
- b = true;
- }
- }
- if (!b) {
- rossztipp +=" ";
- rossztipp += tipp +" ";
- eredmeny = "Ez a betű nincs benne a gondolt szóban "+rossztipp+".\n";
- kep++;
- session.setAttribute("hkep", kep);
- session.setAttribute("rtipp", rossztipp);
- if(kep>10){
- eredmeny = "vége a játéknak!";
- }
- }
- }
- }
- catch (NumberFormatException ex)
- {
- eredmeny="<br /> Helytelen Betü!";
- }
- }
- %>
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function restart()
- {
- // Session.abondon();
- //location.reload();
- document.cookie="JSESSIONID=";
- location.reload();
- }
- </script>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Akasztófa</title>
- <script>
- function ellenor(tipp)
- {
- if (!isNaN(tipp))
- {
- alert("Nem betűt adott meg!");
- return false;
- }
- else if (tipp.length==0)
- {
- alert("Nem adott meg tippet!");
- return false;
- }
- else if (tipp.length>1)
- {alert("Egyszerre csak egy betűt adjon meg!");
- return false;
- }
- return true;
- }
- </script>
- </head>
- <h1>Akasztófa</h1>
- <h2>Adja meg a következő betű tippjét (a-z)!</h2>
- <form action="index.jsp" onsubmit="return ellenor(tipp.value);">
- <INPUT TYPE="text" NAME="tipp" value="" size="10" maxlength="1" />
- <INPUT TYPE="submit" value="Elküld" title="<%=gondoltSzo%>"/>
- </form>
- <h2><%=eredmeny%></h2>
- <h2><img src="pic/akasztofa<%=kep%>.png"</h2>
- <h2><%=vonalka%></h2>
- <br/>
- <% OUT.println(gondoltSzo);
- if(kep==11)
- session.invalidate();
- %>
- <button onclick='restart();<%%> '>Új játék!</button>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement