Advertisement
Guest User

PokeDex

a guest
Feb 26th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. import unal.datastructures.*;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. class PokeDex{
  6.  
  7. public static void menu( ){
  8. System.out.println( "Pokédex" );
  9. System.out.println( "[C]apturar Pokemon" );
  10. System.out.println( "[L]iberar pokemon" );
  11. System.out.println( "[V]er mis pokemon" );
  12. System.out.println( "[P]reguntar" );
  13. System.out.println( "[E]ntrenar" );
  14. System.out.println( "[O]rdenar Pokedex" );
  15. System.out.println( "[G]uardar partida" );
  16. System.out.println( "[S]alir" );
  17. }
  18.  
  19. public static void main( String[] args ) {
  20. Scanner i = new Scanner( System.in );
  21. ArrayLinearListImproved<Pokemon> laboratorio = new ArrayLinearListImproved<>( );
  22. laboratorio.load( "ListaPokedex_1.pok" );
  23.  
  24. String opc;
  25. int ii;
  26. do{
  27. menu( );
  28. opc = i.nextLine( ).toUpperCase( );
  29. switch( opc ){
  30. case "C" : System.out.println( "Lanzando la Pokebola" );
  31. System.out.println( "Cual es este Pokémon? \nNivel= \nId = \nTipo" );
  32. laboratorio.add( 0, new Pokemon( i.next( ), i.nextInt( ), i.nextInt( ), i.next( ) ) );
  33. i.nextLine( );
  34. break;
  35. case "L" : System.out.println( "Estás a punto de liberar a tu Pokémon :( \n" );
  36. System.out.print( "A quien quieres liberar?\n" );
  37. ii = laboratorio.indexOf( new Pokemon( i.nextLine( ) ) );
  38. if( ii == -1 )
  39. System.out.println( "No encontramos este Pokémon, no lo podemos liberar." );
  40. else
  41. {
  42. System.out.println( "Tu Pokémon liberado fue " + laboratorio.get( ii ) );
  43. laboratorio.remove( ii );
  44. }
  45. break;
  46. case "V" : System.out.println( "Visualizando el nombre, el nivel y el id" );
  47. System.out.println( laboratorio );
  48.  
  49. break;
  50. case "P" : System.out.println( "Sobre cual Pokémon quieres saber hoy?" );
  51. System.out.print( "Ingrese el nombre : " );
  52. ii = laboratorio.indexOf( new Pokemon( i.nextLine( ) ) );
  53. if( ii == -1 )
  54. System.out.println( "No ta!" );
  55. else
  56. System.out.println( "Si ta y es " + laboratorio.get( ii ) );
  57. break;
  58. case "E" : System.out.println( "Vamos a entrenar!" );
  59. System.out.print( "Con quien quieres entrenar? " );
  60. ii = laboratorio.indexOf( new Pokemon( i.nextLine( ) ) );
  61. if( ii == -1 )
  62. System.out.println( "Oh no, este Pokémon no aparece en el Pokédex." );
  63. else
  64. {
  65. Pokemon toTrain= laboratorio.remove( ii );
  66. System.out.print( "Nombre [" + toTrain.name + "] : " );
  67. toTrain.name = i.nextLine( );
  68. System.out.print( "Nivel [" + toTrain.nivel + "] : " );
  69. toTrain.nivel = Integer.parseInt( i.nextLine( ) );
  70. System.out.print( "Id [" + toTrain.id + "] : " );
  71. toTrain.id = Integer.parseInt( i.nextLine( ) );
  72. laboratorio.add( ii, toTrain);
  73. System.out.print("Tipo ["+toTrain.tipo+"]:" );
  74. toTrain.tipo = i.nextLine();
  75. }
  76. break;
  77. case "O" : System.out.println( "Ordenemos tu Pokédex" );
  78. laboratorio.sort( );
  79. System.out.println( "El Pokédex ha sido ordenado" );
  80. break;
  81. case "G" : System.out.println( "Guardando la partida, por favor no apagues, ni desconectes el pc." );
  82. laboratorio.save( "ListaPokedex_1.pok" );
  83. break;
  84. case "S" : System.out.println( "Esperamos volverte a ver pronto" );
  85. laboratorio.save( "ListaPokedex_1.pok" );
  86. break;
  87. default : System.out.println( "Lo sentimos, no entendimos lo que querías hacer." );
  88. }
  89. } while( ! opc.equals( "S" ) );
  90. }
  91. }
  92.  
  93. class Pokemon implements Serializable, Comparable< Pokemon >{
  94. // fields
  95. String name;
  96. int nivel; // pos nivel
  97. int id; // id
  98. String tipo;
  99.  
  100. // constructors
  101. Pokemon( ){
  102. this( "N/A", 0, 0, "N/A" );
  103. }
  104.  
  105. Pokemon( String n ){
  106. this( n, 0, 0, "" );
  107. }
  108.  
  109. Pokemon( String n, String t ){
  110. this( n, 0, 0, t );
  111. }
  112.  
  113. Pokemon( String n, int e, int d, String t ){
  114. name = n;
  115. nivel = e;
  116. id = d;
  117. tipo = t ;
  118. }
  119.  
  120. // methods
  121.  
  122. @Override
  123. public String toString( ){
  124. return "\n[ " + name + ", " + nivel + ", " + id + ", "+ tipo +" ]";
  125. }
  126.  
  127. public int compareTo( Pokemon comparadorDePokemon ){
  128. //return (this.nivel - comparadorDePokemon.nivel); // Ordenar por Nivel
  129. return(this.id - comparadorDePokemon.id); // Ordenar por id
  130. //return this.name.compareTo( comparadorDePokemon.name );// Ordenar alfabeticamente
  131. }
  132.  
  133.  
  134. @Override
  135. public boolean equals( Object otro ){
  136. if( otro == null ) return false;
  137. if( otro == this ) return true;
  138. if( ! ( otro instanceof Pokemon) ) return false;
  139. return this.name.equals( ( (Pokemon) otro ).name );
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement