diff --git a/.gitignore b/.gitignore index 26f78e3..fa1c3ae 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,19 @@ -*.class -*.log -*.tmp \ No newline at end of file +# Java +**/.class +**/.jar + +# IDE / Editor +## VS code / VS Codium +**/.vscode/ + +# Git +**/.git/ +!/.git/ + + +# Temporal +## Folders +**/trash/ +## Files +**/.log +**/.tmp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..ac3e445 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Java + +## Install: + +### Oracle + +[Oracle | Cloud Applications and Cloud Platform](https://www.oracle.com/) + +[Java Downloads | Oracle](https://www.oracle.com/java/technologies/downloads/) + +### Adoptium + +[Adoption](https://adoptium.net) + +[Adoption releases](https://adoptium.net/es/temurin/releases/) + + +```sh +apt install -y wget apt-transport-https gpg +wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null +echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list +apt update +apt install temurin-17-jdk +``` + +### Maven + +```shell +sudo apt install maven + +mvn -version +``` + +## Commands + +```java +javac Main.java +java Main +``` + diff --git a/base_de_datos/src/main/resources/reports/reporte_none.jrxml b/base/project/.gitkeep similarity index 100% rename from base_de_datos/src/main/resources/reports/reporte_none.jrxml rename to base/project/.gitkeep diff --git a/makefile b/makefile new file mode 100644 index 0000000..160dbf3 --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +purge: + find . -name "*.class" -type f -delete + + +# Windows Command Powershell: +purge_windows: + powershell -Command "Get-ChildItem -Recurse -Include *.class,*.log,*.tmp,*~ | Remove-Item -Force" + +# Linux Command +purge_linux: + find . -name "*.class" -type f -delete \ No newline at end of file diff --git a/base_de_datos/README.md b/project/base_de_datos/README.md similarity index 100% rename from base_de_datos/README.md rename to project/base_de_datos/README.md diff --git a/base_de_datos/makefile b/project/base_de_datos/makefile similarity index 100% rename from base_de_datos/makefile rename to project/base_de_datos/makefile diff --git a/base_de_datos/pom.xml b/project/base_de_datos/pom.xml similarity index 100% rename from base_de_datos/pom.xml rename to project/base_de_datos/pom.xml diff --git a/base_de_datos/sql/1_db.sql b/project/base_de_datos/sql/1_db.sql similarity index 100% rename from base_de_datos/sql/1_db.sql rename to project/base_de_datos/sql/1_db.sql diff --git a/base_de_datos/sql/2_table.sql b/project/base_de_datos/sql/2_table.sql similarity index 100% rename from base_de_datos/sql/2_table.sql rename to project/base_de_datos/sql/2_table.sql diff --git a/base_de_datos/sql/3_insert.sql b/project/base_de_datos/sql/3_insert.sql similarity index 100% rename from base_de_datos/sql/3_insert.sql rename to project/base_de_datos/sql/3_insert.sql diff --git a/base_de_datos/sql/4_debug.sql b/project/base_de_datos/sql/4_debug.sql similarity index 100% rename from base_de_datos/sql/4_debug.sql rename to project/base_de_datos/sql/4_debug.sql diff --git a/base_de_datos/sql/backup.sql b/project/base_de_datos/sql/backup.sql similarity index 100% rename from base_de_datos/sql/backup.sql rename to project/base_de_datos/sql/backup.sql diff --git a/base_de_datos/src/main/java/com/proy_final/Proy_final_db.java b/project/base_de_datos/src/main/java/com/proy_final/Proy_final_db.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/Proy_final_db.java rename to project/base_de_datos/src/main/java/com/proy_final/Proy_final_db.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/Init.java b/project/base_de_datos/src/main/java/com/proy_final/mod/Init.java similarity index 99% rename from base_de_datos/src/main/java/com/proy_final/mod/Init.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/Init.java index 478251c..26d19a7 100644 --- a/base_de_datos/src/main/java/com/proy_final/mod/Init.java +++ b/project/base_de_datos/src/main/java/com/proy_final/mod/Init.java @@ -15,9 +15,6 @@ import javax.swing.JPanel; public class Init extends JFrame implements ActionListener { - - - public Init() { this.setTitle("Proy Final"); this.setLayout(null); diff --git a/base_de_datos/src/main/java/com/proy_final/mod/db/DataBase.java b/project/base_de_datos/src/main/java/com/proy_final/mod/db/DataBase.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/db/DataBase.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/db/DataBase.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/template/Persona.java b/project/base_de_datos/src/main/java/com/proy_final/mod/template/Persona.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/template/Persona.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/template/Persona.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/template/Ubicacion.java b/project/base_de_datos/src/main/java/com/proy_final/mod/template/Ubicacion.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/template/Ubicacion.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/template/Ubicacion.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/data/Cliente.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Cliente.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/data/Cliente.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Cliente.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/data/Departamento.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Departamento.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/data/Departamento.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Departamento.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/data/Provincia.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Provincia.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/data/Provincia.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Provincia.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/data/Vendedor.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Vendedor.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/data/Vendedor.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/data/Vendedor.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/menu/NavBar.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/NavBar.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/menu/NavBar.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/NavBar.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/menu/inicio/MenuInicioPresentacion.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/inicio/MenuInicioPresentacion.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/menu/inicio/MenuInicioPresentacion.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/inicio/MenuInicioPresentacion.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoCliente.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoCliente.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoCliente.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoCliente.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoVendedor.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoVendedor.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoVendedor.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/mantenimiento/MenuMantenimientoVendedor.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteCliente.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteCliente.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteCliente.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteCliente.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteVendedor.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteVendedor.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteVendedor.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/menu/reporte/MenuReporteVendedor.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/settings/Global.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/settings/Global.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/settings/Global.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/settings/Global.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/struct/Vec2x2.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/struct/Vec2x2.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/struct/Vec2x2.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/struct/Vec2x2.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxCliente.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxCliente.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxCliente.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxCliente.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxVendedor.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxVendedor.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxVendedor.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelMantenimientoBoxVendedor.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelPresentacion.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelPresentacion.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelPresentacion.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelPresentacion.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteCliente.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteCliente.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteCliente.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteCliente.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteVendedor.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteVendedor.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteVendedor.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/view/PanelReporteVendedor.java diff --git a/base_de_datos/src/main/java/com/proy_final/mod/util/view/gui/PanelMantenimientoBox.java b/project/base_de_datos/src/main/java/com/proy_final/mod/util/view/gui/PanelMantenimientoBox.java similarity index 100% rename from base_de_datos/src/main/java/com/proy_final/mod/util/view/gui/PanelMantenimientoBox.java rename to project/base_de_datos/src/main/java/com/proy_final/mod/util/view/gui/PanelMantenimientoBox.java diff --git a/base_de_datos/src/main/resources/reports/reporte_cliente.jrxml b/project/base_de_datos/src/main/resources/reports/reporte_cliente.jrxml similarity index 100% rename from base_de_datos/src/main/resources/reports/reporte_cliente.jrxml rename to project/base_de_datos/src/main/resources/reports/reporte_cliente.jrxml diff --git a/project/base_de_datos/src/main/resources/reports/reporte_none.jrxml b/project/base_de_datos/src/main/resources/reports/reporte_none.jrxml new file mode 100644 index 0000000..e69de29 diff --git a/base_de_datos/src/main/resources/reports/reporte_vendedor.jrxml b/project/base_de_datos/src/main/resources/reports/reporte_vendedor.jrxml similarity index 100% rename from base_de_datos/src/main/resources/reports/reporte_vendedor.jrxml rename to project/base_de_datos/src/main/resources/reports/reporte_vendedor.jrxml diff --git a/project/cafeteria/README.tex b/project/cafeteria/README.tex new file mode 100755 index 0000000..43852a8 --- /dev/null +++ b/project/cafeteria/README.tex @@ -0,0 +1,328 @@ +\documentclass[a4paper, 12pt]{article} +\usepackage[bookmarks=true, unicode]{hyperref} +\usepackage{bookmark} + +\usepackage{fontawesome} + +\usepackage[spanish]{babel} +\usepackage[utf8]{inputenc} + +\usepackage{graphicx} + +\usepackage{listings} +\usepackage{xcolor} + +\renewcommand{\lstlistingname}{Código} +\definecolor{codegreen}{rgb}{0,0.6,0} +\definecolor{codegray}{rgb}{0.5,0.5,0.5} +\definecolor{codepurple}{rgb}{0.58,0,0.82} +\definecolor{backcolour}{rgb}{0.98,0.98,0.98} + +\lstdefinestyle{mystyle}{ + backgroundcolor=\color{backcolour}, + commentstyle=\color{codegreen}, + keywordstyle=\color{magenta}, + numberstyle=\tiny\color{codegray}, + stringstyle=\color{codepurple}, + basicstyle=\ttfamily\footnotesize, + breakatwhitespace=false, + breaklines=true, + captionpos=b, + keepspaces=true, + numbers=left, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2, + basicstyle=\ttfamily, + moredelim=[il][\textcolor{pgrey}]{$$}, + moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%} +} + +\lstset{style=mystyle} +\setlength{\parindent}{0pt} + + +\title{Cafeteria} +\author{Tuzikuz} +\date{\today} + +\raggedright + + +% enumitem clashes with enumerate +\usepackage{enumitem,amssymb} +\newlist{todolist}{itemize}{2} +\setlist[todolist]{label=$\square$} + +\usepackage{pifont} +\newcommand{\cmark}{\ding{51}}% +\newcommand{\xmark}{\ding{55}}% +\newcommand{\done}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}\cmark}}% +\hspace{-2.5pt}} +\newcommand{\wontfix}{\rlap{$\square$}{\large\hspace{1pt}\xmark}} + + +% \begin{lstlisting}[language=Java, caption=Enum java] \end{lstlisting} +% \vspace{0.5cm} + +\begin{document} +\maketitle + + +\newpage + + +\tableofcontents + +\section{TODO} + +\begin{todolist} + \item[\done] Inicio + + \item[\done] Ver menu + \begin{todolist} + \item[\done] Ver detalles + \end{todolist} + + \item[\done] Pedidos + \begin{todolist} + \item[\done] Refund + \item[\done] Mis productos + \item[\done] Recargar saldo + \item[\done] Reducir saldo + \item[\done] Eliminar pedido + \item[\done] Factura + \end{todolist} + + \item[\done] Debug +\end{todolist} + + \section{Index} + + \subsection{Paginas} + \url{https://www.youtube.com} + + \url{https://www.digitalocean.com} + + \url{https://stackoverflow.com} + + \url{https://www.w3schools.com} + + \url{https://www.javatpoint.com} + + \url{https://forums.oracle.com} + + \url{https://www.cs.utexas.edu} + + \url{www.edureka.co} + + + + + \section{Printf in java} + + \begin{lstlisting}[ + language=Java, + caption=Printf java, + extendedchars=true, + inputencoding=utf8, + literate={á}{{\'a}}1 {ã}{{\~a}}1 {é}{{\'e}}1, + ] +/* +Format Specifiers +Lets look at the available format specifiers available for printf: + +%c character +%d decimal (integer) number (base 10) +%e exponential floating-point number +%f floating-point number +%i integer (base 10) +%o octal number (base 8) +%s String +%u unsigned decimal (integer) number +%x number in hexadecimal (base 16) +%t formats date/time +%% print a percent sign +\% print a percent sign + + +Escape Characters +Following are the escape characters available in printf(): + +\b backspace +\f next line first character starts to the right of current line last character +\n newline +\r carriage return +\t tab +\\ backslash +*/ + +int var = 10; +System.out.printf("%i", var);\end{lstlisting} + + \vspace{0.5cm} + + \href{https://www.digitalocean.com/community/tutorials/java-printf-method}{Java printf() - Print Formatted String to Console | DigitalOcean} + + + + + \begin{lstlisting}[language=Java, caption=String format] +int a = 1, b = 2, c = 3; + +return String.format("%d %d %d", a, b, c);\end{lstlisting}\vspace{0.5cm} + + \href{https://www.geeksforgeeks.org/java-string-format-method-with-examples/}{Java String format() Method With Examples - GeeksforGeeks} + + \vspace{0.3cm} + \href{https://stackoverflow.com/questions/23461344/can-a-return-statement-be-formatted-like-a-printf}{java - Can a return statement be formatted like a printf? - Stack Overflow} + + \vspace{0.3cm} + \href{https://www.digitalocean.com/community/tutorials/java-printf-method}{Java printf() - Print Formatted String to Console | DigitalOcean} + + + + + \section{Enum} + + \begin{lstlisting}[language=Java, caption=Enum java] +enum Level { + LOW, + MEDIUM, + HIGH +} + +Level myVar = Level.MEDIUM;\end{lstlisting}\vspace{0.5cm} + + \href{https://www.w3schools.com/java/java_enums.asp}{w3schools Java Enums} + + \vspace{0.3cm} + \href{https://stackoverflow.com/questions/23058275/should-i-use-uppercase-or-camelcase-in-label-enums}{stackoverflow java - Should I use uppercase or camelcase in label enums? - Stack Overflow} + + \vspace{0.3cm} + \href{https://stackoverflow.com/questions/8143995/should-java-member-enum-types-be-capitalized}{stackoverflow eclipse - Should Java member enum types be capitalized? - Stack Overflow} + + + + + \section{Set and get} + \begin{lstlisting}[language=Java, caption=Set get] +public class Person { + private String name; // private = restricted access + + // Getter + public String getName() { + return name; + } + + // Setter + public void setName(String newName) { + this.name = newName; + } +} + \end{lstlisting} + \href{https://www.w3schools.com/java/java_encapsulation.asp}{Java Encapsulation and Getters and Setters} + + + + + \section{Extends and List} + \begin{lstlisting}[language=Java, caption=Extends List] +// You could use java generic.First create a java collection (ex: List) with supper class type, Product. Now you could add any sub classes (Monitor , Keyboard etc) in your collection (List) that extends of class Product. + + +public class Product{} +public class Monitor extends Product{} + +public class Keyboard extends Product{} + +List products = new ArrayList(); +products.add(new Monitor()); +products.add(new Keyboard());\end{lstlisting}\vspace{0.5cm} + + \href{https://stackoverflow.com/questions/18288655/storing-multiple-object-types-in-a-list}{java - Storing multiple object types in a List - Stack Overflow} + + \vspace{0.3cm} + \href{https://es.stackoverflow.com/questions/496024/c%C3%B3digo-en-java-con-arraylist-y-herencia}{Código en Java con arrayList y herencia - Stack Overflow en español]} + + \vspace{0.3cm} + \href{https://www.javatpoint.com/arraylist-implementation-in-java}{ArrayList Implementation in Java - Javatpoint} + + \vspace{0.3cm} + \href{https://forums.oracle.com/ords/apexds/post/to-extend-arraylist-or-to-not-extend-arraylist-1665}{To extend ArrayList, or to not extend ArrayList - Oracle Forums} + + \vspace{0.3cm} + \href{https://www.w3resource.com/java-exercises/oop/java-oop-exercise-18.php}{Java - Restaurant menu, average rating} + + \vspace{0.3cm} + \href{https://www.w3schools.com/java/java_inheritance.asp}{Java Inheritance (Subclass and Superclass)} + \vspace{0.5cm} + + \begin{enumerate} + \item Class array: \href{https://youtu.be/QTPIYcQ6Cxc?t=1100}{ArrayList inheritance Everything - YouTube} + \item super(): \href{https://youtu.be/QTPIYcQ6Cxc?t=2426}{ArrayList inheritance Everything - YouTube} + \item Return string: \href{https://youtu.be/QTPIYcQ6Cxc?t=2629}{ArrayList inheritance Everything - YouTube} + \end{enumerate} + + + \section{Package} + + \begin{lstlisting}[language=Java, caption=Enum java] +import mytest.Mypckg; + +public class Learn { + public static void main(String[] args) { + System.out.println("Hello World"); + Mypckg.show(); + } +} +package mytest; +public class Mypckg { + public static void show(){ + System.out.println("Good Moring"); + } +} + \end{lstlisting}\vspace{0.5cm} + + \href{https://stackoverflow.com/questions/63868318/how-to-import-class-of-one-file-to-another-in-a-subfolder-in-java-using-vscode}{How to import class of one file to another in a subfolder in Java using vscode - Stack Overflow} + + \vspace{0.3cm} + \href{https://stackoverflow.com/questions/26432953/java-import-sub-sub-directory}{Java import sub-sub directory - Stack Overflow} + + \vspace{0.3cm} + \href{https://www.youtube.com/watch?v=PsuZ0WxDJ0M}{How To Import A Class In Java From Another Package or Project - Java Tutorial - YouTube} + + \vspace{0.3cm} + \href{https://www.youtube.com/watch?v=3ybNZM6cP3M}{Calling Java class from other file in Visual Studio Code - YouTube} + + \vspace{0.5cm} + + + \section{User input} + \begin{lstlisting}[language=Java, caption=Normal input] +InputStreamReader inputStreamReader new InputStreamReader (System.in); + +BufferedReader buffer = new BufferedReader (inputStreamReader); + +String userInput = buffer.readLine(); + +int userInputToInt = Integer.parseInt(userInput); +\end{lstlisting}\vspace{1cm} + + \begin{lstlisting}[language=Java, caption=Others input] +BufferedReader buffer = new BufferedReader (new InputStreamReader (System.in)); + +int userInput = Integer.parseInt(buffer.readLine());\end{lstlisting}\vspace{0.5cm} + + \href{https://www.cs.utexas.edu/~mitra/csSpring2004/cs313/assgn/BufferedReader.html#:~:text=BufferedReader%20input%20%3D%20new%20BufferedReader%20(new,readLine()%3B}{Using Buffered Readers} + + \vspace{0.3cm} + \href{https://stackoverflow.com/questions/25491997/how-to-read-multiple-integer-values-from-one-line-in-java-using-bufferedreader-o}{arrays - How to read multiple integer values from one line in Java using BufferedReader object? - Stack Overflow} + + \vspace{0.3cm} + \href{https://www.edureka.co/community/40038/how-to-take-input-using-bufferedreader-in-java}{How to take input using BufferedReader in Java | Edureka Community} + + +\end{document} \ No newline at end of file diff --git a/project/cafeteria/makefile b/project/cafeteria/makefile new file mode 100755 index 0000000..9d53e17 --- /dev/null +++ b/project/cafeteria/makefile @@ -0,0 +1,8 @@ +all: + cd ./src && javac Main.java && java Main + +latex: + pdflatex README.tex + +clear: + del /s /q *.class *.log *.aux *.toc \ No newline at end of file diff --git a/project/cafeteria/src/Main.java b/project/cafeteria/src/Main.java new file mode 100755 index 0000000..a42abcf --- /dev/null +++ b/project/cafeteria/src/Main.java @@ -0,0 +1,9 @@ +import cafeteria.Restaurante; + +public class Main { + public static void main(String[] args) { + Restaurante restaurante = new Restaurante(); + restaurante.db(); + restaurante.start(); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/Restaurante.java b/project/cafeteria/src/cafeteria/Restaurante.java new file mode 100755 index 0000000..8226452 --- /dev/null +++ b/project/cafeteria/src/cafeteria/Restaurante.java @@ -0,0 +1,540 @@ +package cafeteria; + +import cafeteria.clientela.Cliente; +import cafeteria.clientela.ClientePedido; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +import cafeteria.productos.alcohol.*; +import cafeteria.productos.bebida.*; +import cafeteria.productos.alimento.*; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.ArrayList; + +public class Restaurante { + private BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + + private Cliente cliente; + + public Restaurante() { + try { + System.out.printf("%nIngrese sus datos (Cliente):%n"); + + System.out.printf("Cual es tu...%n"); + System.out.printf("Nombre: "); + String nombre = bufferedReader.readLine(); + + System.out.printf("Edad: "); + int edad = Integer.parseInt(bufferedReader.readLine()); + + System.out.printf("Dinero: "); + float dinero = Float.parseFloat(bufferedReader.readLine()); + + cliente = new Cliente(nombre, edad, dinero); + + System.out.printf("%nBienvenido a la cafeteria %s%n", cliente.getNombre()); + + } catch (IOException e) { + System.out.println("Ocurrio un error de entrada/salida:" + e.getMessage()); + } catch (NumberFormatException e) { + System.out.println("Por favor, ingresa solo numeros validos."); + } + } + + ArrayList drain = new ArrayList(); + private int mainID = -1; + + public int getID() { + return this.mainID += 1; + } + + ArrayList gastronomia = new ArrayList(); + public void db() { + gastronomia.add(new CafeNegro(getID(), 25, 1f)); + gastronomia.add(new CafeConLeche(getID(), 25, 1.25f)); + gastronomia.add(new CervezaCristalizada(getID(), 20, 4.05f)); + gastronomia.add(new Limonada(getID(), 5, 3.25f)); + gastronomia.add(new VinoVerde(getID(), 5, 5.25f)); + gastronomia.add(new FlorDeLuna(getID(), 20, 2.45f)); + gastronomia.add(new GalletaRoja(getID(), 13, 3.0f)); + gastronomia.add(new PanDulce(getID(), 22, 1.25f)); + gastronomia.add(new GalletaDorada(getID(), 1, 9999999.99f)); + } + + int userInput, userInputID, userInputCantidad; + boolean end = false; + boolean start = true; + boolean menu = false, menuDetalles = false; + boolean pedido = false, pedidoTerminado = false, pedidoSalir = false, pedidoVer = false, pedidoSaldo = false, inputDrain; + float subTotal = 0; + + + public void menuPedido() { + System.out.printf("%n%n--------------------------------------------------------------%n"); + System.out.printf("|%20s%-20s%20s|%n", "", "MENU DE PRODUCTOS ", ""); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("| %-5s | %-15s | %-17s | %11s |%n", "Numero", "Nombre", "Disponibilidad", "Precio"); + System.out.printf("--------------------------------------------------------------%n"); + for (int i = 0; i < gastronomia.size(); i += 1) { + System.out.printf("| %-6d | %-15s | %-17d | %11.2f |%n", i, gastronomia.get(i).getNombre(), gastronomia.get(i).getStock(), gastronomia.get(i).getPrecio()); + System.out.printf("--------------------------------------------------------------%n"); + } + } + + ArrayList clientePedidos = new ArrayList(); + public void start() { + try { + while(true) { + subTotal = 0; + userInput = 0; + if (end) { + System.out.printf("%nSaliendo...%n"); + System.exit(0); + } + + if (start) { + start = false; + System.out.printf("%n"); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("|%20s%-20s%20s|%n", "", "Cafeteria Sin Nombre", ""); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("|%-60s|%n", "1. Ver menu"); + System.out.printf("|%-60s|%n", "2. Hacer pedido"); + System.out.printf("|%-60s|%n", "3. Salir"); + System.out.printf("--------------------------------------------------------------%n"); + if (inputDrain) { + inputDrain = false; + for (int i = 0; i < drain.size(); i += 1) { + System.out.printf(String.format(drain.get(i))); + } + } + System.out.printf("Ingrese una opcion: "); + userInput = Integer.parseInt(bufferedReader.readLine()); + + switch(userInput) { + case 1: + menu = true; + continue; + case 2: + pedido = true; + continue; + case 3: + end = true; + continue; + default: + start = true; + System.out.printf("%nOpcion Invalida intente de nuevo%n"); + continue; + } + } + + if (menu) { + menu = false; + menuPedido(); + + System.out.printf("1. Inicio%n"); + System.out.printf("2. Ver detalles%n"); + System.out.printf("3. Hacer pedido%n"); + System.out.printf("4. Salir%n"); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Ingrese una opcion: "); + userInput = Integer.parseInt(bufferedReader.readLine()); + + + switch(userInput) { + case 1: + start = true; + continue; + case 2: + menuDetalles = true; + continue; + case 3: + pedido = true; + continue; + case 4: + end = true; + continue; + default: + start = true; + System.out.printf("%nOpcion Invalida intente de nuevo%n"); + continue; + } + } + + if (menuDetalles) { + menuDetalles = false; + System.out.printf("%n%n--------------------------------------------------------------%n"); + System.out.printf("|%18s%-20s%18s|%n", "", "DESCRIPCION DE PRODUCTOS", ""); + System.out.printf("--------------------------------------------------------------%n"); + for (int i = 0; i < gastronomia.size(); i += 1) { + System.out.printf("| %-5s | %-15s | %-40s%n", i, gastronomia.get(i).getNombre(), gastronomia.get(i).getDescripcion()); + System.out.printf("--------------------------------------------------------------%n"); + } + System.out.printf("1. Inicio%n"); + System.out.printf("2. Menu%n"); + System.out.printf("3. Hacer pedido%n"); + System.out.printf("4. Salir%n"); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Ingrese una opcion: "); + userInput = Integer.parseInt(bufferedReader.readLine()); + switch(userInput) { + case 1: + start = true; + continue; + case 2: + menu = true; + continue; + case 3: + pedido = true; + continue; + case 4: + end = true; + continue; + default: + start = true; + System.out.printf("%nOpcion Invalida intente de nuevo%n"); + continue; + } + } + + if (pedido) { + menuPedido(); + System.out.printf("|%20s%-20s%20s|%n", "", "Haciendo pedido...", ""); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Ingrese el producto que desea%n"); + System.out.printf("-1 Para salir%n"); + System.out.printf("ID: "); + userInputID = Integer.parseInt(bufferedReader.readLine()); + + switch (userInputID) { + case -1: + break; + default: + System.out.printf("Cantidad: "); + userInputCantidad = Integer.parseInt(bufferedReader.readLine()); + } + System.out.printf("--------------------------------------------------------------"); + + if (userInputID == -1 || userInputCantidad == -1) { + pedidoSalir = true; + } + + if (pedidoSalir == false && 0 > userInputID || gastronomia.size() < userInputID) { + System.out.printf("%nProducto no encontrado, intente de nuevo.%n"); + continue; + } + + if (pedidoSalir == false && userInputCantidad <= 0) { + System.out.printf("%nLa cantidad pedida es 0 o menor, intente de nuevo.%n"); + continue; + } + + if (pedidoSalir == false && gastronomia.get(userInputID).getStock() - userInputCantidad < 0) { + System.out.printf("%n%nLa cantidad pedida es mayor de la que tenemos, intente de nuevo.%n"); + continue; + } + + if (pedidoSalir == false && cliente.getDinero() < gastronomia.get(userInputID).getPrecio() * userInputCantidad) { + System.out.printf("%nUsted no tiene el suficiente saldo para adquirir este producto, intente agregar mas saldo..%n"); + continue; + } + + if (pedidoSalir == false && cliente.getEdad() < 18 && gastronomia.get(userInputID).getTypo() == GastronomiaTypo.ALCOHOL) { + System.out.printf("%nUsted no tiene la edad suficiente para adquirir este producto, intente de nuevo.%n"); + continue; + } + + + if (pedidoSalir == false) { + clientePedidos.add(new ClientePedido(gastronomia.get(userInputID).getID(), userInputCantidad)); + + gastronomia.get(userInputID).setStockSub(userInputCantidad); + + System.out.printf("%n%nAgrego[ID:%d, Nombre:%s, Contidad:%d] | Stock: %d %n", + gastronomia.get(userInputID).getID(), + gastronomia.get(userInputID).getNombre(), + userInputCantidad, + gastronomia.get(userInputID).getStock() + ); + } + + pedidoSalir = false; + System.out.printf("%n--------------------------------------------------------------%n"); + System.out.printf("1. Terminar pedido%n"); + System.out.printf("2. Hacer otro pedido%n"); + System.out.printf("3. Volver%n"); + System.out.printf("4. Mis productos%n"); + System.out.printf("5. Agregar saldo%n"); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Ingrese una opcion: "); + userInput = Integer.parseInt(bufferedReader.readLine()); + + switch (userInput) { + case 1: + if (clientePedidos.size() == 0) { + System.out.printf("%nNo podemos terminar tu pedido si no ha pedido nada, "); + System.out.printf("si desea volver sin pedir nada intente con la opcion:%n"); + System.out.printf("3. Volver.%n%n"); + continue; + } + + for (int i = 0; i < clientePedidos.size(); i += 1) { + int indexPtr = clientePedidos.get(i).getPtr(); + int indexCantidad = clientePedidos.get(i).getCantidad(); + + for (int x = 0; x < gastronomia.size(); x += 1) { + if (gastronomia.get(x).getID() == indexPtr) { + subTotal += indexCantidad * gastronomia.get(x).getPrecio(); + } + } + } + + if (cliente.getDinero() < subTotal) { + System.out.printf("%nUsted no tiene el suficiente saldo para terminar su pedido. intente eliminar algun producto.%n"); + subTotal = 0; + continue; + } + pedido = false; + pedidoTerminado = true; + continue; + case 2: + continue; + case 3: + pedido = false; + + for (int i = 0; i < clientePedidos.size(); i += 1) { + int indexPtr = clientePedidos.get(i).getPtr(); + int indexCantidad = clientePedidos.get(i).getCantidad(); + + for (int x = 0; x < gastronomia.size(); x += 1) { + if (gastronomia.get(x).getID() == indexPtr) { + gastronomia.get(x).setStockAdd(indexCantidad); + + System.out.printf("Ha devuelto: [idPedido: %d, idProducto: %d, Nombre: %s, Cantidad: %d] %n", + i, + gastronomia.get(x).getID(), + gastronomia.get(x).getNombre(), + indexCantidad + ); + break; + } + } + } + + for (int i = 0; i < clientePedidos.size(); i += 1) { + clientePedidos.remove(i); + } + + start = true; + continue; + case 4: + pedido = false; + pedidoVer = true; + continue; + case 5: + pedido = false; + pedidoSaldo = true; + continue; + default: + System.out.printf("%nOpcion Invalida intente de nuevo%n"); + continue; + } + } + + if (pedidoSaldo) { + pedidoSaldo = false; + pedido = true; + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("%nCuanto saldo desea agregar: "); + cliente.setDineroAdd(Integer.parseInt(bufferedReader.readLine())); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Tu saldo actual es: %.2f %n", cliente.getDinero()); + System.out.printf("--------------------------------------------------------------%n"); + } + + if (pedidoVer) { + if ( clientePedidos.size() == 0) { + System.out.printf("%nUsted carece de algun producto, intente pedir uno.%n"); + pedido = true; + continue; + } + + System.out.printf("%n--------------------------------------------------------------%n"); + System.out.printf("|%20s%-20s%20s|%n", "", "Tus productos", ""); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("|%-8s|%-10s|%-14s|%-10s|%-8s|%-10s|%n", "IDPedido", "IDProducto", "Nombre", "Precio", "Cantidad", "Total"); + System.out.printf("--------------------------------------------------------------%n"); + for (int i = 0; i < clientePedidos.size(); i += 1) { + System.out.printf("|%-8d|%-10d|%-14s|%-10.2f|%-8d|%-10.2f|%n", + i, + clientePedidos.get(i).getPtr(), + gastronomia.get(clientePedidos.get(i).getPtr()).getNombre(), + gastronomia.get(clientePedidos.get(i).getPtr()).getPrecio(), + clientePedidos.get(i).getCantidad(), + gastronomia.get(clientePedidos.get(i).getPtr()).getPrecio() * clientePedidos.get(i).getCantidad() + ); + System.out.printf("--------------------------------------------------------------%n"); + subTotal += gastronomia.get(clientePedidos.get(i).getPtr()).getPrecio() * clientePedidos.get(i).getCantidad(); + } + + System.out.printf("%nSubtotal: %.2f%n", subTotal); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Tu saldo: %.2f%n", cliente.getDinero()); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("1. Recargar saldo%n"); + System.out.printf("2. Reducir saldo%n"); + System.out.printf("3. Eliminar pedido%n"); + System.out.printf("4. Volver%n"); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Input: "); + userInputID = Integer.parseInt(bufferedReader.readLine()); + + switch (userInputID) { + case 1: + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("%nCuanto saldo desea agregar: "); + cliente.setDineroAdd(Integer.parseInt(bufferedReader.readLine())); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Tu saldo actual es: %.2f %n", cliente.getDinero()); + System.out.printf("--------------------------------------------------------------%n"); + continue; + case 2: + System.out.printf("%nCuanto desea reducir: "); + float sub = Float.parseFloat(bufferedReader.readLine()); + if (cliente.getDinero() < sub) { + System.out.printf("El saldo restado en mayor de lo que tiene, Intente de nuevo%n"); + continue; + } + cliente.setDineroSub(sub); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Tu saldo total es: %.2f %n", cliente.getDinero()); + System.out.printf("--------------------------------------------------------------%n"); + continue; + case 3: + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("Que pedido desea eliminar o modificar?%n"); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("-1 Para salir%n"); + System.out.printf("ID: "); + + userInputID = Integer.parseInt(bufferedReader.readLine()); + if (userInputID == -1) { + continue; + } + + System.out.printf("Cantidad: "); + userInputCantidad = Integer.parseInt(bufferedReader.readLine()); + if (userInputCantidad == -1) { + continue; + } + + if (userInputID > gastronomia.size()) { + System.out.printf("Este pedido no esta en la lista. intentale de nuevo.%n"); + continue; + } + + if (true) { /*For fun uwu/ Claim the reward box */ + if (userInputID == -300) { + drain.add("%n%n%n uwu/ Esto es un easter egg. %n%n Reclame su caja misteriosa... %n%n Caja misteriosa: \"El premio son los conocimiento que hicimos en el camino\". owo/ %n%n%n"); + inputDrain = true; + } + } + + if (userInputID < 0 || userInputCantidad < 0) { + System.out.printf("%nLos pedidos -0 no existen, intente de nuevo.%n"); + continue; + } + + if (clientePedidos.get(userInputID).getCantidad() < userInputCantidad) { + System.out.printf("La cantidad a remover es mayor de la que pidio.%n"); + continue; + } + + System.out.printf("%n"); + + for (int i = 0; i < gastronomia.size(); i += 1) { + int indexPtr = clientePedidos.get(userInputID).getPtr(); + int indexCantidad = userInputCantidad; + + if (gastronomia.get(i).getID() == indexPtr) { + + gastronomia.get(i).setStockAdd(indexCantidad); + clientePedidos.get(userInputID).setCantidadSub(indexCantidad); + if (clientePedidos.get(userInputID).getCantidad() == 0) { + clientePedidos.remove(userInputID); + } + + System.out.printf("Ha devuelto: [idPedido: %d, idProducto: %d, Nombre: %s, Cantidad: %d] %n", + indexPtr, + gastronomia.get(i).getID(), + gastronomia.get(i).getNombre(), + indexCantidad + ); + break; + + + } + } + break; + case 4: + pedidoVer = false; + pedido = true; + continue; + default: + pedidoVer = false; + pedido = true; + System.out.printf("%nOpcion Invalida intente de nuevo%n"); + continue; + } + + } + + if (pedidoTerminado) { + System.out.printf("%n%n--------------------------------------------------------------%n"); + System.out.printf("|Recibo de: %s%n", cliente.getNombre()); + System.out.printf("--------------------------------------------------------------%n"); + System.out.printf("|%-2s|%-23s|%-10s|%-10s|%-11s|%n", "id", "Nombre", "Precio", "Cantidad", "Total"); + System.out.printf("--------------------------------------------------------------%n"); + + for (int i = 0; i < clientePedidos.size(); i += 1) { + int indexPtr = clientePedidos.get(i).getPtr(); + int indexCantidad = clientePedidos.get(i).getCantidad(); + + for (int x = 0; x < gastronomia.size(); x += 1) { + if (gastronomia.get(x).getID() == indexPtr) { + System.out.printf("|%-2d|%-23s|%-10.2f|%-10d|%-11.2f|%n", + i, + gastronomia.get(x).getNombre(), + gastronomia.get(x).getPrecio(), + indexCantidad, + indexCantidad * gastronomia.get(x).getPrecio() + ); + System.out.printf("--------------------------------------------------------------%n"); + subTotal += indexCantidad * gastronomia.get(x).getPrecio(); + } + } + + } + + System.out.printf("Total a pagar: %.2f", subTotal); + System.out.printf("%n--------------------------------------------------------------%n"); + System.out.printf("Total tu saldo: %.2f", cliente.getDinero() - subTotal); + System.out.printf("%n--------------------------------------------------------------%n"); + System.out.printf("|%19s%20s%20s|%n", "", "Gracias por su compra", ""); + System.out.printf("--------------------------------------------------------------%n"); + + end = true; + continue; + } + } + } catch (IOException e) { + System.out.println("Ocurrio un error de entrada/salida:" + e.getMessage()); + } catch (NumberFormatException e) { + System.out.println("Por favor, ingresa solo numeros validos."); + } + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/clientela/Cliente.java b/project/cafeteria/src/cafeteria/clientela/Cliente.java new file mode 100755 index 0000000..c10c52d --- /dev/null +++ b/project/cafeteria/src/cafeteria/clientela/Cliente.java @@ -0,0 +1,20 @@ +package cafeteria.clientela; + +public class Cliente { + private String nombre; + private int edad; + private float dinero; + + public Cliente(String nombre, int edad, float dinero) { + this.nombre = nombre; + this.edad = edad; + this.dinero = dinero; + } + + public String getNombre() { return this.nombre; } + public int getEdad() { return this.edad; } + public float getDinero() { return this.dinero; } + + public void setDineroAdd(float dinero) { this.dinero += dinero; } + public void setDineroSub(float dinero) { this.dinero -= dinero; } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/clientela/ClientePedido.java b/project/cafeteria/src/cafeteria/clientela/ClientePedido.java new file mode 100755 index 0000000..b5ef336 --- /dev/null +++ b/project/cafeteria/src/cafeteria/clientela/ClientePedido.java @@ -0,0 +1,16 @@ +package cafeteria.clientela; + +public class ClientePedido { + private int idPtr, cantidad; + + public ClientePedido(int idPtr, int cantidad) { + this.idPtr = idPtr; + this.cantidad = cantidad; + } + + public int getPtr() { return this.idPtr; } + public int getCantidad() { return this.cantidad; } + + public void setCantidadAdd(int num) { this.cantidad += num; } + public void setCantidadSub(int num) { this.cantidad -= num; } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/Gastronomia.java b/project/cafeteria/src/cafeteria/productos/Gastronomia.java new file mode 100755 index 0000000..63b5676 --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/Gastronomia.java @@ -0,0 +1,43 @@ +package cafeteria.productos; + +public class Gastronomia { + public enum GastronomiaTypo { + BEBIDA, + ALIMENTO, + ALCOHOL + } + + private int id; + private String nombre; + private int cantidad, stock; + private float precio; + private GastronomiaTypo typo; + private String descripcion; + + public Gastronomia(int id, String nombre, int cantidad, float precio, GastronomiaTypo typo, String descripcion) { + this.id = id; + this.nombre = nombre; + this.cantidad = cantidad; + this.stock = cantidad; + this.precio = precio; + this.typo = typo; + this.descripcion = descripcion; + } + + public void setNombre(String nombre) { this.nombre = nombre; } + public void setCantidadAdd(int cantidad) { this.cantidad += cantidad; } + public void setCantidadSub(int cantidad) { this.cantidad -= cantidad; } + public void setStockAdd(int stock) { this.stock += stock; } + public void setStockSub(int stock) { this.stock -= stock; } + public void setPrecio(float precio) { this.precio = precio; } + public void setTypo(GastronomiaTypo typo) { this.typo = typo; } + public void setDescripcion(String descripcion) { this.descripcion = descripcion; } + + public int getID() { return this.id; } + public String getNombre() { return this.nombre; } + public int getCantidad() { return this.cantidad; } + public int getStock() { return this.stock; } + public float getPrecio() { return this.precio; } + public GastronomiaTypo getTypo() { return this.typo; } + public String getDescripcion() { return this.descripcion; } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/alcohol/CervezaCristalizada.java b/project/cafeteria/src/cafeteria/productos/alcohol/CervezaCristalizada.java new file mode 100755 index 0000000..94ca61d --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/alcohol/CervezaCristalizada.java @@ -0,0 +1,10 @@ +package cafeteria.productos.alcohol; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class CervezaCristalizada extends Gastronomia { + public CervezaCristalizada(int id, int cantidad, float precio) { + super(id, "Cristalizada", cantidad, precio, GastronomiaTypo.ALCOHOL, "Cerveza con una sensacion cristalizada al beberla"); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/alcohol/VinoVerde.java b/project/cafeteria/src/cafeteria/productos/alcohol/VinoVerde.java new file mode 100755 index 0000000..6362501 --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/alcohol/VinoVerde.java @@ -0,0 +1,10 @@ +package cafeteria.productos.alcohol; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class VinoVerde extends Gastronomia { + public VinoVerde(int id, int cantidad, float precio) { + super(id, "Vino verde", cantidad, precio, GastronomiaTypo.ALCOHOL, String.format("Vino con un regusto picante")); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/alimento/FlorDeLuna.java b/project/cafeteria/src/cafeteria/productos/alimento/FlorDeLuna.java new file mode 100755 index 0000000..ed04c1b --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/alimento/FlorDeLuna.java @@ -0,0 +1,10 @@ +package cafeteria.productos.alimento; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class FlorDeLuna extends Gastronomia { + public FlorDeLuna(int id, int cantidad, float precio) { + super(id, "Flor De Luna", cantidad, precio, GastronomiaTypo.ALIMENTO, "Una galleta aflorada con una luna en medio"); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/alimento/GalletaDorada.java b/project/cafeteria/src/cafeteria/productos/alimento/GalletaDorada.java new file mode 100755 index 0000000..6a126bf --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/alimento/GalletaDorada.java @@ -0,0 +1,10 @@ +package cafeteria.productos.alimento; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class GalletaDorada extends Gastronomia { + public GalletaDorada(int id, int cantidad, float precio) { + super(id, "Galleta Dorada", cantidad, precio, GastronomiaTypo.ALIMENTO, "Galleta dorada (Dictan aquellos capaces de saborearla que sabe a alegría pura)"); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/alimento/GalletaRoja.java b/project/cafeteria/src/cafeteria/productos/alimento/GalletaRoja.java new file mode 100755 index 0000000..6476a95 --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/alimento/GalletaRoja.java @@ -0,0 +1,10 @@ +package cafeteria.productos.alimento; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class GalletaRoja extends Gastronomia { + public GalletaRoja(int id, int cantidad, float precio) { + super(id, "Galleta Roja", cantidad, precio, GastronomiaTypo.ALIMENTO, "Galleta con relleno dulce, al masticarlo el relleno sale como si fuera sangre, sangre dulce"); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/alimento/PanDulce.java b/project/cafeteria/src/cafeteria/productos/alimento/PanDulce.java new file mode 100755 index 0000000..651c70c --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/alimento/PanDulce.java @@ -0,0 +1,10 @@ +package cafeteria.productos.alimento; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class PanDulce extends Gastronomia { + public PanDulce(int id, int cantidad, float precio) { + super(id, "Pan dulce", cantidad, precio, GastronomiaTypo.ALIMENTO, "Pan dulce... solo un pan dulce"); + } +} \ No newline at end of file diff --git a/project/cafeteria/src/cafeteria/productos/bebida/CafeConLeche.java b/project/cafeteria/src/cafeteria/productos/bebida/CafeConLeche.java new file mode 100755 index 0000000..747bf2a --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/bebida/CafeConLeche.java @@ -0,0 +1,10 @@ +package cafeteria.productos.bebida; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class CafeConLeche extends Gastronomia { + public CafeConLeche(int id, int cantidad, float precio) { + super(id, "Cafe Con Leche", cantidad, precio, GastronomiaTypo.BEBIDA, "Un simple cafe con leche"); + } +} diff --git a/project/cafeteria/src/cafeteria/productos/bebida/CafeNegro.java b/project/cafeteria/src/cafeteria/productos/bebida/CafeNegro.java new file mode 100755 index 0000000..1d2f509 --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/bebida/CafeNegro.java @@ -0,0 +1,10 @@ +package cafeteria.productos.bebida; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class CafeNegro extends Gastronomia { + public CafeNegro(int id, int cantidad, float precio) { + super(id, "Cafe negro", cantidad, precio, GastronomiaTypo.BEBIDA, "Un simple cafe negro (Las leyendas dictan que el reflejo del cafe predice tu futuro)"); + } +} diff --git a/project/cafeteria/src/cafeteria/productos/bebida/Limonada.java b/project/cafeteria/src/cafeteria/productos/bebida/Limonada.java new file mode 100755 index 0000000..6415d95 --- /dev/null +++ b/project/cafeteria/src/cafeteria/productos/bebida/Limonada.java @@ -0,0 +1,10 @@ +package cafeteria.productos.bebida; + +import cafeteria.productos.Gastronomia; +import cafeteria.productos.Gastronomia.GastronomiaTypo; + +public class Limonada extends Gastronomia { + public Limonada(int id, int cantidad, float precio) { + super(id, "Limonada", cantidad, precio, GastronomiaTypo.BEBIDA, "Limonada dulce"); + } +} diff --git a/project/enjambre_de_langosta/META-INF/MANIFEST.MF b/project/enjambre_de_langosta/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a51079e --- /dev/null +++ b/project/enjambre_de_langosta/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.src.Proy1 +Created-By: Tuzikuz diff --git a/project/enjambre_de_langosta/META-INF/manifest.txt b/project/enjambre_de_langosta/META-INF/manifest.txt new file mode 100644 index 0000000..a51079e --- /dev/null +++ b/project/enjambre_de_langosta/META-INF/manifest.txt @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.src.Proy1 +Created-By: Tuzikuz diff --git a/project/enjambre_de_langosta/README.md b/project/enjambre_de_langosta/README.md new file mode 100755 index 0000000..fd8b884 --- /dev/null +++ b/project/enjambre_de_langosta/README.md @@ -0,0 +1 @@ +# Proy 1 Enjambre de Langosta v1.5 \ No newline at end of file diff --git a/project/enjambre_de_langosta/build/Ault_977_Proy1.jar b/project/enjambre_de_langosta/build/Ault_977_Proy1.jar new file mode 100644 index 0000000..6600d11 Binary files /dev/null and b/project/enjambre_de_langosta/build/Ault_977_Proy1.jar differ diff --git a/project/enjambre_de_langosta/makefile b/project/enjambre_de_langosta/makefile new file mode 100755 index 0000000..9c43982 --- /dev/null +++ b/project/enjambre_de_langosta/makefile @@ -0,0 +1,15 @@ +MAIN_CLASS = Proy1 + +all: + mkdir -p out + javac -d out $(shell find src -name "*.java") + cat META-INF/manifest.txt > META-INF/MANIFEST.MF + jar cfm build/$(MAIN_CLASS).jar META-INF/MANIFEST.MF -C out . + rm -rf ./out + cd build && java -jar $(MAIN_CLASS).jar + +purge_windows: + powershell -Command "Get-ChildItem -Recurse -Include *.class,*.log,*.tmp,*~ | Remove-Item -Force" + +purge_linux: + find . -name "*.class" -type f -delete \ No newline at end of file diff --git a/project/enjambre_de_langosta/src/com/Proy1.java b/project/enjambre_de_langosta/src/com/Proy1.java new file mode 100755 index 0000000..8be4810 --- /dev/null +++ b/project/enjambre_de_langosta/src/com/Proy1.java @@ -0,0 +1,11 @@ +package com.src; + +import mod.Init; + +public class Proy1 { + public static void main(String[] args) { + System.out.printf("Proy1 %n"); + Init game = new Init(); + game.start(); + } +} \ No newline at end of file diff --git a/project/enjambre_de_langosta/src/com/mod/Init.java b/project/enjambre_de_langosta/src/com/mod/Init.java new file mode 100755 index 0000000..2e8fefb --- /dev/null +++ b/project/enjambre_de_langosta/src/com/mod/Init.java @@ -0,0 +1,1123 @@ +package mod; + +import mod.utils.Vec2x2; +import mod.utils.GameButton; + + +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.Insets; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JButton; +import javax.swing.JTextField; +import javax.swing.JComponent; + + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.util.Random; + + + + + +public class Init extends JFrame implements ActionListener { + private JFrame window_main; + private String window_main_name = "Proy1 Ejambre de Langostas"; + + private Random rnd = new Random(); + private int ejambre = -1; + + private boolean debug = false; + private boolean debug_game_inside = false; + private JButton btn_loc_start; + private int intentos_counter = 0; + + enum EnumUIMenu { + EjambreUbication, + Debug, + Intentos, + InfoEjambre, + Iniciar + } + private JComponent[] ArrMenu = new JComponent[5]; + + private Color[] arr_color = { + Color.RED, + Color.YELLOW, + Color.GRAY, + Color.PINK, + Color.ORANGE, + Color.MAGENTA, + Color.CYAN, + new Color(190, 0, 190) + }; + + enum EnumEjambreMove { + Norte, + NorEste, + Este, + SurEste, + Sur, + SurOeste, + Oeste, + NorOeste, + } + + enum EnumEjambre { + Ejambre, + Norte, + NorEste, + Este, + SurEste, + Sur, + SurOeste, + Oeste, + NorOeste, + } + private JComponent[] ArrEjambre = new JComponent[9]; + public Init() {} + + public void start() { + System.out.printf("=====Cultivos Start Game=====\n"); + // System.out.printf("%d%n", ejambre); + + window_main = new JFrame(window_main_name); + window_main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window_main.setExtendedState(JFrame.MAXIMIZED_BOTH); + window_main.setLayout(null); + + Vec2x2 vec2x2_window_main = new Vec2x2(); + // vec2x2_window_main.x1_pos = 0; + // vec2x2_window_main.y1_pos = 0; + vec2x2_window_main.x2_size = 1400; + vec2x2_window_main.y2_size = 900; + + window_main.setBounds( + vec2x2_window_main.x1_pos, + vec2x2_window_main.y1_pos, + vec2x2_window_main.x2_size, + vec2x2_window_main.y2_size + ); + + + Vec2x2 vec2x2_map = new Vec2x2(); + vec2x2_map.x1_pos = 113; + vec2x2_map.y1_pos = 40; + vec2x2_map.x2_size = 0; + vec2x2_map.y2_size = 0; + + int i = 156, p = -1, x = 1, y = 14; + + // System.out.printf("Debug"); + for(; i >= 1; i = i - 1) { + p = p + 1; + + GameButton btn = new GameButton(); + btn.setEnabled(false); + btn.setText(String.valueOf(i)); + btn.setBounds( + // vec2x2_map.x1_pos+60*(p/13), + vec2x2_map.x1_pos+59*(p/13), + // vec2x2_map.y1_pos+45*(p%13), + vec2x2_map.y1_pos+45*(p%13), + 60, + 45 + ); + + // btn.setBounds(60+25*(i/13),60+55*(i%13),60,30); + // btn.setFont(new Font("Arial", Font.BOLD, 12)); + // btn.setFont(new Font("Arial", Font.BOLD, 24)); + // btn.setFont(new Font("Arial", Font.PLAIN, 18)); + btn.setMargin(new Insets(0, 0, 0, 0)); + // btn.setFont(new Font("Arial", Font.PLAIN, 16)); + btn.setFont(new Font("Arial", Font.PLAIN, 12)); + btn.addActionListener(this); + // btn.y = y; + // btn.x = x; + + window_main.add(btn); + } + + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fiel = (GameButton) cmp; + y = y - 1; + + fiel.y = y; + fiel.x = x; + + if (y == 1) { + y = 14; + x = x + 1; + } + } + } + + + Vec2x2 vec2x2_x_label = new Vec2x2(); + // vec2x2_x_label.x1_pos = 500; + vec2x2_x_label.y1_pos = 620; + vec2x2_x_label.x2_size = 20; + vec2x2_x_label.y2_size = 28; + + int y_pos = 14, p_pos = 0, x_pos = 0; + while (true) { + x_pos = x_pos + 1; + p_pos = p_pos + 1; + // System.out.printf("y:%d p:%d %n", x_pos, y_pos, p_pos); + + vec2x2_x_label.x1_pos = 84 + p_pos * 58; + JLabel x_label = new JLabel(String.valueOf(x_pos)); + if (debug) { + x_label.setOpaque(true); + x_label.setBackground(Color.GREEN); + } + x_label.setBounds( + vec2x2_x_label.x1_pos, + vec2x2_x_label.y1_pos, + vec2x2_x_label.x2_size, + vec2x2_x_label.y2_size + ); + window_main.add(x_label); + + if (x_pos == 12) { + p_pos = 0; + break; + } + } + + Vec2x2 vec2x2_y_label = new Vec2x2(); + vec2x2_y_label.x1_pos = 80; + vec2x2_y_label.y1_pos = 0; + vec2x2_y_label.x2_size = 30; + vec2x2_y_label.y2_size = 40; + while (true) { + y_pos = y_pos - 1; + p_pos = p_pos + 1; + + vec2x2_y_label.y1_pos = 7 + p_pos * 44; + JLabel y_label = new JLabel(String.valueOf(y_pos)); + if (debug) { + y_label.setOpaque(true); + y_label.setBackground(Color.YELLOW); + } + y_label.setBounds( + vec2x2_y_label.x1_pos, + vec2x2_y_label.y1_pos, + vec2x2_y_label.x2_size, + vec2x2_y_label.y2_size + ); + window_main.add(y_label); + + if (y_pos == 1) { + break; + } + } + + + + String[] arr_cardinal = new String[] { + " Norte ", + " Este ", + " Sur ", + " Oeste ", + }; + + Vec2x2[] arr_cardinal_pos = { + new Vec2x2(440, 0, 60, 35), + new Vec2x2(823, 320, 45, 35), + new Vec2x2(440, 650, 60, 35), + new Vec2x2(15, 320, 60, 35) + }; + + int num_cardinal_pos = -1; + for(String cardinal : arr_cardinal) { + num_cardinal_pos = num_cardinal_pos + 1; + + JLabel label_cardinal = new JLabel(cardinal); + + if (debug) { + label_cardinal.setOpaque(true); + label_cardinal.setBackground(Color.BLUE); + } + + Vec2x2 vec_cardinal = arr_cardinal_pos[num_cardinal_pos]; + + // System.out.printf("Pos:%d%n", arr_cardinal_pos[num_cardinal_pos].x1_pos); + // System.out.printf("Cardinal:%d%n", num_cardinal_pos); + // System.out.printf("Vec:%d%n", vec_cardinal.x1_pos); + + label_cardinal.setBounds( + vec_cardinal.x1_pos, + vec_cardinal.y1_pos, + vec_cardinal.x2_size, + vec_cardinal.y2_size + ); + + window_main.add(label_cardinal); + } + + + Vec2x2 vec2x2_menu_info_label = new Vec2x2(); + vec2x2_menu_info_label.x1_pos = 1045; + // vec2x2_menu_info_label.y1_pos = 100; + vec2x2_menu_info_label.x2_size = 320; + vec2x2_menu_info_label.y2_size = 30; + String[] arr_infos_menu_context = new String[] { + // String.format(" %40s %s %-10s ", "Facultad de Ingeniería de Sistemas Computacionales", ":", "Universidad Facultad"), + String.format(" %50s ", "Universidad Facultad"), + String.format(" %50s ", "Facultad de Ingeniería de Sistemas Computacionales"), + String.format(" %50s ", "Carrera"), + String.format(" %50s ", "Licenciatura en Desarrollo y Gestión de Software"), + String.format(" %50s ", "Materia"), + String.format(" %50s ", "Desarrollo de Software 3"), + String.format(" %50s ", "Profesor"), + String.format(" %50s ", "Ricardo Chan"), + String.format(" %50s ", "Estudiante Cedula"), + String.format(" %50s ", "0-000-0000"), + String.format(" %50s ", "Grupo" ), + String.format(" %50s ", "\\\\[!G_G???]// Grupo de 1: Tuzikuz"), + String.format(" %50s ", "Fecha"), + String.format(" %50s ", "6/04/2025"), + }; + + + int index = -1; + // for (int index = 0; index < arr_infos_menu.length; index++) { + for (String info : arr_infos_menu_context) { + index = index + 1; + JLabel info_menu = new JLabel(arr_infos_menu_context[index]); + + + if (debug) { + info_menu.setOpaque(true); + info_menu.setBackground(Color.RED); + } + + if (index % 2 == 0) { + int index_pos = 30 + index * 40; + info_menu.setBounds( + vec2x2_menu_info_label.x1_pos, + vec2x2_menu_info_label.y1_pos + index_pos, + vec2x2_menu_info_label.x2_size, + vec2x2_menu_info_label.y2_size + ); + } else { + int index_pos = 30 + index * 40; + info_menu.setBounds( + vec2x2_menu_info_label.x1_pos, + vec2x2_menu_info_label.y1_pos + index_pos - 20, + vec2x2_menu_info_label.x2_size, + vec2x2_menu_info_label.y2_size + ); + } + + window_main.add(info_menu); + } + + + + + String[] arr_menu_game = new String[] { + // Text Field + String.format(" %s ", "None :Ejambre Ubicacion"), + // Button + String.format(" %s ", "Debug"), + // Label + String.format(" %s %s ", "None", ":Intentos"), + String.format(" %s %s ", "None", ":Ejambre"), + // Button + String.format(" %s ", "Start"), + }; + + String[] arr_menu_info = new String[] { + "Menu_Ejambre", + "Menu_Debug", + "Menu_Intentos", + "Menu_Ejambre_Info", + "Menu_Inicio", + }; + + Vec2x2 vec2x2_menu_game = new Vec2x2(); + vec2x2_menu_game.x1_pos = 872; + vec2x2_menu_game.y1_pos = 50; + vec2x2_menu_game.x2_size = 170; + vec2x2_menu_game.y2_size = 50; + + Color debug_game_menu = Color.CYAN; + int num_game_menu = -1; + while(true) { + num_game_menu = num_game_menu + 1; + vec2x2_menu_game.y1_pos = vec2x2_menu_game.y1_pos + 60; + switch (num_game_menu) { + case 0: + JTextField text_field_Ejambre_Ubicacion = new JTextField(arr_menu_game[num_game_menu]); + text_field_Ejambre_Ubicacion.setName(arr_menu_info[num_game_menu]); + if (debug) {text_field_Ejambre_Ubicacion.setBackground(debug_game_menu);} + + text_field_Ejambre_Ubicacion.setVisible(false); + + text_field_Ejambre_Ubicacion.setBounds( + vec2x2_menu_game.x1_pos, + vec2x2_menu_game.y1_pos, + vec2x2_menu_game.x2_size, + vec2x2_menu_game.y2_size + ); + text_field_Ejambre_Ubicacion.addActionListener(this); + window_main.add(text_field_Ejambre_Ubicacion); + + ArrMenu[EnumUIMenu.EjambreUbication.ordinal()] = text_field_Ejambre_Ubicacion; + break; + + case 1: + JButton button_debug = new JButton(arr_menu_game[num_game_menu]); + button_debug.setName(arr_menu_info[num_game_menu]); + if (debug) {button_debug.setBackground(debug_game_menu);} + button_debug.setEnabled(false); + + button_debug.setBounds( + vec2x2_menu_game.x1_pos, + vec2x2_menu_game.y1_pos, + vec2x2_menu_game.x2_size, + vec2x2_menu_game.y2_size + ); + button_debug.addActionListener(this); + window_main.add(button_debug); + ArrMenu[EnumUIMenu.Debug.ordinal()] = button_debug; + break; + + case 2: + JLabel button_intentoss = new JLabel(arr_menu_game[num_game_menu]); + button_intentoss.setName(arr_menu_info[num_game_menu]); + if (debug) { + button_intentoss.setBackground(debug_game_menu); + } + button_intentoss.setBounds( + vec2x2_menu_game.x1_pos, + vec2x2_menu_game.y1_pos, + vec2x2_menu_game.x2_size, + vec2x2_menu_game.y2_size + ); + window_main.add(button_intentoss); + ArrMenu[EnumUIMenu.Intentos.ordinal()] = button_intentoss; + break; + + case 3: + JLabel label_ejambre_info = new JLabel(arr_menu_game[num_game_menu]); + label_ejambre_info.setName(arr_menu_info[num_game_menu]); + if (debug) {label_ejambre_info.setBackground(debug_game_menu);} + + label_ejambre_info.setBounds( + vec2x2_menu_game.x1_pos, + vec2x2_menu_game.y1_pos, + vec2x2_menu_game.x2_size, + vec2x2_menu_game.y2_size + ); + window_main.add(label_ejambre_info); + ArrMenu[EnumUIMenu.InfoEjambre.ordinal()] = label_ejambre_info; + break; + + case 4: + JButton button_inicio = new JButton(arr_menu_game[num_game_menu]); + button_inicio.setName(arr_menu_info[num_game_menu]); + if (debug) {button_inicio.setBackground(debug_game_menu);} + + button_inicio.setBounds( + vec2x2_menu_game.x1_pos, + vec2x2_menu_game.y1_pos, + vec2x2_menu_game.x2_size, + vec2x2_menu_game.y2_size + ); + button_inicio.addActionListener(this); + window_main.add(button_inicio); + ArrMenu[EnumUIMenu.Iniciar.ordinal()] = button_inicio; + break; + default: + break; + } + if (num_game_menu == arr_menu_game.length || num_game_menu == arr_menu_info.length) { + break; + } + } + + + window_main.setVisible(true); + } + + + // public void old_ejambre_move(EnumEjambreMove move) { + // // boolean berrk = false; + // // GameButton ejambre_button = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]); + + // // reset_point(); + // // set_point(); + + // // while (true) { + // // int next_ejambre = rnd.nextInt(156); + + // // if (next_ejambre == ejambre) { + // // continue; + // // } + + // // System.out.printf("Random Debug::::%d%n", next_ejambre); + + // // switch (move) { + // // case EnumEjambreMove.Norte: + // // break; + + // // case EnumEjambreMove.NorEste: + // // break; + + // // case EnumEjambreMove.Este: + // // break; + + // // case EnumEjambreMove.SurEste: + // // break; + + // // case EnumEjambreMove.Sur: + // // break; + + // // case EnumEjambreMove.SurOeste: + // // break; + + // // case EnumEjambreMove.Oeste: + // // for (Component cmp : window_main.getContentPane().getComponents()) { + // // if (cmp instanceof GameButton) { + // // GameButton field = (GameButton) cmp; + // // GameButton ejambre_button = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]); + + // // if ( + // // ejambre_button.x == 1 || + // // ejambre_button.x == 12 || + // // ejambre_button.y == 1 || + // // ejambre_button.y == 13 + // // ) { + // // berrk = true; + // // break; + // // } + + // // // if (ejambre_button.x == 12) + // // // && next_ejambre < ejambre_button + // // if ( + // // Integer.parseInt(field.getText()) == next_ejambre + // // && ejambre_button.x == field.x + // // && ejambre_button.y > field.y + // // ) { + // // ejambre = next_ejambre; + + // // reset_point(); + // // ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setText(String.valueOf(ejambre)); + // // berrk = true; + // // } + // // } + // // } + // // break; + + // // case EnumEjambreMove.NorOeste: + // // break; + + // // default: + // // break; + // // } + + // // if (berrk == true) { + // // berrk = false; + // // break; + // // } + + // // } + // } + + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + + + if (source instanceof GameButton) { + GameButton click_button = (GameButton) source; + + intentos_counter = intentos_counter + 1; + ((JLabel) ArrMenu[EnumUIMenu.Intentos.ordinal()]).setText(String.format("%d %s", intentos_counter, ":Intentos")); + + System.out.printf("%s:(x:%d,y:%d)%n", click_button.getText(), click_button.x, click_button.y); + + if (ejambre == Integer.parseInt(click_button.getText())) { + // ! Ganar + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format(" %s ", "Ganastes \\wuw/")); + + ((JButton) ArrMenu[EnumUIMenu.Iniciar.ordinal()]).setEnabled(true); + ((JButton) ArrMenu[EnumUIMenu.Debug.ordinal()]).setEnabled(false); + ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setVisible(false); + + set_purge_point(); + + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fiel = (GameButton) cmp; + fiel.setEnabled(false); + } + } + } + + + // click_button.x, click_button.y + // if (click_button.x == click_button.y) ( + + GameButton btn_ejambre = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]); + // System.out.printf("%d", click_button.x); + // System.out.printf("%d", btn_ejambre.x); + if ( + // Corre ejambre 1 + click_button.x == btn_ejambre.x && click_button.y == btn_ejambre.y + 1 || + // Corre ejambre 2 + click_button.x == btn_ejambre.x + 1 && click_button.y == btn_ejambre.y + 1 || + // Corre ejambre 3 + click_button.x == btn_ejambre.x + 1 && click_button.y == btn_ejambre.y || + // Corre ejambre 4 + click_button.x == btn_ejambre.x + 1 && click_button.y == btn_ejambre.y - 1 || + // Corre ejambre 5 + click_button.x == btn_ejambre.x && click_button.y == btn_ejambre.y - 1 || + // Corre ejambre 6 + click_button.x == btn_ejambre.x - 1 && click_button.y == btn_ejambre.y - 1 || + // Corre ejambre 7 + click_button.x == btn_ejambre.x - 1 && click_button.y == btn_ejambre.y || + // Corre ejambre 8 + click_button.x == btn_ejambre.x - 1 && click_button.y == btn_ejambre.y + 1 + + ) { + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Se escapo el ejambre T-T")); + // ! Corre ejambre + + set_new_enjambre_ubication(); + return; + } + + // * ! Sur =! Norte + if (click_button.x == btn_ejambre.x && click_button.y <= btn_ejambre.y - 2) { + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el Norte :EJambre")); + return; + } + + // * SurOeste != NorEste + if ( + click_button.x <= btn_ejambre.x - 2 && + click_button.y <= btn_ejambre.y - 2 || + click_button.x <= btn_ejambre.x - 2 && + click_button.y <= btn_ejambre.y - 1 || + click_button.x <= btn_ejambre.x - 1 && + click_button.y <= btn_ejambre.y - 2 + ) { + // System.out.printf("%n%d%n", btn_ejambre.x); + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el NorEste :EJambre")); + return; + } + + // * ! Oeste =! Este + if (click_button.x <= btn_ejambre.x - 2 && click_button.y == btn_ejambre.y) { + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el Este :EJambre")); + return; + } + + // * SurEste != NorOeste + if ( + click_button.x >= btn_ejambre.x + 2 && + click_button.y <= btn_ejambre.y - 2 || + + click_button.x <= btn_ejambre.x + 2 && + click_button.y <= btn_ejambre.y - 1 || + + click_button.x <= btn_ejambre.x + 1 && + click_button.y <= btn_ejambre.y - 2 + + // click_button.x >= btn_ejambre.x - 2 && click_button.y <= btn_ejambre.y - 2 + ) { + // System.out.printf("%n%d%n", btn_ejambre.x); + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el NorOeste :EJambre")); + return; + } + + // * ! Norte != Sur + if (click_button.x == btn_ejambre.x && click_button.y >= btn_ejambre.y + 2) { + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el Sur :EJambre")); + return; + } + + + // * ! NorEste != SurOeste + if ( + click_button.x >= btn_ejambre.x + 2 && + click_button.y >= btn_ejambre.y + 2 || + + click_button.x >= btn_ejambre.x + 2 && + click_button.y >= btn_ejambre.y + 1 || + + click_button.x >= btn_ejambre.x + 1 && + click_button.y >= btn_ejambre.y + 2 + + // click_button.x <= btn_ejambre.x - 2 && click_button.y >= btn_ejambre.y - 2 + ) { + // System.out.printf("%n%d%n", btn_ejambre.x); + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el SurOeste :EJambre")); + // ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Chacha :EJambre")); + return; + } + + // * ! Este != Oeste + if (click_button.x >= btn_ejambre.x + 2 && click_button.y == btn_ejambre.y) { + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el Oeste :EJambre")); + return; + } + + // * ! NorOeste != SurEste + if ( + click_button.x <= btn_ejambre.x - 2 && + click_button.y >= btn_ejambre.y + 2 || + + click_button.x <= btn_ejambre.x - 2 && + click_button.y >= btn_ejambre.y + 1 || + + click_button.x <= btn_ejambre.x - 1 && + click_button.y >= btn_ejambre.y + 2 + + // click_button.x >= btn_ejambre.x + 2 && click_button.y >= btn_ejambre.y + 2 + ) { + // System.out.printf("%n%d%n", btn_ejambre.x); + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Por el SurEste :EJambre")); + // ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format("Chacha :EJambre")); + return; + } + + + return; + } + + if (source instanceof JButton) { + JButton button_get = (JButton) source; + switch (button_get.getName()) { + case "Menu_Debug": + if (debug_game_inside == false) { + set_color_debug_true(); + break; + } + + if (debug_game_inside == true) { + set_color_debug_false(); + break; + } + + break; + case "Menu_Inicio": + + intentos_counter = 0; + + ((JLabel) ArrMenu[EnumUIMenu.Intentos.ordinal()]).setText(String.format(" %d %s ", intentos_counter, ":Intentos")); + + ((JLabel) ArrMenu[EnumUIMenu.InfoEjambre.ordinal()]).setText(String.format(" %s %s ", "None", ":Ejambre")); + + + ejambre = rnd.nextInt(156); + ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setText(String.valueOf(ejambre)); + ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setVisible(false); + + button_get.setEnabled(false); + debug_game_inside = false; + ((JButton) ArrMenu[EnumUIMenu.Debug.ordinal()]).setEnabled(true); + + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fiel = (GameButton) cmp; + if (ejambre == Integer.parseInt(fiel.getText())) { + // System.out.printf("Ejambre: %s:(x:%d,y:%d)%n", fiel.getText(), fiel.x, fiel.y); + // fiel.setBackground(Color.BLUE); + ArrEjambre[EnumEjambre.Ejambre.ordinal()] = fiel; + // break; + } + + fiel.setEnabled(true); + } + } + + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fields = (GameButton) cmp; + + int ejambre_x = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]).x; + int ejambre_y = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]).y; + + // Norte + if (fields.x == ejambre_x && fields.y == ejambre_y + 1) { + // fields.setBackground(Color.RED); + ArrEjambre[EnumEjambre.Norte.ordinal()] = fields; + continue; + } + // NorEste + if (fields.x == ejambre_x + 1 && fields.y == ejambre_y + 1) { + // fields.setBackground(Color.YELLOW); + ArrEjambre[EnumEjambre.NorEste.ordinal()] = fields; + continue; + } + // Este + if (fields.x == ejambre_x + 1 && fields.y == ejambre_y) { + // fields.setBackground(Color.GRAY); + ArrEjambre[EnumEjambre.Este.ordinal()] = fields; + continue; + } + // SurEste + if (fields.x == ejambre_x + 1 && fields.y == ejambre_y - 1) { + // fields.setBackground(Color.PINK); + ArrEjambre[EnumEjambre.SurEste.ordinal()] = fields; + continue; + } + // Sur + if (fields.x == ejambre_x && fields.y == ejambre_y - 1) { + // fields.setBackground(Color.ORANGE); + ArrEjambre[EnumEjambre.Sur.ordinal()] = fields; + continue; + } + // SurOeste + if (fields.x == ejambre_x - 1 && fields.y == ejambre_y - 1) { + // fields.setBackground(Color.MAGENTA); + ArrEjambre[EnumEjambre.SurOeste.ordinal()] = fields; + continue; + } + // Oeste + if (fields.x == ejambre_x - 1 && fields.y == ejambre_y) { + // fields.setBackground(Color.CYAN); + ArrEjambre[EnumEjambre.Oeste.ordinal()] = fields; + continue; + } + // Noroeste + if (fields.x == ejambre_x - 1 && fields.y == ejambre_y + 1) { + // fields.setBackground(new Color(190, 0, 190)); + ArrEjambre[EnumEjambre.NorOeste.ordinal()] = fields; + continue; + } + } + } + + // ArrMenu[EnumEjambre.Ejambre.ordinal()].setBackground(Color.Red) + // ArrMenu[EnumEjambre.Ejambre.ordinal()].setBackground(Color.YELLOW) + // fiel.getText(), fiel.x, fiel.y + // System.out.printf("Cerca EJembre: %s:(x:%d,y:%d)%n", fiel.getText(), fiel.x, fiel.y); + + // if (ejambre == Integer.parseInt(fiel.getText())) { + + // } + // fiel.setBackground(Color.RED); + + + break; + default: + break; + } + return; + } + + try { + if (source instanceof JTextField) { + System.out.printf("Debug 0%n"); + JTextField field = (JTextField) source; + + switch (field.getName()) { + case "Menu_Ejambre": + + if ( + Integer.parseInt(field.getText()) >= 156 || + Integer.parseInt(field.getText()) <= 0 + ) { + field.setText(String.format("Invalid num Ejambre = %d", ejambre)); + break; + } + + int new_number = Integer.parseInt(field.getText()); + // System.out.printf("11%n"); + System.out.printf("Debug 1%n"); + ejambre = new_number; + field.setText(String.format("Ejambre = %d", ejambre)); + + + + // reset_point(); + + // ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setVisible(false); + + // ! Set colors + set_purge_point(); + set_ejambre_points(); + set_reset_debug(); + // for (int h = 1; h <= arr_color.length; h = h + 1) { + // // System.out.printf("%d%n", h); + // if (((GameButton) ArrEjambre[h]) == null) { continue; } + // ((GameButton) ArrEjambre[h]).setBackground(arr_color[h - 1]); + // } + + break; + default: + break; + } + } + } catch (NumberFormatException ex) { + if (source instanceof JTextField) { + JTextField field = (JTextField) source; + + switch (field.getName()) { + case "Menu_Ejambre": + field.setText(String.format("%s: Ejambre = %d", "Invalid type!", ejambre)); + break; + default: + break; + } + return; + } + } + } + + public void set_point() { + // if (debug_game_inside == false) { + // ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setVisible(true); + + System.out.printf("%d%n", arr_color.length); + for (int h = 1; h <= arr_color.length; h = h + 1) { + System.out.printf("%d%n", h); + + if (((GameButton) ArrEjambre[h]) == null) { + continue; + } + ((GameButton) ArrEjambre[h]).setBackground(arr_color[h - 1]); + } + + // debug_game_inside = true; + // // break; + // } + } + + public void set_random_ejambre() { + ejambre = rnd.nextInt(156); + } + + public void set_purge_point() { + for (int h = 1; h <= arr_color.length; h = h + 1) { + if (((GameButton) ArrEjambre[h]) == null) {continue;} + ((GameButton) ArrEjambre[h]).setBackground(null); + ArrEjambre[h] = null; + } + + // debug_game_inside = false; + } + + public void set_label_ejambre() { + ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setText(String.format("%d", ejambre)); + } + + public void set_color_debug_true() { + if (debug_game_inside == false) { + ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setVisible(true); + for (int h = 1; h <= arr_color.length; h = h + 1) { + if (((GameButton) ArrEjambre[h]) == null) { continue; } + ((GameButton) ArrEjambre[h]).setBackground(arr_color[h - 1]); + } + debug_game_inside = true; + } + } + + public void set_color_debug_false() { + if (debug_game_inside == true) { + ((JTextField) ArrMenu[EnumUIMenu.EjambreUbication.ordinal()]).setVisible(false); + for (int h = 1; h <= arr_color.length; h = h + 1) { + if (((GameButton) ArrEjambre[h]) == null) { continue; } + ((GameButton) ArrEjambre[h]).setBackground(null); + } + debug_game_inside = false; + } + } + + public void set_reset_debug() { + if (debug_game_inside == true) { + for (int h = 1; h <= arr_color.length; h = h + 1) { + if (((GameButton) ArrEjambre[h]) == null) { continue; } + ((GameButton) ArrEjambre[h]).setBackground(arr_color[h - 1]); + } + } + } + + public void set_ejambre_points() { + // ! Get Ejambre + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fiel = (GameButton) cmp; + if (ejambre == Integer.parseInt(fiel.getText())) { + ArrEjambre[EnumEjambre.Ejambre.ordinal()] = fiel; + break; + } + } + } + + // ! Get positions adyacentes + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton field = (GameButton) cmp; + + int ejambre_x = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]).x; + int ejambre_y = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]).y; + + // Norte + if (field.x == ejambre_x && field.y == ejambre_y + 1) { + // field.setBackground(Color.RED); + ArrEjambre[EnumEjambre.Norte.ordinal()] = field; + continue; + } + // NorEste + if (field.x == ejambre_x + 1 && field.y == ejambre_y + 1) { + // field.setBackground(Color.YELLOW); + ArrEjambre[EnumEjambre.NorEste.ordinal()] = field; + continue; + } + // Este + if (field.x == ejambre_x + 1 && field.y == ejambre_y) { + // field.setBackground(Color.GRAY); + ArrEjambre[EnumEjambre.Este.ordinal()] = field; + continue; + } + // SurEste + if (field.x == ejambre_x + 1 && field.y == ejambre_y - 1) { + // field.setBackground(Color.PINK); + ArrEjambre[EnumEjambre.SurEste.ordinal()] = field; + continue; + } + // Sur + if (field.x == ejambre_x && field.y == ejambre_y - 1) { + // field.setBackground(Color.ORANGE); + ArrEjambre[EnumEjambre.Sur.ordinal()] = field; + continue; + } + // SurOeste + if (field.x == ejambre_x - 1 && field.y == ejambre_y - 1) { + // field.setBackground(Color.MAGENTA); + ArrEjambre[EnumEjambre.SurOeste.ordinal()] = field; + continue; + } + // Oeste + if (field.x == ejambre_x - 1 && field.y == ejambre_y) { + // field.setBackground(Color.CYAN); + ArrEjambre[EnumEjambre.Oeste.ordinal()] = field; + continue; + } + // Noroeste + if (field.x == ejambre_x - 1 && field.y == ejambre_y + 1) { + // field.setBackground(new Color(190, 0, 190)); + ArrEjambre[EnumEjambre.NorOeste.ordinal()] = field; + continue; + } + } + } + } + + public void set_new_enjambre_ubication() { + set_purge_point(); + set_random_ejambre(); + set_label_ejambre(); + // ! Purge Point + // for (int h = 1; h <= arr_color.length; h = h + 1) { + // System.out.printf("%d%n", h); + + // if (((GameButton) ArrEjambre[h]) == null) {continue;} + // ((GameButton) ArrEjambre[h]).setBackground(null); + // } + + // for (int h = 1; h <= arr_color.length; h = h + 1) { + // if (((GameButton) ArrEjambre[h]) == null) {continue;} + // ((GameButton) ArrEjambre[h]).setBackground(null); + // ArrEjambre[h] = null; + // } + + set_ejambre_points(); + + System.out.printf("Debu_game_inside:%b%n", debug_game_inside); + set_reset_debug(); + } + + public void reset_point() { + for (int h = 1; h <= arr_color.length; h = h + 1) { + System.out.printf("%d%n", h); + + if (((GameButton) ArrEjambre[h]) == null) { + continue; + } + ((GameButton) ArrEjambre[h]).setBackground(null); + } + + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fiel = (GameButton) cmp; + if (ejambre == Integer.parseInt(fiel.getText())) { + // System.out.printf("Ejambre: %s:(x:%d,y:%d)%n", fiel.getText(), fiel.x, fiel.y); + // fiel.setBackground(Color.BLUE); + ArrEjambre[EnumEjambre.Ejambre.ordinal()] = fiel; + break; + } + } + } + + for (Component cmp : window_main.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton field = (GameButton) cmp; + + int ejambre_x = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]).x; + int ejambre_y = ((GameButton) ArrEjambre[EnumEjambre.Ejambre.ordinal()]).y; + + // Norte + if (field.x == ejambre_x && field.y == ejambre_y + 1) { + // field.setBackground(Color.RED); + ArrEjambre[EnumEjambre.Norte.ordinal()] = field; + continue; + } + // NorEste + if (field.x == ejambre_x + 1 && field.y == ejambre_y + 1) { + // field.setBackground(Color.YELLOW); + ArrEjambre[EnumEjambre.NorEste.ordinal()] = field; + continue; + } + // Este + if (field.x == ejambre_x + 1 && field.y == ejambre_y) { + // field.setBackground(Color.GRAY); + ArrEjambre[EnumEjambre.Este.ordinal()] = field; + continue; + } + // SurEste + if (field.x == ejambre_x + 1 && field.y == ejambre_y - 1) { + // field.setBackground(Color.PINK); + ArrEjambre[EnumEjambre.SurEste.ordinal()] = field; + continue; + } + // Sur + if (field.x == ejambre_x && field.y == ejambre_y - 1) { + // field.setBackground(Color.ORANGE); + ArrEjambre[EnumEjambre.Sur.ordinal()] = field; + continue; + } + // SurOeste + if (field.x == ejambre_x - 1 && field.y == ejambre_y - 1) { + // field.setBackground(Color.MAGENTA); + ArrEjambre[EnumEjambre.SurOeste.ordinal()] = field; + continue; + } + // Oeste + if (field.x == ejambre_x - 1 && field.y == ejambre_y) { + // field.setBackground(Color.CYAN); + ArrEjambre[EnumEjambre.Oeste.ordinal()] = field; + continue; + } + // Noroeste + if (field.x == ejambre_x - 1 && field.y == ejambre_y + 1) { + // field.setBackground(new Color(190, 0, 190)); + ArrEjambre[EnumEjambre.NorOeste.ordinal()] = field; + continue; + } + } + } + } +} \ No newline at end of file diff --git a/project/enjambre_de_langosta/src/com/mod/utils/GameButton.java b/project/enjambre_de_langosta/src/com/mod/utils/GameButton.java new file mode 100755 index 0000000..1163642 --- /dev/null +++ b/project/enjambre_de_langosta/src/com/mod/utils/GameButton.java @@ -0,0 +1,8 @@ +package mod.utils; + +import javax.swing.*; +import java.awt.event.*; + +public class GameButton extends JButton { + public int x, y; +} \ No newline at end of file diff --git a/project/enjambre_de_langosta/src/com/mod/utils/Vec2x2.java b/project/enjambre_de_langosta/src/com/mod/utils/Vec2x2.java new file mode 100755 index 0000000..7936128 --- /dev/null +++ b/project/enjambre_de_langosta/src/com/mod/utils/Vec2x2.java @@ -0,0 +1,27 @@ +package mod.utils; + +public class Vec2x2 { + // Position + public int x1_pos; + public int y1_pos; + + // Size + public int x2_size; + public int y2_size; + + + public Vec2x2() { + this.x1_pos = 0; + this.y1_pos = 0; + this.x2_size = 0; + this.y2_size = 0; + } + + public Vec2x2(int x1, int y1, int x2, int y2) { + this.x1_pos = x1; + this.y1_pos = y1; + this.x2_size = x2; + this.y2_size = y2; + } + +} \ No newline at end of file diff --git a/project/juego_de_adivinanza_de_numeros/Main.java b/project/juego_de_adivinanza_de_numeros/Main.java new file mode 100755 index 0000000..787b380 --- /dev/null +++ b/project/juego_de_adivinanza_de_numeros/Main.java @@ -0,0 +1,66 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Random; + +public class Main { + public static void main(String[] args) { + InputStreamReader inputStreamReader = new InputStreamReader(System.in); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + Random random = new Random(); + + try { + System.out.printf("Ingrese el numero maximo del juego [Adivina el numero]: "); + String inputDelUsuario = bufferedReader.readLine(); + int inputDelUsuarioToInt = Integer.parseInt(inputDelUsuario); + System.out.printf("%n"); + + + int numeroRandom = random.nextInt(inputDelUsuarioToInt) + 1; + Adivina adivina = new Adivina(numeroRandom); + adivina.jugar(); + } catch (IOException e) { + System.out.println("Ocurrio un error de entrada/salida:" + e.getMessage()); + return; + } catch (NumberFormatException e) { + System.out.println("Por favor, ingresa solo numeros validos."); + return; + } + } +} + + +class Adivina { + int index; + Adivina(int index) { + this.index = index; + } + + public void jugar() { + InputStreamReader inputStreamReader = new InputStreamReader(System.in); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + + try { + while (true) { + System.out.printf("Adivina el numero: "); + String inputDelUsuario = bufferedReader.readLine(); + int inputDelUsuarioToInt = Integer.parseInt(inputDelUsuario); + + if (inputDelUsuarioToInt == index) { + System.out.printf("Felicidades acertastes el numero es => [%d]%n", inputDelUsuarioToInt); + break; + } + if (inputDelUsuarioToInt < index) { + System.out.printf("Incorrecto [%d] es menor.%n%n", inputDelUsuarioToInt); + continue; + } + if (inputDelUsuarioToInt > index) { + System.out.printf("Incorrecto [%d] es mayor.%n%n", inputDelUsuarioToInt); + continue; + } + } + } catch (IOException e) { + System.out.println("Ocurrio un error de entrada/salida:" + e.getMessage()); + } finally {} + } +} \ No newline at end of file diff --git a/project/juego_de_adivinanza_de_numeros/makefile b/project/juego_de_adivinanza_de_numeros/makefile new file mode 100755 index 0000000..a958afd --- /dev/null +++ b/project/juego_de_adivinanza_de_numeros/makefile @@ -0,0 +1,3 @@ +all: + javac Main.java + java Main \ No newline at end of file diff --git a/project/rompecabeza/META-INF/MANIFEST.MF b/project/rompecabeza/META-INF/MANIFEST.MF new file mode 100644 index 0000000..31ee422 --- /dev/null +++ b/project/rompecabeza/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.src.Proy2 +Created-By: tuzikuz diff --git a/project/rompecabeza/META-INF/manifest.txt b/project/rompecabeza/META-INF/manifest.txt new file mode 100644 index 0000000..31ee422 --- /dev/null +++ b/project/rompecabeza/META-INF/manifest.txt @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.src.Proy2 +Created-By: tuzikuz diff --git a/project/rompecabeza/Makefile b/project/rompecabeza/Makefile new file mode 100755 index 0000000..499385b --- /dev/null +++ b/project/rompecabeza/Makefile @@ -0,0 +1,15 @@ +MAIN_CLASS = Proy2 + +all: + mkdir -p out + javac -d out $(shell find src -name "*.java") + cat META-INF/manifest.txt > META-INF/MANIFEST.MF + jar cfm build/$(MAIN_CLASS).jar META-INF/MANIFEST.MF -C out . + rm -rf ./out + cd build && java -jar $(MAIN_CLASS).jar + +purge_windows: + powershell -Command "Get-ChildItem -Recurse -Include *.class,*.log,*.tmp,*~ | Remove-Item -Force" + +purge_linux: + find . -name "*.class" -type f -delete \ No newline at end of file diff --git a/project/rompecabeza/README.md b/project/rompecabeza/README.md new file mode 100644 index 0000000..017dcf6 --- /dev/null +++ b/project/rompecabeza/README.md @@ -0,0 +1,17 @@ +# Rompecabeza Proy 2 v1.0 + +## Como compilar el programa (Java) (Linux) + +### Requerimientos +- Java 17 ([adoptium](https://adoptium.net)) +- shell + + +### Comandos + +#### Make (LInux) +```shell + +make + +``` \ No newline at end of file diff --git a/project/rompecabeza/build/Proy2.jar b/project/rompecabeza/build/Proy2.jar new file mode 100644 index 0000000..c595ded Binary files /dev/null and b/project/rompecabeza/build/Proy2.jar differ diff --git a/project/rompecabeza/build/storage/data.ini b/project/rompecabeza/build/storage/data.ini new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/project/rompecabeza/build/storage/data.ini @@ -0,0 +1 @@ + diff --git a/project/rompecabeza/src/com/Proy2.java b/project/rompecabeza/src/com/Proy2.java new file mode 100755 index 0000000..6cf345c --- /dev/null +++ b/project/rompecabeza/src/com/Proy2.java @@ -0,0 +1,12 @@ +package com.src; + +import mod.Init; + +public class Proy2 { + public static void main(String[] args) { + System.out.printf("Proy2 %n"); + Init game = new Init(); + game.start(); + } +} + diff --git a/project/rompecabeza/src/com/mod/Init.java b/project/rompecabeza/src/com/mod/Init.java new file mode 100644 index 0000000..477e6d5 --- /dev/null +++ b/project/rompecabeza/src/com/mod/Init.java @@ -0,0 +1,849 @@ +package mod; + +import mod.util.Vec2x2; +import mod.util.UserData; +import mod.util.GameButton; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.JScrollPane; +import javax.swing.DefaultListModel; +import javax.swing.border.EmptyBorder; +import javax.swing.ListSelectionModel; +import javax.swing.Timer; +import javax.swing.JTextField; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.Color; +import java.awt.Font; +import java.awt.Component; + +import java.util.Random; +import java.util.Vector; +import java.util.Scanner; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.File; + +public class Init extends JFrame implements ActionListener { + private boolean DEBUG_CONSOLE = true; + + private UserData my_user_data = new UserData(); + + private Random rnd = new Random(); + + private String[] menu_info; + + private boolean puntuacion = false; + + private JTextField user_name; + + private int puzzle_buttons_num = 16; + private Vector puzzle_buttons_vec = new Vector<>(); + + private JLabel move_show; + + + private boolean ganastes = false; + + private boolean quick_fix_debug_start = false; + + private String[] menu_game; + private Vector menu_game_buttons = new Vector<>(); + enum EnumMenuGame { + Iniciar, + Reiniciar, + Puntuacion, + IniciarDebug, + } + + private JScrollPane scroll_pane; + + private String[] menu_board; + private DefaultListModel list_default_model; + + private boolean debug_program = false; + private boolean debug_game = true; + + private JLabel crono_show; + + private Vector user_data_Vec = new Vector<>(); + private int crono = 0; + private Timer timer_crono = new Timer(1000, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + crono = crono + 1; + crono_show.setText(String.format("Timer: %d", crono)); + } + }); + + private int anim_btn_vec_pos = 0; + private GameButton btn_movimiento_tmp; + private Timer timer_move_anim = new Timer(15, new ActionListener() + { + public void actionPerformed(ActionEvent e) { + boton_en_movimiento = true; + + int btn_sisi_location_x = btn_movimiento_tmp.getLocation().x; + int btn_sisi_location_y = btn_movimiento_tmp.getLocation().y; + + // if (DEBUG_CONSOLE) { + // System.out.printf("Anim X:%d Y:%d%n", btn_movimiento_tmp.x_anim, btn_movimiento_tmp.y_anim); + // System.out.printf("Loop X:%d Y:%d%n", btn_sisi_location_x, btn_sisi_location_y); + // } + + + if ( + btn_sisi_location_x == btn_movimiento_tmp.x_anim + && + btn_sisi_location_y == btn_movimiento_tmp.y_anim + ) { + boton_en_movimiento = false; + timer_move_anim.stop(); + System.out.printf("Stop timer%n"); + ganastes(); + return; + } + + + if (btn_sisi_location_x > btn_movimiento_tmp.x_anim) { + btn_movimiento_tmp.setLocation(btn_sisi_location_x - 1, btn_sisi_location_y); + return; + } + + if (btn_sisi_location_x < btn_movimiento_tmp.x_anim) { + btn_movimiento_tmp.setLocation(btn_sisi_location_x + 1, btn_sisi_location_y); + return; + } + + if (btn_sisi_location_y > btn_movimiento_tmp.y_anim) { + btn_movimiento_tmp.setLocation(btn_sisi_location_x, btn_sisi_location_y - 1); + return; + } + + if (btn_sisi_location_y < btn_movimiento_tmp.y_anim) { + btn_movimiento_tmp.setLocation(btn_sisi_location_x, btn_sisi_location_y + 1); + return; + } + } + }); + + private int button_num_clicked; + private boolean boton_en_movimiento = false; + private Timer mover_boton = new Timer(100, new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + boton_en_movimiento = true; + + int puzz_x = puzzle_buttons_vec.get(button_num_clicked).getLocation().x; + int puzz_y = puzzle_buttons_vec.get(button_num_clicked).getLocation().y; + + puzzle_buttons_vec.get(button_num_clicked).setLocation(puzz_x + 1, puzz_y + 1); + } + }); + + + public Init() { + this.setTitle("Proy2 "); + this.setLayout(null); + this.setVisible(true); + this.setBounds( + 0, + 0, + 1000, + 900 + ); + if (debug_program) { + this.getContentPane().setBackground(Color.WHITE); + } + this.setExtendedState(JFrame.MAXIMIZED_BOTH); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + menu_info = new String[] { + String.format(" %45s ", "Universidad Facultad"), + String.format(" %45s ", " Facultad de Ingeniería de Sistemas Computacionales"), + + String.format(" %45s ", "Carrera"), + String.format(" %45s ", " Licenciatura en Desarrollo y Gestión de Software"), + + String.format(" %45s ", "Materia"), + String.format(" %45s ", "Desarrollo de Software 3"), + + String.format(" %45s ", "Profesor"), + String.format(" %45s ", "Ricardo Chan"), + + String.format(" %45s ", "Estudiante Cedula"), + String.format(" %45s ", "0-000-0000"), + + String.format(" %45s ", "Grupo" ), + String.format(" %45s ", "Tuzikuz"), + + String.format(" %45s ", "Fecha"), + String.format(" %45s ", "????"), + }; + + + menu_game = new String[] { + String.format("Iniciar"), + String.format("Reiniciar"), + String.format("Puntuacion"), + String.format("Iniciar Debug") + }; + + menu_board = new String[] { + "Tabla", + "" + }; + } + + public void start() { + // ? ============== Menu Info + Vec2x2 vec2x2_menu_info = new Vec2x2(); + vec2x2_menu_info.x1_pos = 10; + vec2x2_menu_info.y1_pos = 25; + vec2x2_menu_info.x2_size = 355; + vec2x2_menu_info.y2_size = 30; + for (int index = 0; index < menu_info.length; index = index + 1 ) { + JLabel label_menu_info = new JLabel(menu_info[index]); + label_menu_info.setFont(new Font("Arial", Font.PLAIN, 12)); + + + if (debug_program) { + label_menu_info.setOpaque(true); + label_menu_info.setBackground(Color.RED); + } + + + if (index % 2 == 0) { + int index_pos = 30 + index * 40; + label_menu_info.setBounds( + vec2x2_menu_info.x1_pos, + vec2x2_menu_info.y1_pos + index_pos, + vec2x2_menu_info.x2_size, + vec2x2_menu_info.y2_size + ); + } else { + int index_pos = 30 + index * 40; + label_menu_info.setBounds( + vec2x2_menu_info.x1_pos, + vec2x2_menu_info.y1_pos + index_pos - 20, + vec2x2_menu_info.x2_size, + vec2x2_menu_info.y2_size + ); + } + + this.add(label_menu_info); + } + + + // ? ============== Puzzle + Vec2x2 vec2x2_puzzle = new Vec2x2(); + vec2x2_puzzle.x1_pos = 425; + vec2x2_puzzle.y1_pos = 50; + vec2x2_puzzle.x2_size = 0; + vec2x2_puzzle.y2_size = 0; + + for(int index = 0; index < puzzle_buttons_num; index = index + 1) { + GameButton button = new GameButton(); + button.setEnabled(true); + button.setText(String.valueOf(index + 1)); + button.setBounds( + vec2x2_puzzle.x1_pos+63*(index%4), + vec2x2_puzzle.y1_pos+45*(index/4), + 60, + 45 + ); + + button.setFont(new Font("Arial", Font.PLAIN, 16)); + button.addActionListener(this); + button.setEnabled(false); + this.add(button); + puzzle_buttons_vec.add(button); + } + + puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1).setVisible(false); + + int button_num_x = 0; + int button_num_y = 1; + for (Component cmp : this.getContentPane().getComponents()) { + if (cmp instanceof GameButton) { + GameButton fiel = (GameButton) cmp; + button_num_x = button_num_x + 1; + + fiel.x = button_num_x; + fiel.y = button_num_y; + + if (button_num_x == 4) { + button_num_y = button_num_y + 1; + button_num_x = 0; + } + } + } + + + // ? ============== Menu Game + Vec2x2 vec2x2_menu_game = new Vec2x2(); + vec2x2_menu_game.x1_pos = 730; + vec2x2_menu_game.y1_pos = 50; + vec2x2_menu_game.x2_size = 170; + vec2x2_menu_game.y2_size = 50; + + + for (int index = 0; index < menu_game.length; index = index + 1 ) { + JButton button = new JButton(); + button.setEnabled(true); + button.setText(menu_game[index]); + + + button.setFont(new Font("Arial", Font.PLAIN, 12)); + button.addActionListener(this); + + button.setBounds( + vec2x2_menu_game.x1_pos, + vec2x2_menu_game.y1_pos, + vec2x2_menu_game.x2_size, + vec2x2_menu_game.y2_size + ); + vec2x2_menu_game.y1_pos = vec2x2_menu_game.y1_pos + 60; + + this.add(button); + menu_game_buttons.add(button); + } + + + user_name = new JTextField("\"Introduce tu nombre\""); + user_name.setBounds( + 405, + 300, + 310, + 50 + ); + + this.add(user_name); + + + + + + // ? ============== Board + Vec2x2 vec2x2_board = new Vec2x2(); + vec2x2_board.x1_pos = 700; + vec2x2_board.y1_pos = 50; + vec2x2_board.x2_size = 170; + vec2x2_board.y2_size = 50; + + + + list_default_model = new DefaultListModel(); + JList list = new JList<>(list_default_model); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setBorder(BorderFactory.createTitledBorder("Score")); + + scroll_pane = new JScrollPane(list); + scroll_pane.setBounds(950,40,400,500); + + scroll_pane.setVisible(false); + this.add(scroll_pane); + + menu_game_buttons.get(EnumMenuGame.Reiniciar.ordinal()).setEnabled(false); + + + + Vec2x2 vec2x2_crono = new Vec2x2(); + vec2x2_crono.x1_pos = 510; + vec2x2_crono.y1_pos = 250; + vec2x2_crono.x2_size = 170; + vec2x2_crono.y2_size = 50; + + move_show = new JLabel("Movimientos: 0"); + move_show.setBounds( + vec2x2_crono.x1_pos -100, + vec2x2_crono.y1_pos, + vec2x2_crono.x2_size, + vec2x2_crono.y2_size + ); + this.add(move_show); + + crono_show = new JLabel("Timer: 0"); + crono_show.setBounds( + vec2x2_crono.x1_pos +100, + vec2x2_crono.y1_pos, + vec2x2_crono.x2_size, + vec2x2_crono.y2_size + ); + this.add(crono_show); + this.repaint(); + } + + public void file_read_scanner(String path_file) { + File file = new File(path_file); + + try { + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + // System.out.println(this.user_data_Vec); + UserData user_data = new UserData(); + user_data.name = scanner.nextLine(); + user_data.crono = Integer.parseInt(scanner.nextLine()); + user_data.movimientos = Integer.parseInt(scanner.nextLine()); + + this.user_data_Vec.add(user_data); + } + } + catch (Exception e) { + System.out.printf("Err read scanner: "); + System.out.println(e.toString()); + } + } + + + public void bubble_sort_list(Vector user_data) { + // %-5s | %-15s | %-17s | %11s + this.list_default_model.addElement(String.format("[%s, %s, %s]", "Nombre", "Segundos", "Movimiento")); + + for(int x = 0; x < user_data.size() - 1; x = x + 1) { + for (int y = 0; y < user_data.size() - x - 1; y = y + 1) { + if (user_data.get(y).crono > user_data.get(y + 1).crono) { + UserData tmp = user_data.get(y); + + user_data.set(y, user_data.get(y + 1)); + user_data.set(y + 1, tmp); + } + } + } + + int limit = 6; + while(user_data.size() >= limit) { + user_data.remove(user_data.size() - 1); + } + + + for(UserData data : user_data) { + this.list_default_model.addElement(String.format("[%s, %s, %s]", data.name, String.valueOf(data.crono), String.valueOf(data.movimientos))); + } + + } + + + public void desorden() { + for (int z = 0; z < puzzle_buttons_vec.size() - 1; z = z + 1) { + int random_number = rnd.nextInt(14) + 1; + + GameButton tmp = puzzle_buttons_vec.get(z); + int tmp_x = tmp.getLocation().x; + int tmp_y = tmp.getLocation().y; + int tmp_x_grid = tmp.x; + int tmp_y_grid = tmp.y; + + GameButton tmp_random = puzzle_buttons_vec.get(random_number); + int tmp_random_x = tmp_random.getLocation().x; + int tmp_random_y = tmp_random.getLocation().y; + int tmp_random_x_grid = tmp_random.x; + int tmp_random_y_grid = tmp_random.y; + + + tmp.setLocation(tmp_random_x, tmp_random_y); + tmp.x = tmp_random_x_grid; + tmp.y = tmp_random_y_grid; + + tmp_random.setLocation(tmp_x, tmp_y); + tmp_random.x = tmp_x_grid; + tmp_random.y = tmp_y_grid; + + puzzle_buttons_vec.set(z, tmp_random); + puzzle_buttons_vec.set(random_number, tmp); + // JButton button_get_z = puzzle_buttons_vec.get(z); + //int button_get_z_x = button_get_z.getLocation().x; + //int button_get_z_y = button_get_z.getLocation().y; + + //JButton button_random = + //int button_random_x = button_random.getLocation().x; + //int button_random_y = button_random.getLocation().y; + + //button_get_z.setLocation(,); + //button_random.setLocation(,); + + //puzzle_buttons_vec.set(random_number, button_random); + + // System.out.printf("%d%n", random_number); + // System.out.println(puzzle_buttons_vec); + } + } + + public void purge_list() { + list_default_model.clear(); + user_data_Vec = new Vector<>(); + } + + + public void ganastes() { + int puzz_index = 0; + for (JButton puzz_but : puzzle_buttons_vec) { + puzz_index = puzz_index + 1; + + if (Integer.parseInt(puzz_but.getText()) == puzz_index) { + if (puzz_index == puzzle_buttons_vec.size()) { + ganastes = true; + break; + } + continue; + } + + break; + } + + if (ganastes) { + try { + + this.my_user_data.crono = crono; + FileWriter file_writer = new FileWriter("storage/data.ini", true); // true=append, false=overwrite + // file_writer.write(String.format("%n")); + file_writer.write(String.format("%s%n", this.my_user_data.name)); + file_writer.write(String.format("%d%n", this.my_user_data.crono)); + file_writer.write(String.format("%d%n", this.my_user_data.movimientos)); + file_writer.close(); + ganastes = false; + System.out.printf("%nGANASTES%n"); + + crono_show.setText(String.format("Timer: %d", crono)); + move_show.setText(String.format("Movimientos: %d", this.my_user_data.movimientos)); + this.my_user_data.movimientos = 0; + + restart(); + + user_name.setText("\"Ganastes\""); + + + } catch(Exception e) { + System.out.println("error grabar " + e.toString()); + } + + } + } + + public void bubble_puzzle() { + + for (JButton puzzle_buttons : puzzle_buttons_vec) { + puzzle_buttons.setEnabled(false); + puzzle_buttons.setVisible(true); + } + + for(int x = 0; x < puzzle_buttons_vec.size() - 1; x = x + 1) { + for (int y = 0; y < puzzle_buttons_vec.size() - x - 1; y = y + 1) { + int puzz_num_1 = Integer.parseInt(puzzle_buttons_vec.get(y).getText()); + int puzz_num_2 = Integer.parseInt(puzzle_buttons_vec.get(y + 1).getText()); + if ( puzz_num_1 > puzz_num_2 ) { + // System.out.println(puzzle_buttons_vec.get(y).getText()); + + GameButton tmp = puzzle_buttons_vec.get(y); + int tmp_x = tmp.getLocation().x; + int tmp_y = tmp.getLocation().y; + int tmp_x_grid = tmp.x; + int tmp_y_grid = tmp.y; + + GameButton tmp_random = puzzle_buttons_vec.get(y + 1); + int tmp_random_x = tmp_random.getLocation().x; + int tmp_random_y = tmp_random.getLocation().y; + int tmp_random_x_grid = tmp_random.x; + int tmp_random_y_grid = tmp_random.y; + // tmp_random.setEnabled(false); + + + tmp.x = tmp_random_x_grid; + tmp.y = tmp_random_y_grid; + tmp_random.x = tmp_x_grid; + tmp_random.y = tmp_y_grid; + + tmp.setLocation(tmp_random_x, tmp_random_y); + tmp_random.setLocation(tmp_x, tmp_y); + + puzzle_buttons_vec.set(y, tmp_random); + puzzle_buttons_vec.set(y + 1, tmp); + + } + } + } + + puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1).setEnabled(false); + puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1).setVisible(false); + } + + public void actionPerformed(ActionEvent e) { + if (boton_en_movimiento) { + return; + } + + if (ganastes) { + ganastes = false; + return; + } + + if (e.getSource() == menu_game_buttons.get(EnumMenuGame.Puntuacion.ordinal())) { + purge_list(); + file_read_scanner("storage/data.ini"); + this.bubble_sort_list(this.user_data_Vec); + + if (puntuacion == false) { + scroll_pane.setVisible(true); + puntuacion = true; + } else { + scroll_pane.setVisible(false); + puntuacion = false; + } + return; + } + + if (e.getSource() == menu_game_buttons.get(EnumMenuGame.IniciarDebug.ordinal())) { + if (user_name.getText().equals("\"Introduce tu nombre\"") + || + user_name.getText().equals("\"Ganastes\"") + || + user_name.getText().equals("\"(Elimina todo el texto he introduce tu nombre)\"") + ) { + user_name.setText("\"(Elimina todo el texto he introduce tu nombre)\""); + return; + } + + menu_game_buttons.get(EnumMenuGame.IniciarDebug.ordinal()).setEnabled(false); + menu_game_buttons.get(EnumMenuGame.Iniciar.ordinal()).setEnabled(false); + menu_game_buttons.get(EnumMenuGame.Reiniciar.ordinal()).setEnabled(true); + + user_name.setEnabled(false); + crono = 0; + crono_show.setText(String.format("Timer: %d", crono)); + this.my_user_data.movimientos = 0; + move_show.setText(String.format("Movimientos: %d", this.my_user_data.movimientos)); + timer_crono.start(); + + this.my_user_data.name = user_name.getText(); + + for (JButton puzzle_button : puzzle_buttons_vec) { + puzzle_button.setEnabled(true); + } + puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1).setEnabled(false); + + + + GameButton tmp_nono_btn = puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1); + int tmp_nono_btn_x = tmp_nono_btn.getLocation().x; + int tmp_nono_btn_y = tmp_nono_btn.getLocation().y; + int tmp_nono_btn_x_grid = tmp_nono_btn.x; + int tmp_nono_btn_y_grid = tmp_nono_btn.y; + + + GameButton tmp_btn = puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 2); + int tmp_btn_x = tmp_btn.getLocation().x; + int tmp_btn_y = tmp_btn.getLocation().y; + int tmp_btn_x_grid = tmp_btn.x; + int tmp_btn_y_grid = tmp_btn.y; + + + tmp_nono_btn.setLocation(tmp_btn_x, tmp_btn_y); + tmp_nono_btn.x = tmp_btn_x_grid; + tmp_nono_btn.y = tmp_btn_y_grid; + + tmp_btn.setLocation(tmp_nono_btn_x, tmp_nono_btn_y); + tmp_btn.x = tmp_nono_btn_x_grid; + tmp_btn.y = tmp_nono_btn_y_grid; + + puzzle_buttons_vec.set(puzzle_buttons_vec.size() - 2, tmp_nono_btn); + puzzle_buttons_vec.set(puzzle_buttons_vec.size() - 1, tmp_btn); + return; + } + + if (e.getSource() == menu_game_buttons.get(EnumMenuGame.Reiniciar.ordinal())) { + restart(); + + return; + } + + + + if (e.getSource() == menu_game_buttons.get(EnumMenuGame.Iniciar.ordinal())) { + if (user_name.getText().equals("\"Introduce tu nombre\"") + || + user_name.getText().equals("\"Ganastes\"") + || + user_name.getText().equals("\"(Elimina todo el texto he introduce tu nombre)\"") + ) { + user_name.setText("\"(Elimina todo el texto he introduce tu nombre)\""); + return; + } + + menu_game_buttons.get(EnumMenuGame.Reiniciar.ordinal()).setEnabled(true); + menu_game_buttons.get(EnumMenuGame.Iniciar.ordinal()).setEnabled(false); + menu_game_buttons.get(EnumMenuGame.IniciarDebug.ordinal()).setEnabled(false); + + + this.my_user_data.name = user_name.getText(); + crono = 0; + crono_show.setText(String.format("Timer: %d", crono)); + timer_crono.start(); + + this.desorden(); + + + for (JButton puzzle_button : puzzle_buttons_vec) { + puzzle_button.setEnabled(true); + puzzle_button.setVisible(true); + } + + puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1).setEnabled(false); + puzzle_buttons_vec.get(puzzle_buttons_vec.size() - 1).setVisible(false); + + user_name.setEnabled(false); + + return; + } + + if (e.getSource() instanceof GameButton) { + // ! Cast + GameButton cmp_button = (GameButton) e.getSource(); + + GameButton puzz_sisi_btn = new GameButton(); + GameButton puzz_nono_btn = new GameButton(); + int puzz_vec_pos = 0; + + boolean in_loop = true; + for (GameButton puzzle : puzzle_buttons_vec) { + if (cmp_button == puzzle) { + puzz_sisi_btn = puzzle; + puzz_sisi_btn.vec_pos = puzz_vec_pos; + puzz_vec_pos = 0; + in_loop = false; + break; + } + puzz_vec_pos = puzz_vec_pos + 1; + } + + if (in_loop) { + return; + } + + for (GameButton puzzle_nono_btn : puzzle_buttons_vec) { + if (puzzle_nono_btn.isEnabled() == false) { + puzz_nono_btn = puzzle_nono_btn; + puzz_nono_btn.vec_pos = puzz_vec_pos; + puzz_vec_pos = 0; + break; + } + puzz_vec_pos = puzz_vec_pos + 1; + } + + System.out.printf( + "Puzzz: Name:%s X:%d Y:%d %n", + puzz_sisi_btn.getText(), + puzz_sisi_btn.x, + puzz_sisi_btn.y); + + System.out.printf( + "Puzzz Nono: Name:%s X:%d Y:%d %n", + puzz_nono_btn.getText(), + puzz_nono_btn.x, + puzz_nono_btn.y); + + + if ( + puzz_sisi_btn.x == puzz_nono_btn.x + && + puzz_sisi_btn.y + 1 == puzz_nono_btn.y + + || + + puzz_sisi_btn.x + 1 == puzz_nono_btn.x + && + puzz_sisi_btn.y == puzz_nono_btn.y + + || + + puzz_sisi_btn.x == puzz_nono_btn.x + && + puzz_sisi_btn.y - 1 == puzz_nono_btn.y + + || + + puzz_sisi_btn.x - 1 == puzz_nono_btn.x + && + puzz_sisi_btn.y == puzz_nono_btn.y + ) { + System.out.printf("Valid click btn%n"); + mover(puzz_sisi_btn, puzz_nono_btn); + return; + } + } + + } + + + + public void mover(GameButton sisi, GameButton nono) { + System.out.printf("Mover%n"); + this.my_user_data.movimientos = this.my_user_data.movimientos + 1; + move_show.setText(String.format("Movimientos: %d", this.my_user_data.movimientos)); + + anim_btn_vec_pos = nono.vec_pos; + + System.out.printf("Debug pos sisi: %d nono %d%n", sisi.vec_pos, nono.vec_pos); + GameButton tmp_btn_sisi = puzzle_buttons_vec.get(sisi.vec_pos); + int tmp_btn_sisi_x = tmp_btn_sisi.getLocation().x; + int tmp_btn_sisi_y = tmp_btn_sisi.getLocation().y; + int tmp_btn_sisi_x_grid = tmp_btn_sisi.x; + int tmp_btn_sisi_y_grid = tmp_btn_sisi.y; + + + GameButton tmp_btn_nono = puzzle_buttons_vec.get(nono.vec_pos); + int tmp_btn_nono_x = tmp_btn_nono.getLocation().x; + int tmp_btn_nono_y = tmp_btn_nono.getLocation().y; + int tmp_btn_nono_x_grid = tmp_btn_nono.x; + int tmp_btn_nono_y_grid = tmp_btn_nono.y; + + + // tmp_sisi.setLocation(tmp_nono_x, tmp_nono_y); + tmp_btn_sisi.x = tmp_btn_nono_x_grid; + tmp_btn_sisi.y = tmp_btn_nono_y_grid; + tmp_btn_sisi.x_anim = tmp_btn_nono_x; + tmp_btn_sisi.y_anim = tmp_btn_nono_y; + + tmp_btn_nono.setLocation(tmp_btn_sisi_x, tmp_btn_sisi_y); + tmp_btn_nono.x = tmp_btn_sisi_x_grid; + tmp_btn_nono.y = tmp_btn_sisi_y_grid; + + + puzzle_buttons_vec.set(sisi.vec_pos, tmp_btn_nono); + puzzle_buttons_vec.set(nono.vec_pos, tmp_btn_sisi); + + btn_movimiento_tmp = puzzle_buttons_vec.get(anim_btn_vec_pos); + timer_move_anim.start(); + } + + public void restart() { + menu_game_buttons.get(EnumMenuGame.Reiniciar.ordinal()).setEnabled(false); + menu_game_buttons.get(EnumMenuGame.IniciarDebug.ordinal()).setEnabled(true); + menu_game_buttons.get(EnumMenuGame.Iniciar.ordinal()).setEnabled(true); + + user_name.setText("\"Introduce tu nombre\""); + + timer_crono.stop(); + user_name.setEnabled(true); + crono = 0; + this.my_user_data.movimientos = 0; + + crono_show.setText(String.format("Timer: %d", crono)); + move_show.setText(String.format("Movimientos: %d", this.my_user_data.movimientos)); + this.bubble_puzzle(); + + this.purge_list(); + file_read_scanner("storage/data.ini"); + this.bubble_sort_list(this.user_data_Vec); + } +} \ No newline at end of file diff --git a/project/rompecabeza/src/com/mod/util/GameButton.java b/project/rompecabeza/src/com/mod/util/GameButton.java new file mode 100755 index 0000000..e084314 --- /dev/null +++ b/project/rompecabeza/src/com/mod/util/GameButton.java @@ -0,0 +1,11 @@ +package mod.util; + +import javax.swing.*; +import java.awt.event.*; + +public class GameButton extends JButton { + public int x, y; + public int vec_pos; + public int x_anim; + public int y_anim; +} \ No newline at end of file diff --git a/project/rompecabeza/src/com/mod/util/UserData.java b/project/rompecabeza/src/com/mod/util/UserData.java new file mode 100644 index 0000000..b265eff --- /dev/null +++ b/project/rompecabeza/src/com/mod/util/UserData.java @@ -0,0 +1,7 @@ +package mod.util; + +public class UserData { + public String name; + public int crono; + public int movimientos; +} \ No newline at end of file diff --git a/project/rompecabeza/src/com/mod/util/Vec2D.java b/project/rompecabeza/src/com/mod/util/Vec2D.java new file mode 100644 index 0000000..ff197db --- /dev/null +++ b/project/rompecabeza/src/com/mod/util/Vec2D.java @@ -0,0 +1,11 @@ +package mod.util; + +public class Vec2D { + public int x; + public int y; + + public Vec2D() { + this.x = 0; + this.y = 0; + } +} \ No newline at end of file diff --git a/project/rompecabeza/src/com/mod/util/Vec2x2.java b/project/rompecabeza/src/com/mod/util/Vec2x2.java new file mode 100644 index 0000000..a676147 --- /dev/null +++ b/project/rompecabeza/src/com/mod/util/Vec2x2.java @@ -0,0 +1,25 @@ +package mod.util; + +public class Vec2x2 { + // Position + public int x1_pos; + public int y1_pos; + + // Size + public int x2_size; + public int y2_size; + + public Vec2x2() { + this.x1_pos = 0; + this.y1_pos = 0; + this.x2_size = 0; + this.y2_size = 0; + } + + public Vec2x2(int x1, int y1, int x2, int y2) { + this.x1_pos = x1; + this.y1_pos = y1; + this.x2_size = x2; + this.y2_size = y2; + } +} \ No newline at end of file