Guest User

Untitled

a guest
Apr 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. //************************takto to pridavam************
  2.  
  3. private Vector<Item> items = new Vector<Item>();
  4.  
  5.     public void addItem(Item item) {
  6.         Item old = new Item();
  7.         boolean used = false;
  8.         for (Item element : items) {
  9.             if (element.getPosition() == item.getPosition()) {
  10.                 used = true;
  11.                 old = element;
  12.             }
  13.         }
  14.         if (used == false) {
  15.             items.addElement(item);
  16.             item.printInfo();
  17.             System.out.println("pridan");
  18.         } else {
  19.             item.printInfo();
  20.             int n = JOptionPane.showConfirmDialog(null,
  21.                     "Chcete nový předmět vyměnit za starý?"+
  22.                     "\nNový: " + "\nNázev: " + item.getName() + "\nUtok: " + item.getAttack() + "\nObrana: "+ item.getDefence() + "\nCharisma: " + item.getCharisma() +
  23.                     "\n\nStarý: " + "\nNázev: " + old.getName() + "\nUtok: " + old.getAttack() + "\nObrana: "+ old.getDefence() + "\nCharisma: " + old.getCharisma(),
  24.                     "Změna předmětu." +
  25.                             "",
  26.                     JOptionPane.YES_NO_OPTION);
  27.             if (n == 0){
  28.                 old.setName(item.getName());
  29.                 old.setAttack(item.getAttack());
  30.                 old.setCharisma(item.getCharisma());
  31.                 old.setDefence(item.getDefence());
  32.                 System.out.println("ano");
  33.             }
  34.         }
  35.  
  36.     }
  37.  
  38.  
  39.  
  40. //************************TOTO posílám*****************
  41.  
  42.             item.setName("Zlatá koruna");
  43.             item.setAttack(4);
  44.             item.setDefence(5);
  45.             item.setCharisma(4);
  46.             item.setPosition(E_position.POS_HEAD);
  47.             player.addItem(item);
  48.  
  49. //**********************Trida item**********************
  50.  
  51.  
  52. package cz.mendelu.pef.pjj.xhromek1;
  53.  
  54. import javax.swing.JOptionPane;
  55.  
  56. enum E_position {
  57.     POS_HEAD, POS_CHEST, POS_LEGS
  58. }
  59.  
  60. public class Item {
  61.  
  62.     private String name;
  63.     private int attack;
  64.     private int defence;
  65.     private int charisma;
  66.     private E_position position;
  67.  
  68.    
  69.     void printInfo() {
  70.         String s_position = new String();
  71.         switch (this.position) {
  72.         case POS_HEAD:
  73.             s_position = "Prilba";
  74.             break;
  75.         case POS_CHEST:
  76.             s_position = "Zbroj";
  77.             break;
  78.         case POS_LEGS:
  79.             s_position = "Kalhoty";
  80.             break;
  81.         }
  82.         JOptionPane.showMessageDialog(null, "Informace o predmetu '" + this.name
  83.                 + "'\nBonus do utoku: " + this.attack + "\nBonus do obrany: "
  84.                 + this.defence + "\nBonus do charisma: " + this.charisma
  85.                 + "\nTyp predmetu: "+ s_position);
  86.             }
  87.  
  88.     public String getName() {
  89.         return name;
  90.     }
  91.  
  92.     public void setName(String name) {
  93.         this.name = name;
  94.     }
  95.  
  96.     public int getAttack() {
  97.         return attack;
  98.     }
  99.  
  100.     public void setAttack(int attack) {
  101.         this.attack = attack;
  102.     }
  103.  
  104.     public int getDefence() {
  105.         return defence;
  106.     }
  107.  
  108.     public void setDefence(int defence) {
  109.         this.defence = defence;
  110.     }
  111.  
  112.     public int getCharisma() {
  113.         return charisma;
  114.     }
  115.  
  116.     public void setCharisma(int charisma) {
  117.         this.charisma = charisma;
  118.     }
  119.  
  120.     public E_position getPosition() {
  121.         return position;
  122.     }
  123.  
  124.     public void setPosition(E_position position) {
  125.         this.position = position;
  126.     }
  127.  
  128. }
Add Comment
Please, Sign In to add comment