Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unal.datastructures.*;
- import java.io.*;
- import java.util.*;
- class PokeDex{
- public static void menu( ){
- System.out.println( "Pokédex" );
- System.out.println( "[C]apturar Pokemon" );
- System.out.println( "[L]iberar pokemon" );
- System.out.println( "[V]er mis pokemon" );
- System.out.println( "[P]reguntar" );
- System.out.println( "[E]ntrenar" );
- System.out.println( "[O]rdenar Pokedex" );
- System.out.println( "[G]uardar partida" );
- System.out.println( "[S]alir" );
- }
- public static void main( String[] args ) {
- Scanner i = new Scanner( System.in );
- ArrayLinearListImproved<Pokemon> laboratorio = new ArrayLinearListImproved<>( );
- laboratorio.load( "ListaPokedex_1.pok" );
- String opc;
- int ii;
- do{
- menu( );
- opc = i.nextLine( ).toUpperCase( );
- switch( opc ){
- case "C" : System.out.println( "Lanzando la Pokebola" );
- System.out.println( "Cual es este Pokémon? \nNivel= \nId = \nTipo" );
- laboratorio.add( 0, new Pokemon( i.next( ), i.nextInt( ), i.nextInt( ), i.next( ) ) );
- i.nextLine( );
- break;
- case "L" : System.out.println( "Estás a punto de liberar a tu Pokémon :( \n" );
- System.out.print( "A quien quieres liberar?\n" );
- ii = laboratorio.indexOf( new Pokemon( i.nextLine( ) ) );
- if( ii == -1 )
- System.out.println( "No encontramos este Pokémon, no lo podemos liberar." );
- else
- {
- System.out.println( "Tu Pokémon liberado fue " + laboratorio.get( ii ) );
- laboratorio.remove( ii );
- }
- break;
- case "V" : System.out.println( "Visualizando el nombre, el nivel y el id" );
- System.out.println( laboratorio );
- break;
- case "P" : System.out.println( "Sobre cual Pokémon quieres saber hoy?" );
- System.out.print( "Ingrese el nombre : " );
- ii = laboratorio.indexOf( new Pokemon( i.nextLine( ) ) );
- if( ii == -1 )
- System.out.println( "No ta!" );
- else
- System.out.println( "Si ta y es " + laboratorio.get( ii ) );
- break;
- case "E" : System.out.println( "Vamos a entrenar!" );
- System.out.print( "Con quien quieres entrenar? " );
- ii = laboratorio.indexOf( new Pokemon( i.nextLine( ) ) );
- if( ii == -1 )
- System.out.println( "Oh no, este Pokémon no aparece en el Pokédex." );
- else
- {
- Pokemon toTrain= laboratorio.remove( ii );
- System.out.print( "Nombre [" + toTrain.name + "] : " );
- toTrain.name = i.nextLine( );
- System.out.print( "Nivel [" + toTrain.nivel + "] : " );
- toTrain.nivel = Integer.parseInt( i.nextLine( ) );
- System.out.print( "Id [" + toTrain.id + "] : " );
- toTrain.id = Integer.parseInt( i.nextLine( ) );
- laboratorio.add( ii, toTrain);
- System.out.print("Tipo ["+toTrain.tipo+"]:" );
- toTrain.tipo = i.nextLine();
- }
- break;
- case "O" : System.out.println( "Ordenemos tu Pokédex" );
- laboratorio.sort( );
- System.out.println( "El Pokédex ha sido ordenado" );
- break;
- case "G" : System.out.println( "Guardando la partida, por favor no apagues, ni desconectes el pc." );
- laboratorio.save( "ListaPokedex_1.pok" );
- break;
- case "S" : System.out.println( "Esperamos volverte a ver pronto" );
- laboratorio.save( "ListaPokedex_1.pok" );
- break;
- default : System.out.println( "Lo sentimos, no entendimos lo que querías hacer." );
- }
- } while( ! opc.equals( "S" ) );
- }
- }
- class Pokemon implements Serializable, Comparable< Pokemon >{
- // fields
- String name;
- int nivel; // pos nivel
- int id; // id
- String tipo;
- // constructors
- Pokemon( ){
- this( "N/A", 0, 0, "N/A" );
- }
- Pokemon( String n ){
- this( n, 0, 0, "" );
- }
- Pokemon( String n, String t ){
- this( n, 0, 0, t );
- }
- Pokemon( String n, int e, int d, String t ){
- name = n;
- nivel = e;
- id = d;
- tipo = t ;
- }
- // methods
- @Override
- public String toString( ){
- return "\n[ " + name + ", " + nivel + ", " + id + ", "+ tipo +" ]";
- }
- public int compareTo( Pokemon comparadorDePokemon ){
- //return (this.nivel - comparadorDePokemon.nivel); // Ordenar por Nivel
- return(this.id - comparadorDePokemon.id); // Ordenar por id
- //return this.name.compareTo( comparadorDePokemon.name );// Ordenar alfabeticamente
- }
- @Override
- public boolean equals( Object otro ){
- if( otro == null ) return false;
- if( otro == this ) return true;
- if( ! ( otro instanceof Pokemon) ) return false;
- return this.name.equals( ( (Pokemon) otro ).name );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement