Update
This commit is contained in:
parent
10bb6dc2e5
commit
c9037ed317
|
|
@ -1,3 +1,19 @@
|
|||
*.class
|
||||
*.log
|
||||
*.tmp
|
||||
# Java
|
||||
**/.class
|
||||
**/.jar
|
||||
|
||||
# IDE / Editor
|
||||
## VS code / VS Codium
|
||||
**/.vscode/
|
||||
|
||||
# Git
|
||||
**/.git/
|
||||
!/.git/
|
||||
|
||||
|
||||
# Temporal
|
||||
## Folders
|
||||
**/trash/
|
||||
## Files
|
||||
**/.log
|
||||
**/.tmp
|
||||
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -15,9 +15,6 @@ import javax.swing.JPanel;
|
|||
|
||||
public class Init extends JFrame implements ActionListener {
|
||||
|
||||
|
||||
|
||||
|
||||
public Init() {
|
||||
this.setTitle("Proy Final");
|
||||
this.setLayout(null);
|
||||
|
|
@ -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<Product> products = new ArrayList<Product>();
|
||||
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}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
all:
|
||||
cd ./src && javac Main.java && java Main
|
||||
|
||||
latex:
|
||||
pdflatex README.tex
|
||||
|
||||
clear:
|
||||
del /s /q *.class *.log *.aux *.toc
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import cafeteria.Restaurante;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Restaurante restaurante = new Restaurante();
|
||||
restaurante.db();
|
||||
restaurante.start();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> drain = new ArrayList<String>();
|
||||
private int mainID = -1;
|
||||
|
||||
public int getID() {
|
||||
return this.mainID += 1;
|
||||
}
|
||||
|
||||
ArrayList<Gastronomia> gastronomia = new ArrayList<Gastronomia>();
|
||||
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<ClientePedido> clientePedidos = new ArrayList<ClientePedido>();
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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)");
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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)");
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.src.Proy1
|
||||
Created-By: Tuzikuz
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.src.Proy1
|
||||
Created-By: Tuzikuz
|
||||
|
|
@ -0,0 +1 @@
|
|||
# Proy 1 Enjambre de Langosta v1.5
|
||||
Binary file not shown.
|
|
@ -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
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,8 @@
|
|||
package mod.utils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GameButton extends JButton {
|
||||
public int x, y;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
all:
|
||||
javac Main.java
|
||||
java Main
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.src.Proy2
|
||||
Created-By: tuzikuz
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.src.Proy2
|
||||
Created-By: tuzikuz
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
```
|
||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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<GameButton> 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<JButton> 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<UserData> 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<String>();
|
||||
JList<String> 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<UserData> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package mod.util;
|
||||
|
||||
public class UserData {
|
||||
public String name;
|
||||
public int crono;
|
||||
public int movimientos;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package mod.util;
|
||||
|
||||
public class Vec2D {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public Vec2D() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue