Advertisement
TobiasM

Calculator.cpp

Jul 19th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.60 KB | None | 0 0
  1. /* Programa para calcular promedios de vida de personajes del Imperium AO
  2.  * Creado por Tobias Nahuel Paiva Orzel Mallo
  3.  * http://tobiasmallo.wordpress.com/
  4.  *
  5.  * <Inicio de la licencia>
  6.  *
  7.  * Copyright (c) <2011> <Tobias Nahuel Paiva Orzel Mallo>
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *   notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *   notice, this list of conditions and the following disclaimer in the
  17.  *   documentation and/or other materials provided with the distribution.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21.  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
  23.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29.  * POSSIBILITY OF SUCH DAMAGE.
  30.  *
  31.  * <Fin de la licencia>
  32.  *
  33.  * Calculator.cpp
  34.  * Definición de las funciones de la clase Calculator
  35.  */
  36.  
  37. #include <iostream>
  38. using std::cout;
  39. using std::cin;
  40. using std::endl;
  41. using std::fixed;
  42.  
  43. #include <iomanip>
  44. using std::setprecision;
  45.  
  46. #include "Calculator.h"
  47.  
  48. void Calculator::ingresoDatos()
  49. {
  50.   int claseElegida;
  51.   int tuNivel;
  52.   int constitucion;
  53.   int vidaInicial;
  54.   int tuVida;
  55.   int humano;
  56.  
  57.   cout << "\nElige una clase:\n\n"
  58.   << "1_ Asesino\n" << "2_ Bardo\n" << "3_ Cazador\n" << "4_ Gladiador\n"
  59.   << "5_ Clerigo\n" << "6_ Druida\n" << "7_ Guerrero\n" << "8_ Ladron\n"
  60.   << "9_ Mago\n" << "10_ Nigromante\n" << "11_ Paladin\n" << "12_ Mercenario\n"
  61.   << endl;
  62.  
  63.   cout << "\nIngresa un numero del 1 al 12: ";
  64.   cin >> claseElegida;
  65.  
  66.   while ( claseElegida < 1 || claseElegida > 12 )
  67.   {
  68.     cout << "\nElige una clase:\n\n"
  69.     << "1_ Asesino\n" << "2_ Bardo\n" << "3_ Cazador\n" << "4_ Gladiador\n"
  70.     << "5_ Clerigo\n" << "6_ Druida\n" << "7_ Guerrero\n" << "8_ Ladron\n"
  71.     << "9_ Mago\n" << "10_ Nigromante\n" << "11_ Paladin\n" << "12_ Mercenario\n"
  72.     << endl;
  73.    
  74.     cout << "\nIngresa un numero del 1 al 12: ";
  75.     cin >> claseElegida;
  76.   }
  77.  
  78.   // Acá se ingresa el nivel del personaje
  79.   cout << "\nIngresa el nivel (2 a 60): ";
  80.   cin >> tuNivel;
  81.  
  82.   while ( tuNivel < 2 || tuNivel > 60 )
  83.   {
  84.     cout << "\nIngresa el nivel (2 a 60): ";
  85.     cin >> tuNivel;
  86.   }
  87.  
  88.   setNivel( tuNivel );
  89.  
  90.   // Acá se ingresan los puntos de constitución del personaje
  91.   cout << "\nIngresa constitucion (17 a 22): ";
  92.   cin >> constitucion;
  93.  
  94.   while ( constitucion < 17 || constitucion > 22 )
  95.   {
  96.     cout << "\nIngresa constitucion (17 a 22): ";
  97.     cin >> constitucion;
  98.   }
  99.  
  100.   setConstitucion( constitucion );
  101.  
  102.   setClase( claseElegida );
  103.  
  104.   // Se ingresa la vida inicial del personaje
  105.   // Tengo que averiguar bien el mínimo y máximo
  106.   cout << "\nIngresa vida inicial (8 a 26): ";
  107.   cin >> vidaInicial;
  108.  
  109.   while ( vidaInicial < 8 || vidaInicial > 26 )
  110.   {
  111.     cout << "\nIngresa vida inicial (8 a 26): ";
  112.     cin >> vidaInicial;
  113.   }
  114.  
  115.   setVidaInicial( vidaInicial );
  116.  
  117.   // Vida total del personaje
  118.   cout << "\nIngresa vida total (12 a 625): ";
  119.   cin >> tuVida;
  120.  
  121.   while ( tuVida < 12 || tuVida > 625 )
  122.   {
  123.     cout << "\nIngresa vida total (12 a 625): ";
  124.     cin >> tuVida;
  125.   }
  126.  
  127.   setVida( tuVida );
  128.  
  129.   cout << "\nLa raza de tu personaje es \"Humano\"?\n"
  130.   << "1_ Si\n" << "2_ No\n" << "\nElige: ";
  131.   cin >> humano;
  132.  
  133.   while ( humano < 1 || humano > 2 )
  134.   {
  135.     cout << "\nLa raza de tu personaje es \"Humano\"?\n"
  136.     << "1_ Si\n" << "2_ No\n" << "\nElige: ";
  137.     cin >> humano;
  138.   }
  139.  
  140.   switch ( humano )
  141.   {
  142.     case 1:
  143.       bonusHumano = ( nivelAjustado / 8 );
  144.       esHumano = true;
  145.       break;
  146.      
  147.     case 2:
  148.       bonusHumano = 0;
  149.       esHumano = false;
  150.       break;
  151.   }
  152. }
  153.  
  154. void Calculator::setConstitucion( int constitucion )
  155. {
  156.   Constit = constitucion;
  157. }
  158.  
  159. void Calculator::setClase( int claseElegida )
  160. {
  161.   switch ( claseElegida )
  162.   {
  163.     case 1:
  164.       tuClase = "Asesino";
  165.       if ( Constit == 22 )
  166.          setPromedio( 9 );
  167.       if ( Constit == 21 )
  168.          setPromedio( 8.75 );
  169.       if ( Constit == 20 )
  170.          setPromedio( 8 );
  171.       if ( Constit == 19 )
  172.          setPromedio( 7.5 );
  173.       if ( Constit == 18 )
  174.          setPromedio( 7.25 );
  175.       if ( Constit == 17 )
  176.          setPromedio( 6.5 );
  177.       break;
  178.      
  179.     case 2:
  180.       tuClase = "Bardo";
  181.       if ( Constit == 22 )
  182.          setPromedio( 8.5 );
  183.       if ( Constit == 21 )
  184.          setPromedio( 8 );
  185.       if ( Constit == 20 )
  186.          setPromedio( 7.5 );
  187.       if ( Constit == 19 )
  188.          setPromedio( 7 );
  189.       if ( Constit == 18 )
  190.          setPromedio( 6.75 );
  191.       if ( Constit == 17 )
  192.          setPromedio( 6.5 );
  193.       break;
  194.      
  195.     case 3:
  196.       tuClase = "Cazador";
  197.       if ( Constit == 22 )
  198.          setPromedio( 10 );
  199.       if ( Constit == 21 )
  200.          setPromedio( 9.75 );
  201.       if ( Constit == 20 )
  202.          setPromedio( 9.665 );
  203.       if ( Constit == 19 )
  204.          setPromedio( 9.5 );
  205.       if ( Constit == 18 )
  206.          setPromedio( 9.25 );
  207.       if ( Constit == 17 )
  208.          setPromedio( 9 );
  209.       break;
  210.      
  211.     case 4:
  212.       tuClase = "Gladiador";
  213.       if ( Constit == 22 )
  214.          setPromedio( 9.5 );
  215.       if ( Constit == 21 )
  216.          setPromedio( 9.25 );
  217.       if ( Constit == 20 )
  218.          setPromedio( 9 );
  219.       if ( Constit == 19 )
  220.          setPromedio( 8.5 );
  221.       if ( Constit == 18 )
  222.          setPromedio( 8 );
  223.       if ( Constit == 17 )
  224.          setPromedio( 7.5 );
  225.       break;
  226.      
  227.     case 5:
  228.       tuClase = "Clerigo";
  229.       if ( Constit == 22 )
  230.          setPromedio( 8.5 );
  231.       if ( Constit == 21 )
  232.          setPromedio( 8 );
  233.       if ( Constit == 20 )
  234.          setPromedio( 7.5 );
  235.       if ( Constit == 19 )
  236.          setPromedio( 7 );
  237.       if ( Constit == 18 )
  238.          setPromedio( 6.75 );
  239.       if ( Constit == 17 )
  240.          setPromedio( 6.5 );
  241.       break;
  242.      
  243.     case 6:
  244.       tuClase = "Druida";
  245.       if ( Constit == 22 )
  246.          setPromedio( 8.5 );
  247.       if ( Constit == 21 )
  248.          setPromedio( 8 );
  249.       if ( Constit == 20 )
  250.          setPromedio( 7.5 );
  251.       if ( Constit == 19 )
  252.          setPromedio( 7 );
  253.       if ( Constit == 18 )
  254.          setPromedio( 6.75 );
  255.       if ( Constit == 17 )
  256.          setPromedio( 6.5 );
  257.       break;
  258.      
  259.     case 7:
  260.       tuClase = "Guerrero";
  261.       if ( Constit == 22 )
  262.          setPromedio( 10 );
  263.       if ( Constit == 21 )
  264.          setPromedio( 9.75 );
  265.       if ( Constit == 20 )
  266.          setPromedio( 9.665 );
  267.       if ( Constit == 19 )
  268.          setPromedio( 9.5 );
  269.       if ( Constit == 18 )
  270.          setPromedio( 9.25 );
  271.       if ( Constit == 17 )
  272.          setPromedio( 9 );
  273.       break;
  274.      
  275.     case 8:
  276.       tuClase = "Ladron";
  277.       if ( Constit == 22 )
  278.          setPromedio( 8.5 );
  279.       if ( Constit == 21 )
  280.          setPromedio( 8.25 );
  281.       if ( Constit == 20 )
  282.          setPromedio( 8 );
  283.       if ( Constit == 19 )
  284.          setPromedio( 7.5 );
  285.       if ( Constit == 18 )
  286.          setPromedio( 7 );
  287.       if ( Constit == 17 )
  288.          setPromedio( 6.5 );
  289.       break;
  290.      
  291.     case 9:
  292.       tuClase = "Mago";
  293.       if ( Constit == 22 )
  294.          setPromedio( 7 );
  295.       if ( Constit == 21 )
  296.          setPromedio( 6.75 );
  297.       if ( Constit == 20 )
  298.          setPromedio( 6.5 );
  299.       if ( Constit == 19 )
  300.          setPromedio( 6 );
  301.       if ( Constit == 18 )
  302.          setPromedio( 5.75 );
  303.       if ( Constit == 17 )
  304.          setPromedio( 5.5 );
  305.       break;
  306.      
  307.     case 10:
  308.       tuClase = "Nigromante";
  309.       if ( Constit == 22 )
  310.          setPromedio( 8 );
  311.       if ( Constit == 21 )
  312.          setPromedio( 7.5 );
  313.       if ( Constit == 20 )
  314.          setPromedio( 7 );
  315.       if ( Constit == 19 )
  316.          setPromedio( 6.75 );
  317.       if ( Constit == 18 )
  318.          setPromedio( 6.5 );
  319.       if ( Constit == 17 )
  320.          setPromedio( 6.25 );
  321.       break;
  322.      
  323.     case 11:
  324.       tuClase = "Paladin";
  325.       if ( Constit == 22 )
  326.          setPromedio( 9.75 );
  327.       if ( Constit == 21 )
  328.          setPromedio( 9.665 );
  329.       if ( Constit == 20 )
  330.          setPromedio( 9.5 );
  331.       if ( Constit == 19 )
  332.          setPromedio( 9 );
  333.       if ( Constit == 18 )
  334.          setPromedio( 8.75 );
  335.       if ( Constit == 17 )
  336.          setPromedio( 8.5 );
  337.       break;
  338.      
  339.     case 12:
  340.       tuClase = "Mercenario";
  341.       if ( Constit == 22 )
  342.          setPromedio( 9.5 );
  343.       if ( Constit == 21 )
  344.          setPromedio( 9.25 );
  345.       if ( Constit == 20 )
  346.          setPromedio( 9 );
  347.       if ( Constit == 19 )
  348.          setPromedio( 8.5 );
  349.       if ( Constit == 18 )
  350.          setPromedio( 8 );
  351.       if ( Constit == 17 )
  352.          setPromedio( 7.5 );
  353.       break;
  354.   }
  355. }
  356.  
  357. void Calculator::setPromedio( double promedioRecibido )
  358. {
  359.   promedioClase = promedioRecibido;
  360. }
  361.  
  362. void Calculator::setNivel( int tuNivel )
  363. {
  364.   if ( tuNivel > 50 )
  365.     nivelAjustado = 50;
  366.   else
  367.     nivelAjustado = tuNivel;
  368. }
  369.  
  370. void Calculator::setVidaInicial( int vidaInicial )
  371. {
  372.   inicial = vidaInicial;
  373. }
  374.  
  375. void Calculator::setVida( int tuVida )
  376. {
  377.   vida = tuVida;
  378. }
  379.  
  380. void Calculator::calcularPromedio() // Aún falta trabajar en esto
  381. {
  382.   double resultado;
  383.   int bonusClerigo = 0;
  384.  
  385.   if ( tuClase == "Clerigo" )
  386.     bonusClerigo = ( nivelAjustado / 5 );
  387.  
  388.   resultado = ( static_cast< double >( vida ) - bonusClerigo - bonusHumano - inicial ) / ( nivelAjustado - 1 );
  389.  
  390.   // En resultado vendría bien un fixed y un setprecision( 2 )
  391.   cout << fixed << setprecision( 3 );
  392.   cout << "\nEl promedio de tu personaje es: " << resultado << "\n"
  393.   << "El promedio de un " << tuClase << " con " << Constit << " puntos de constitucion es: "
  394.   << promedioClase << "\n" << endl;
  395.    
  396.   // Agregar acá los resultados para el bonus de clérigo y humano
  397.   if ( esHumano == true )
  398.     cout << "Recibiste " << bonusHumano << " punto(s) extra de vida por el bonus de humano" << endl;
  399.   if ( tuClase == "Clerigo" )
  400.     cout << "Recibiste " << bonusClerigo << " punto(s) extra de vida por el bonus de clerigo" << endl;
  401.  
  402.   cout << endl;
  403. }
  404.  
  405. // Fin de la clase Calculator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement