Commit f61f5997 by Pedro Rolon

Se agregó el proyecto correspondiente a la tarea

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_191">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="lib/json-20180813.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jweb-e002</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="jweb-e002">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="jweb-e002"/>
<property name="java-output-path" value="/jweb-e002/build/classes"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v8.0"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/>
<fixed facet="java"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Manifest-Version: 1.0
Class-Path:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="clases.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mejores Combinaciones</title>
</head>
<body style="background-color: #871b7c;">
<h1>Mejores Combinaciones</h1>
<hr>
<h2>Cartas Generadas Aleatoriamente</h2>
<%
Carta[] cartas = (Carta[])request.getAttribute("cartas");
for(int i=0; i<cartas.length; i++){
String nombreImagen="";
%>
<img src="imagenesCartas/<%= cartas[i].valor.toUpperCase()+cartas[i].palo.toUpperCase() %>.png" width=80 height="120">
<%}%>
<br>
<h2>Mejores Combinaciones</h2>
<%
Carta[] mano = new Carta[5];
String mejores = (String)request.getAttribute("mejores");
Poker p = new Poker();
//Separa el string en arrays, donde encuentre ";"
//Si hay ; quiere decir que hubieron dos o mas ganadores
for(int i=0; i<mejores.split(";").length; i++) {
//Los arrays resultantes de separar por ; lo separa por coma
for(int j=0; j<mejores.split(";")[i].split(",").length; j++) {
mano[j] = new Carta(mejores.split(";")[i].split(",")[j]);
%>
<img src="imagenesCartas/<%= mano[j].valor.toUpperCase()+mano[j].palo.toUpperCase() %>.png" width=80 height="120">
<%}%>
<h4><%=p.nombreJugada(mano)%></h4>
<br>
<%}%>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<img src= "<%=request.getAttribute("rutaImagen") %>" width=200 height=250 >
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="clases.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mano doc desde api</title>
</head>
<body style="background-color: #ced5e0;">
<h1>Cartas!</h1>
<hr>
<h2>Manos Aleatorias extraidas desde api</h2>
<%Carta[] cartas = (Carta[])request.getAttribute("mano");
String nombreJugada = (String) request.getAttribute("nombreJugada");
for(int i=0; i<cartas.length; i++){
%>
<img src="<%="imagenesCartas/"+ cartas[i].valor+cartas[i].palo+".png" %>" width=80 height=120>
<%
}
%>
<h3>Jugada: <%=nombreJugada%></h3>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>jweb-e002</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Cartas de Poker</h1>
<hr>
<form action="/jweb-e002/dibujar_carta" method="get">
Palo: <select name="palo">
<option value="s">S</option>
<option value="h">H</option>
<option value="c">C</option>
<option value="d">D</option>
</select>
<br>
Valor: <input type="text" name="valor">
<input type="submit">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<li><a href="html/cartas.html">Cartas</a></li>
<li><a href="SieteCartas">7 Cartas</a></li>
<li><a href="mano_doc">Usando API</a></li>
</ul>
</body>
</html>
\ No newline at end of file
package clases;
public class Carta {
public Carta()
{
}
public Carta(String completo)
{
this.valor = String.valueOf(completo.charAt(0));
this.palo = String.valueOf(completo.charAt(1));
}
String valorPalo()
{
return this.valor + this.palo;
}
public String valor;
public String palo;
}
package servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Cartas
*/
@WebServlet("/dibujar_carta")
public class Cartas extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Cartas() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String palo = request.getParameter("palo").toUpperCase();
String valor = request.getParameter("valor").toUpperCase();
String rutaImagen = "imagenesCartas/"+valor+palo+".png";
System.out.println(rutaImagen);
request.setAttribute("rutaImagen", rutaImagen);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/WEB-INF/jsp/cartas.jsp");
rd.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package servlets;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import org.json.JSONObject;
import clases.Carta;
import clases.Poker;
/**
* Servlet implementation class ManoDoc
*/
@WebServlet("/mano_doc")
public class ManoDoc extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ManoDoc() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url = "https://deckofcardsapi.com/api/deck/new/draw/?count=5";
String json = obtenerJson(url);
Carta[] mano = obtenerCartas(json);
Poker p = new Poker();
String nombreJugada = p.nombreJugada(mano);
for(int i=0; i<mano.length; i++) {
System.out.println(mano[i].valor + mano[i].palo);
}
System.out.println(nombreJugada);
System.out.println("************************");
request.setAttribute("mano", mano);
request.setAttribute("nombreJugada", nombreJugada);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/WEB-INF/jsp/mano_doc.jsp");
rd.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
public static String obtenerJson(String myURL) {
System.setProperty("http.agent", "Chrome");
System.out.println("Requeted URL:" + myURL);
StringBuilder sb = new StringBuilder();
URLConnection urlConn = null;
InputStreamReader in = null;
try {
URL url = new URL(myURL);
urlConn = url.openConnection();
if (urlConn != null)
urlConn.setReadTimeout(60 * 1000);
if (urlConn != null && urlConn.getInputStream() != null) {
in = new InputStreamReader(urlConn.getInputStream(),
Charset.defaultCharset());
BufferedReader bufferedReader = new BufferedReader(in);
if (bufferedReader != null) {
int cp;
while ((cp = bufferedReader.read()) != -1) {
sb.append((char) cp);
}
bufferedReader.close();
}
}
in.close();
} catch (Exception e) {
throw new RuntimeException("Exception while calling URL:"+ myURL, e);
}
return sb.toString();
}
public Carta[] obtenerCartas(String json) {
JSONObject obj = new JSONObject(json);
JSONArray cartas = obj.getJSONArray("cards");
Carta[] mano= new Carta[5];
for(int i=0; i<mano.length;i++) {
String valor = cartas.getJSONObject(i).getString("code").substring(0, 1);
String palo = cartas.getJSONObject(i).getString("code").substring(1, 2);
if(valor.equals("0")) {
valor = "T";
}
String carta = valor+palo;
mano[i] = new Carta(carta);
}
return mano;
}
}
package servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import clases.*;
/**
* Servlet implementation class SieteCartas
*/
@WebServlet("/SieteCartas")
public class SieteCartas extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public SieteCartas() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Poker p = new Poker();
Carta [] cartas;
//Genera las cartas aleatoriamente y las almacena en un array de Cartas
cartas = p.generarCartas(7);
String mejores = p.mejorJugada(cartas);
request.setAttribute("cartas", cartas);
request.setAttribute("mejores", mejores);
/*
//Imprime las cartas generadas aleatoriamente
for(int i=0 ;i<cartas.length; i++) {
System.out.println(cartas[i].valor+cartas[i].palo);
}
System.out.println("******");
//Encuentra las mejores jugadas de todas las combinaciones posibles de 7 cartas tomadas de a 5
//y las guarda en un string llamado mejores
System.out.println(mejores);
System.out.println("******");
*/
//Se define un array de cartas para almacenar la mano que será evaluada
//y de quien se obtendrá el nombre de jugada
Carta[] mano = new Carta[5];
//Separa el string en arrays, donde encuentre ";"
//Si hay ; quiere decir que hubieron dos o mas ganadores
for(int i=0; i<mejores.split(";").length; i++) {
//Los arrays resultantes de separar por ; lo separa por coma
for(int j=0; j<mejores.split(";")[i].split(",").length; j++) {
mano[j] = new Carta(mejores.split(";")[i].split(",")[j]);
System.out.println(mano[j].valor+mano[j].palo);
}
System.out.println(p.nombreJugada(mano));
System.out.println("************");
}
RequestDispatcher rd = getServletContext().getRequestDispatcher("/WEB-INF/jsp/SieteCartas.jsp");
rd.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment