Advertisement
LinuxAIO

Proyecto_Jonathan.cpp

Jan 20th, 2019
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. struct Luchador{
  8.   string nombre;
  9.   string contextura;
  10.   Luchador *prox;
  11. };
  12.  
  13. struct Movimientos{
  14.   string combo;
  15.   int damage;
  16.   string ventajas;
  17.   Movimientos *prox;
  18. };
  19.  
  20. struct Jugador{
  21.   string nombre;
  22.   int nivel;
  23.   Jugador *prox;
  24. };
  25.  
  26. struct Pila_Luchadores{
  27.   string nombre;
  28.   Pila_Luchadores *prox;
  29.  
  30. };
  31.  
  32. void Agregar_Luchadores(Pila_Luchadores *&pila, string n){
  33.   Pila_Luchadores *nuevo_nodo = new Pila_Luchadores();
  34.   nuevo_nodo->nombre = n;
  35.   nuevo_nodo->prox = pila;
  36.   pila = nuevo_nodo;
  37. }//end-push
  38.  
  39.  
  40. void Sacar_Luchadores(Pila_Luchadores *&pila, string &n){
  41.   Pila_Luchadores *aux = pila;
  42.   n = aux->nombre;
  43.   pila = aux->prox;
  44.   delete aux;
  45. }//end-pop
  46.  
  47.  
  48. /*Funciones para el Luchador*/
  49.  
  50. bool Buscar_Luchador(Luchador *Listado_Luchadores, string nombre){
  51.   Luchador *actual = new Luchador();
  52.   actual = Listado_Luchadores;
  53.   while(actual != NULL){
  54.     if(actual->nombre == nombre){
  55.       return true;
  56.     }
  57.     actual = actual->prox;
  58.   }
  59.   return false;
  60. }//end-busqueda
  61.  
  62. void Insertar_Luchadores(Luchador *&Listado_Luchadores, string nombre, string contextura){
  63.   Luchador *nuevo_luchador = new Luchador();
  64.   nuevo_luchador->nombre = nombre;
  65.   nuevo_luchador->contextura = contextura;
  66.   Luchador *aux1 = Listado_Luchadores;
  67.   Luchador *aux2;
  68.  
  69.   while(aux1 != NULL){
  70.     aux2 = aux1;
  71.     aux1 = aux1->prox;
  72.   }
  73.  
  74.   if(Listado_Luchadores == aux1){
  75.     Listado_Luchadores = nuevo_luchador;
  76.   }else{
  77.     aux2 -> prox = nuevo_luchador;
  78.   }
  79. }//end-insertar
  80.  
  81.  
  82. /*Funciones para los Movimientos*/
  83.  
  84. void Insertar_Movimientos(Movimientos *&Listado_Movimientos, string nombre, int damage, string contextura){
  85.   Movimientos *nuevo_movimiento = new Movimientos();
  86.   nuevo_movimiento->combo = nombre;
  87.   nuevo_movimiento->damage = damage;
  88.   nuevo_movimiento->ventajas = contextura;
  89.   Movimientos *aux1 = Listado_Movimientos;
  90.   Movimientos *aux2;
  91.  
  92.   while(aux1 != NULL){
  93.     aux2 = aux1;
  94.     aux1 = aux1->prox;
  95.   }
  96.  
  97.   if(Listado_Movimientos == aux1){
  98.     Listado_Movimientos = nuevo_movimiento;
  99.   }else{
  100.     aux2 ->prox = nuevo_movimiento;
  101.   }
  102. }//end-insertar
  103.  
  104.  
  105. /*Funciones para el Jugador*/
  106.  
  107. void Insertar_Jugador(Jugador *&Listado_Jugadores, string nombre, int level){
  108.   Jugador *nuevo_jugador = new Jugador();
  109.   nuevo_jugador->nombre = nombre;
  110.   nuevo_jugador->nivel = level;
  111.   Jugador *aux1 = Listado_Jugadores;
  112.   Jugador *aux2;
  113.   while(aux1 != NULL){
  114.     aux2 = aux1;
  115.     aux1 = aux1->prox;
  116.   }
  117.   if(Listado_Jugadores == aux1){
  118.     Listado_Jugadores = nuevo_jugador;
  119.   }else{
  120.     aux2->prox=nuevo_jugador;
  121.   }
  122. }//end-insertar-jugador
  123.  
  124. bool Buscar_Jugador(Jugador *Listado_Jugadores, string nombre){
  125. Jugador *actual = new Jugador();
  126.   actual = Listado_Jugadores;
  127.   while(actual != NULL){
  128.     if(actual->nombre == nombre){
  129.       return true;
  130.     }
  131.     actual = actual->prox;
  132.   }
  133.   return false;
  134. }//end-Buscar_Jugador
  135.  
  136.  
  137. bool validar_nivel(int n){
  138.   return (n < 0 || n > 100)? true : false;
  139. }
  140.  
  141. bool validar_contextura(string a){
  142.   if(a == "ligero" || a == "pesado" || a == "equilibrado" ||
  143. a == "[ligero]" || a == "[pesado]" || a == "[equilibrado]" || a =="[]"){
  144.     return true;
  145.   }else{
  146.     return false;
  147.   }
  148. }
  149.  
  150. Luchador *Listado_Luchadores = NULL;
  151. Movimientos *Listado_Movimientos = NULL;
  152. Jugador *Listado_Jugadores = NULL;
  153. Pila_Luchadores *pila = NULL;
  154.  
  155. int main(){
  156.   string peticion, aux, contextura;
  157.   int damage = 0;
  158.   ifstream Entrada;
  159.   Entrada.open("Entrada.in");
  160.   while(getline(Entrada,peticion)){
  161.     damage = 0;
  162.     stringstream line(peticion);
  163.     line >> peticion;
  164.     if(peticion == "Luchador"){
  165.       line >> aux >> contextura;
  166.       if(validar_contextura(contextura)){
  167.         Insertar_Luchadores(Listado_Luchadores, aux, contextura);
  168.       }else{
  169.         cout << "Lo sentimos contextura no valida \n";
  170.       }
  171.  
  172.     }else if(peticion == "Movimiento"){
  173.       line >> aux;
  174.       if(Buscar_Luchador(Listado_Luchadores,aux)){
  175.         line >> aux >> damage >> contextura;
  176.         //cout << "ventajas: " << contextura << "\n";
  177.         if(validar_contextura(contextura)){
  178.           Insertar_Movimientos(Listado_Movimientos, aux, damage, contextura);
  179.         }else{
  180.           cout << "El combo a utilizar no contiene ventajas validas \n";
  181.         }
  182.       }else{
  183.         cout << "Nombre del Luchador no existe \n";
  184.       }
  185.  
  186.     }else if(peticion == "Jugador"){
  187.       line >> aux >> damage;
  188.       if(!validar_nivel(damage)){
  189.         Insertar_Jugador(Listado_Jugadores, aux, damage);
  190.       }else{
  191.         cout << "Lo sentimos nivel requerido 0-100 \n";
  192.       }
  193.  
  194.     }else if(peticion == "Asignar"){
  195.       line >> aux >> contextura;
  196.       if(Buscar_Jugador(Listado_Jugadores,aux)){
  197.         Agregar_Luchadores(pila,contextura);
  198.       }else{
  199.         cout << "Jugador no existe \n";
  200.       }
  201.     }else if(peticion == "Combate"){
  202.       cout << "Entras en la team-fight \n";
  203.     }else{
  204.       cout << "Lo sentimos Comando invalido \n";
  205.     }//end-validacion
  206.  
  207.     //cout << aux << "\n";
  208.     //cout << damage << "\n";
  209.     //cout << contextura << "\n";
  210.   }//end-while
  211.  
  212.   Entrada.close();
  213.   return 0;
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement