You are on page 1of 10

PROYECTO FINAL “TABLERO DE DARDOS” PRIMERA PARTE

Brahyan Aguirre Díaz

Mateo Betancurt Vélez

Profesor:

Julián Esteban Gutiérrez Posada

Universidad del Quindío

Programa Ingeniería de Sistemas y Computación

Paradigma Orientado a Objetos

Armenia, Quindío

Octubre del 2016


TABLERO DE DARDOS

CÓDIGO FUENTE:

//Estudiantes: Mateo Betancurt Vélez, Brahyan Aguirre Díaz


//Profesor: Julián Esteban Gutiérrez Posada
//Materia: Paradigma Orientado a Objetos
//Proyecto: Dardos

package Dardos;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
* Programa para contabilizar los puntos realizados por un jugador, realizando
lanzamientos a un tablero de dardos
* a través de la función Math.random() e imprime el puntaje de cada lanzamiento y el
puntaje final del jugador.
*
* @author Mateo Betancurt Velez
* @author Brahyan Aguirre Díaz
*/
public class Dardos
{
final static int DIANA_SIMPLE = 25;
final static int DIANA = 50;
final static int PUNTAJE = 301;

/**
* Método para leer un entero
*
* @param m Mensaje de la pregunta (Dato que se va a solicitar)
* @return Número entero dado por usuario
*/
public static int leerEntero(String m)
{
while (true)
{
try
{
return Integer.parseInt(JOptionPane.showInputDialog(m));
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Por favor digite un número", "¡ERROR!",
JOptionPane.ERROR_MESSAGE,
new ImageIcon("src/imagen/Error.png"));
}
}
}

2
/**
* Método para imprimir un mensaje
*
* @param t Texto a imprimir
* @param tipoPartida Texto del tipo de partida
*/
public static void imprimir(String t,String tipoPartida)
{
if (tipoPartida == "PARTIDA BUENA")
{
JOptionPane.showMessageDialog(null, t,"Resultados",
JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/imagen/PartidaBuena.png"));
}
else
{
if (tipoPartida == "PARTIDA NORMAL")
{
JOptionPane.showMessageDialog(null, t,"Resultados",
JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/imagen/PartidaNormal.png"));
}
else
{
JOptionPane.showMessageDialog(null, t,"Resultados",
JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/imagen/PartidaMala.png"));
}
}

/**
* Método para calculaar tipo de partida
*
* @param puntaje Puntaje del jugador para determinar el tipo de partida
* @return Tipo de partida (PARTIDA BUENA, PARTIDA NORMAL, PARTIDA MALA)
*/
public static String tipoPartida(int puntaje)
{
String tipo = null;

if(puntaje >= 0 && puntaje <= 100)


{
tipo = "PARTIDA BUENA";
}

if(puntaje >= 101 && puntaje <= 200)


{
tipo = "PARTIDA NORMAL";
}
if(puntaje >=201 && puntaje <= 301)
{
tipo = "PARTIDA MALA";
}

return tipo;
}

3
/**
* Método para procesar el menú
*
* @param nombre Nombre del jugador ingresado
* @param tipoPartida Tipo de partida (PARTIDA BUENA, PARTIDA NORMAL, PARTIDA
MALA)
* @param puntaje Puntaje inicial de la partida
*/
public static void procesarMenu(String nombre, String tipoPartida, int puntaje)
{
String menu;
int opcion;

menu = "JUEGO DE DARDOS\n\n";


menu += "1. Jugar\n";
menu += "2. Ver puntaje\n";
menu += "3. Salir";

do
{
opcion = leerEntero(menu);
switch (opcion)
{

case 1:
nombre = JOptionPane.showInputDialog("Por favor ingrese el nombre del
jugador");
puntaje =PUNTAJE;
puntaje = jugar(puntaje);
tipoPartida = tipoPartida(puntaje);

imprimir("Nombre: " + nombre + "\nPuntaje: " + puntaje


+ "\n"+ tipoPartida,tipoPartida);
break;

case 2:
if(nombre != null && tipoPartida != null)
{
JOptionPane.showMessageDialog(null,"Nombre: " + nombre+ "\nPuntaje: "
+ puntaje + "\n" + tipoPartida,"Puntaje",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/MejorPuntaje.png"));
break;
}
else
{
JOptionPane.showMessageDialog(null,"Lo sentimos. \n"+"Aún no se
encuentran partidas realizadas","No hay datos aún",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/NoPuntaje.png"));
break;
}

4
case 3:
JOptionPane.showMessageDialog(null,"Fin del
juego","Salir",JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("src/imagen/Fin.png"));
break;

default:
JOptionPane.showMessageDialog(null,"Número no
válido","Advertencia",JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("src/imagen/Advertencia.png"));
break;
}
}while (opcion != 3);
}

/**
* Método para generar 10 lanzamientos de números aleatorios
*
* @param puntaje Puntaje inicial de la partida
* @return Puntaje total al final de los 10 lanzamientos
*/
public static int jugar(int puntaje)
{
int i, zona, zonaLanzamiento;

for(i=1;i<11;i++)
{
int puntos;
zona = (int) (Math.random()* 20 + 1);
zonaLanzamiento = (int) (Math.random()* 62 + 1);

if(puntaje >0)
{
if(zonaLanzamiento >=1 && zonaLanzamiento <=20)
{
puntos = zona;

if(puntaje - puntos >= 0)


{
puntaje -= puntos;
JOptionPane.showMessageDialog(null,"LANZAMIENTO: " + i + "\n\n"
+ "Cayó en zona: " + zona + "\n"
+ "Puntos: " + puntos + "\n"
+ "Puntaje: " + puntaje, "Lanzamientos",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/Lanzamientos.png"));
}
else
{
return 0;
}
}

if(zonaLanzamiento >=21 && zonaLanzamiento <=40)


{

5
puntos = (zona * 2);

if(puntaje - puntos >=0)


{
puntaje -= puntos;
JOptionPane.showMessageDialog(null,"LANZAMIENTO: " + i + "\n\n"
+"Cayó en zona externa: "+ zona + " *2" + "\n"
+ "Puntos: " + puntos + "\n"
+ "Puntaje: " + puntaje, "Lanzamientos",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/Lanzamientos.png") );
}
else
{
return 0;
}
}

if(zonaLanzamiento >= 41 && zonaLanzamiento <=60)


{
puntos = (zona * 3);

if(puntaje - puntos >=0)


{
puntaje -= puntos;
JOptionPane.showMessageDialog(null,"LANZAMIENTO: " + i + "\n\n"
+ "Cayó en zona interna: " + zona + " *3" + "\n"
+ "Puntos: " + puntos + "\n"
+ "Puntaje: " + puntaje, "Lanzamientos",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/Lanzamientos.png") );
}
else
{
return 0;
}
}

if(zonaLanzamiento == 61)
{
puntos = DIANA_SIMPLE;

if(puntaje - puntos >=0)


{
puntaje -= puntos;
JOptionPane.showMessageDialog(null,"LANZAMIENTO: " + i + "\n\n"
+ "Cayó en Diana simle \n"
+ "Puntos: " + puntos + "\n"
+ "puntaje: " + puntaje, "Lanzamientos",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/Lanzamientos.png") );
}
else
{
return 0;

6
}
}

if(zonaLanzamiento == 62)
{
puntos = DIANA;

if(puntaje - puntos >=0)


{
puntaje -= puntos;
JOptionPane.showMessageDialog(null,"LANZAMIENTO: " + i + "\n\n"
+ "Cayó en la Diana \n"
+ "Puntos: " + puntos + "\n"
+ "Puntaje: " + puntaje, "Lanzamientos",
JOptionPane.INFORMATION_MESSAGE, new
ImageIcon("src/imagen/Lanzamientos.png") );
}
else
{
return 0;
}
}
}
}
return puntaje;
}

/**
* @param args argumentos de linea de comandos
*/
public static void main(String[] args)
{
int puntaje;
puntaje = PUNTAJE;
String nombre = null, tipoPartida = null;

procesarMenu(nombre, tipoPartida, puntaje);

}
}

7
EJECUCIÓN:

 Menú

 Jugar

8
 Ver Puntaje

 Salir

 Tipos de partida

9
 Validaciones

 Ingreso de letras y/o símbolos

 Números no incluidos en el menú

 Ver puntaje sin haber jugado anteriormente

10

You might also like