Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************************takto to pridavam************
- private Vector<Item> items = new Vector<Item>();
- public void addItem(Item item) {
- Item old = new Item();
- boolean used = false;
- for (Item element : items) {
- if (element.getPosition() == item.getPosition()) {
- used = true;
- old = element;
- }
- }
- if (used == false) {
- items.addElement(item);
- item.printInfo();
- System.out.println("pridan");
- } else {
- item.printInfo();
- int n = JOptionPane.showConfirmDialog(null,
- "Chcete nový předmět vyměnit za starý?"+
- "\nNový: " + "\nNázev: " + item.getName() + "\nUtok: " + item.getAttack() + "\nObrana: "+ item.getDefence() + "\nCharisma: " + item.getCharisma() +
- "\n\nStarý: " + "\nNázev: " + old.getName() + "\nUtok: " + old.getAttack() + "\nObrana: "+ old.getDefence() + "\nCharisma: " + old.getCharisma(),
- "Změna předmětu." +
- "",
- JOptionPane.YES_NO_OPTION);
- if (n == 0){
- old.setName(item.getName());
- old.setAttack(item.getAttack());
- old.setCharisma(item.getCharisma());
- old.setDefence(item.getDefence());
- System.out.println("ano");
- }
- }
- }
- //************************TOTO posílám*****************
- item.setName("Zlatá koruna");
- item.setAttack(4);
- item.setDefence(5);
- item.setCharisma(4);
- item.setPosition(E_position.POS_HEAD);
- player.addItem(item);
- //**********************Trida item**********************
- package cz.mendelu.pef.pjj.xhromek1;
- import javax.swing.JOptionPane;
- enum E_position {
- POS_HEAD, POS_CHEST, POS_LEGS
- }
- public class Item {
- private String name;
- private int attack;
- private int defence;
- private int charisma;
- private E_position position;
- void printInfo() {
- String s_position = new String();
- switch (this.position) {
- case POS_HEAD:
- s_position = "Prilba";
- break;
- case POS_CHEST:
- s_position = "Zbroj";
- break;
- case POS_LEGS:
- s_position = "Kalhoty";
- break;
- }
- JOptionPane.showMessageDialog(null, "Informace o predmetu '" + this.name
- + "'\nBonus do utoku: " + this.attack + "\nBonus do obrany: "
- + this.defence + "\nBonus do charisma: " + this.charisma
- + "\nTyp predmetu: "+ s_position);
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAttack() {
- return attack;
- }
- public void setAttack(int attack) {
- this.attack = attack;
- }
- public int getDefence() {
- return defence;
- }
- public void setDefence(int defence) {
- this.defence = defence;
- }
- public int getCharisma() {
- return charisma;
- }
- public void setCharisma(int charisma) {
- this.charisma = charisma;
- }
- public E_position getPosition() {
- return position;
- }
- public void setPosition(E_position position) {
- this.position = position;
- }
- }
Add Comment
Please, Sign In to add comment