DearOohDeer

Dekorator

May 24th, 2022 (edited)
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.02 KB | None | 0 0
  1. //Main
  2. package DecoChar;
  3. import java.util.Scanner;
  4. import DecoChar.Character.ListEq;
  5.  
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.  
  10.  
  11.         Scanner Input = new Scanner(System.in);
  12.         Character CharOb = null;
  13.         int MenuOption;
  14.  
  15.         CharOb = new MainCharacter();
  16.         do {
  17.             menu();
  18.             MenuOption = Input.nextInt();
  19.             switch (MenuOption) {
  20.                 case 1:
  21.                     CharOb = new MainCharacter();
  22.                     CharOb.CheckStats();
  23.                     break;
  24.                 case 2:
  25.                     if (CharOb.CurrentEq[0] == null) {
  26.                         CharOb = new Gloves(CharOb);
  27.                         CharOb.CurrentEq[0] = new Gloves(CharOb);
  28.                         System.out.println("Założono rękawice");
  29.                     } else {
  30.                         CharOb.CurrentEq[0] = null;
  31.                         CharOb.Deco = ListEq.GLOVES;
  32.                         CharOb.RemovDeco(CharOb);
  33.                         System.out.println("Zdjęto rękawice");
  34.                     }
  35.                     CharOb.CheckStats();
  36.                     break;
  37.                 case 3:
  38.                     if (CharOb.CurrentEq[1] == null) {
  39.                         CharOb = new Shoes(CharOb);
  40.                         CharOb.CurrentEq[1] = new Shoes(CharOb);
  41.                         System.out.println("Założono buty");
  42.                     } else {
  43.                         CharOb.CurrentEq[1] = null;
  44.                         CharOb.Deco = ListEq.SHOES;
  45.                         CharOb.RemovDeco(CharOb);
  46.                         System.out.println("Zdjęto buty");
  47.                     }
  48.                     CharOb.CheckStats();
  49.                     break;
  50.                 case 4:
  51.                     if (CharOb.CurrentEq[2] == null) {
  52.                         CharOb = new Pants(CharOb);
  53.                         CharOb.CurrentEq[2] = new Pants(CharOb);
  54.                         System.out.println("Założono spodnie");
  55.                     } else {
  56.                         CharOb.CurrentEq[2] = null;
  57.                         CharOb.Deco = ListEq.PANTS;
  58.                         CharOb.RemovDeco(CharOb);
  59.                         System.out.println("Zdjęto spodnie");
  60.                     }
  61.                     CharOb.CheckStats();
  62.                     break;
  63.                 case 5:
  64.                     if (CharOb.CurrentEq[3] == null) {
  65.                         CharOb = new Helmet(CharOb);
  66.                         CharOb.CurrentEq[3] = new Helmet(CharOb);
  67.                         System.out.println("Założono hełm");
  68.                     } else {
  69.                         CharOb.CurrentEq[3] = null;
  70.                         CharOb.Deco = ListEq.HELMET;
  71.                         CharOb.RemovDeco(CharOb);
  72.                         System.out.println("Zdjęto hełm");
  73.                     }
  74.                     CharOb.CheckStats();
  75.                     break;
  76.                 case 6:
  77.                     if (CharOb.CurrentEq[5] == null) {
  78.                         CharOb = new Sword(CharOb);
  79.                         CharOb.CurrentEq[5] = new Sword(CharOb);
  80.                         System.out.println("Założono miecz");
  81.                     } else {
  82.                         CharOb.CurrentEq[5] = null;
  83.                         CharOb.Deco = ListEq.SWORD;
  84.                         CharOb.RemovDeco(CharOb);
  85.                         System.out.println("Zdjęto miecz");
  86.                     }
  87.                     CharOb.CheckStats();
  88.                     break;
  89.                 case 7:
  90.                     if (CharOb.CurrentEq[6] == null) {
  91.                         CharOb = new Chest(CharOb);
  92.                         CharOb.CurrentEq[6] = new Chest(CharOb);
  93.                         System.out.println("Założono zbroje");
  94.                     } else {
  95.                         CharOb.CurrentEq[6] = null;
  96.                         CharOb.Deco = ListEq.CHEST;
  97.                         CharOb.RemovDeco(CharOb);
  98.                         System.out.println("Zdjęto zbroje");
  99.                     }
  100.                     CharOb.CheckStats();
  101.                     break;
  102.                 case 0:
  103.                     break;
  104.                 default:
  105.                     System.out.println("Wprowadz liczbe od 0-7.");
  106.             }
  107.         } while (MenuOption != 0);
  108.         Input.close();
  109.     }
  110.  
  111.     public static void menu() {
  112.         System.out.println("1.Aby zresetować postać.");
  113.         System.out.println("2.Aby założyć lub zdjąć rękawice.");
  114.         System.out.println("3.Aby założyć lub zdjąć buty.");
  115.         System.out.println("4.Aby założyć lub zdjąć spodnie.");
  116.         System.out.println("5.Aby założyć lub zdjąć hełm.");
  117.         System.out.println("6.Aby założyć lub zdjąć miecz.");
  118.         System.out.println("7.Aby założyć lub zdjąć zbroje.");
  119.         System.out.println("Wcisnij 0 aby zakończyć program.\n");
  120.     }
  121. }
  122.  
  123. //Character
  124. package DecoChar;
  125. public abstract class Character {
  126.     String Name;
  127.     int HP = 0;
  128.     int Atk = 0;
  129.     int Def = 0;
  130.     ListEq Deco = ListEq.NONE;
  131.     Character[] CurrentEq = new Character[7];
  132.  
  133.     enum ListEq {
  134.         NONE,
  135.         GLOVES,
  136.         SHOES,
  137.         PANTS,
  138.         HELMET,
  139.         SWORD,
  140.         CHEST
  141.     }
  142.  
  143.     public void CheckStats() {
  144.         System.out.println("\n"+Name + ":");
  145.         System.out.println("Statystki postaci : ");
  146.         System.out.println("Hp: " + HP);
  147.         System.out.println("Atk: " + Atk);
  148.         System.out.println("Def: " + Def);
  149.         System.out.println();
  150.     }
  151.  
  152.     public void RemovDeco(Character MainChar) {
  153.         switch (Deco) {
  154.             case GLOVES:
  155.                 MainChar.AddHP(-Gloves.HP);
  156.                 MainChar.AddAtk(-Gloves.Atk);
  157.                 MainChar.AddDef(-Gloves.Def);
  158.                 break;
  159.             case SHOES:
  160.                 MainChar.AddHP(-Shoes.HP);
  161.                 MainChar.AddAtk(-Shoes.Atk);
  162.                 MainChar.AddDef(-Shoes.Def);
  163.                 break;
  164.             case PANTS:
  165.                 MainChar.AddHP(-Pants.HP);
  166.                 MainChar.AddAtk(-Pants.Atk);
  167.                 MainChar.AddDef(-Pants.Def);
  168.                 break;
  169.             case HELMET:
  170.                 MainChar.AddHP(-Helmet.HP);
  171.                 MainChar.AddAtk(-Helmet.Atk);
  172.                 MainChar.AddDef(-Helmet.Def);
  173.                 break;
  174.             case SWORD:
  175.                 MainChar.AddHP(-Sword.HP);
  176.                 MainChar.AddAtk(-Sword.Atk);
  177.                 MainChar.AddDef(-Sword.Def);
  178.                 break;
  179.             case CHEST:
  180.                 MainChar.AddHP(-Chest.HP);
  181.                 MainChar.AddAtk(-Chest.Atk);
  182.                 MainChar.AddDef(-Chest.Def);
  183.                 break;
  184.             default:
  185.                 break;
  186.         }
  187.     }
  188.  
  189.     public void setNazwa(String Name) {
  190.         this.Name = Name;
  191.     }
  192.  
  193.     public String getName() {
  194.         return this.Name;
  195.     }
  196.  
  197.     public void setHP(int HP) {
  198.         this.HP = HP;
  199.     }
  200.  
  201.     public void AddHP(int HP) {
  202.         this.HP += HP;
  203.     }
  204.  
  205.     public int getHP() {
  206.         return this.HP;
  207.     }
  208.  
  209.     public void setAtk(int ATK) {
  210.         this.Atk = ATK;
  211.     }
  212.  
  213.     public void AddAtk(int ATK) {
  214.         this.Atk += ATK;
  215.     }
  216.  
  217.     public int getAtk() {
  218.         return this.Atk;
  219.     }
  220.  
  221.     public void setDef(int Def) {
  222.         this.Def = Def;
  223.     }
  224.  
  225.     public void AddDef(int Def) {
  226.         this.Def += Def;
  227.     }
  228.  
  229.     public int getDef() {
  230.         return this.Def;
  231.     }
  232.  
  233.     public void setEq(Character[] EqList) {
  234.         CurrentEq = EqList;
  235.     }
  236. }
  237.  
  238. //MainCharacter
  239. package DecoChar;
  240.  
  241. public class MainCharacter extends Character {
  242.     public MainCharacter() {
  243.         setNazwa("Raziel");
  244.         setHP(100);
  245.         setAtk(15);
  246.         setDef(5);
  247.     }
  248. }
  249.  
  250. //Pants
  251. package DecoChar;
  252. public class Pants extends MainCharacter
  253. {
  254.     public static int HP = 8;
  255.     public static int Atk = 4;
  256.     public static int Def = 4;
  257.     public Pants(Character CharOb)
  258.     {
  259.         setHP(CharOb.getHP() + HP);
  260.         setAtk(CharOb.getAtk() + Atk);
  261.         setDef(CharOb.getDef() + Def);
  262.         setEq(CharOb.CurrentEq);
  263.     }
  264. }
  265.  
  266. //Shoes
  267. package DecoChar;
  268. public class Shoes extends MainCharacter
  269. {
  270.     public static int HP = 10;
  271.     public static int Atk = 1;
  272.     public static int Def = 2;
  273.     public Shoes(Character CharOb)
  274.     {
  275.         setHP(CharOb.getHP() + HP);
  276.         setAtk(CharOb.getAtk() + Atk);
  277.         setDef(CharOb.getDef() + Def);
  278.         setEq(CharOb.CurrentEq);
  279.     }
  280. }
  281.  
  282. //Sword
  283. package DecoChar;
  284. public class Sword extends MainCharacter
  285. {
  286.     public static int HP = 0;
  287.     public static int Atk = 20;
  288.     public static int Def = 10;
  289.     public Sword(Character CharOb)
  290.     {
  291.         setHP(CharOb.getHP() + HP);
  292.         setAtk(CharOb.getAtk() + Atk);
  293.         setDef(CharOb.getDef() + Def);
  294.         setEq(CharOb.CurrentEq);
  295.     }
  296. }
  297.  
  298. //Helmet
  299. package DecoChar;
  300. public class Helmet extends MainCharacter
  301. {
  302.     public static int HP = 20;
  303.     public static int Atk = 2;
  304.     public static int Def = 10;
  305.     public Helmet(Character CharOb)
  306.     {
  307.         setHP(CharOb.getHP() + HP);
  308.         setAtk(CharOb.getAtk() + Atk);
  309.         setDef(CharOb.getDef() + Def);
  310.         setEq(CharOb.CurrentEq);
  311.     }
  312. }
  313.  
  314. //Gloves
  315. package DecoChar;
  316. public class Gloves extends MainCharacter
  317. {
  318.     public static int HP = 3;
  319.     public static int Atk = 9;
  320.     public static int Def = 9;
  321.     public Gloves(Character CharOb)
  322.     {
  323.         setHP(CharOb.getHP() + HP);
  324.         setAtk(CharOb.getAtk() + Atk);
  325.         setDef(CharOb.getDef() + Def);
  326.         setEq(CharOb.CurrentEq);
  327.     }
  328. }
  329.  
  330. //Chest
  331. package DecoChar;
  332. public class Chest extends MainCharacter
  333. {
  334.     public static int HP = 30;
  335.     public static int Atk = 0;
  336.     public static int Def = 20;
  337.     public Chest(Character CharOb)
  338.     {
  339.         setHP(CharOb.getHP() + HP);
  340.         setAtk(CharOb.getAtk() + Atk);
  341.         setDef(CharOb.getDef() + Def);
  342.         setEq(CharOb.CurrentEq);
  343.     }
  344. }
Add Comment
Please, Sign In to add comment