Facebook
From Beefy Lion, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 63
  1. package learning;
  2.  
  3. import static learning.VocationEnum.*;
  4.  
  5. public class Character {
  6.  
  7.     int lvl = 10, hp, mp, cap;
  8.     Double exp;
  9.     VocationEnum vocation;
  10.  
  11.     public void print() {
  12.         System.out.println(" Postać na poziomie " + lvl + " posiada " + exp.intValue() + " doświadczenia. ");
  13.         printProfessionResults();
  14.     }
  15.  
  16.     private void printProfessionResults() {
  17.         switch(vocation) {
  18.             case KNIGHT :
  19.                 System.out.println("Knight posiada: ");
  20.                 break;
  21.  
  22.             case PALADIN:
  23.                 System.out.println("Paladin posiada: ");
  24.                 break;
  25.  
  26.             case SORCERER:
  27.                 System.out.println("Sorcerer posiada: ");
  28.                 break;
  29.  
  30.             case DRUID:
  31.                 System.out.println(" Elder Druid posiada: ");
  32.                 break;
  33.         }
  34.  
  35.         System.out.println(hp + " życia");
  36.         System.out.println(mp + " many. ");
  37.         System.out.println(cap + " capa. ");
  38.         System.out.println();
  39.     }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.     void askForProfession() {
  46.         System.out.println(" Wybierz numer swojej profesji lub q by zakończyć: ");
  47.         System.out.println(" 1. EK ");
  48.         System.out.println(" 2. RP ");
  49.         System.out.println(" 3. MS ");
  50.         System.out.println(" 4. ED ");
  51.     }
  52.  
  53.  
  54.  
  55.  
  56.     boolean isVal(int ch) {
  57.         if(ch < '1' | ch > 4 & ch != 'q') {
  58.             return false;
  59.         }
  60.         else {
  61.             return true;
  62.         }
  63.     }
  64.  
  65.  
  66.  
  67.  
  68.     public void setProfession(char choice) {
  69.         switch(choice) {
  70.             case '1': vocation = KNIGHT; break;
  71.             case '2': vocation = PALADIN; break;
  72.             case '3': vocation = SORCERER; break;
  73.             case '4': vocation = DRUID; break;
  74.         }
  75.     }
  76.  
  77.     public void calculate() {
  78.         exp = 50.0 / 3.0  * ((lvl * lvl * lvl) - (6 * (lvl * lvl)) + (17 * lvl) - 12);
  79.  
  80.         if(vocation == KNIGHT) {
  81.             calculateKnight();
  82.         } else if (vocation == PALADIN) {
  83.             calculatePaladin();
  84.         } else {
  85.             calculateMaginProfession();
  86.         }
  87.     }
  88.  
  89.     private void calculateKnight() {
  90.         hp = 5*(3 * lvl +13);
  91.         mp = 5*(lvl + 10);
  92.         cap = 5*(5 * lvl + 54);
  93.     }
  94.  
  95.     private void calculatePaladin() {
  96.         hp = 5*(2 * lvl + 21);
  97.         mp = 5*(3 * lvl - 6);
  98.         cap = 10*(2 * lvl + 31);
  99.     }
  100.  
  101.     private void calculateMaginProfession() {
  102.         hp = 5*(lvl + 29);
  103.         mp = 5*(6 * lvl - 30);
  104.         cap = 10*(lvl + 39);
  105.     }
  106. }
  107.