Itembar System: itembar - UQdeco2800/2021-ext-studio-2 GitHub Wiki

Itembar System

Relevant Files:

newItembar

  • newItembar.java: the finalized java class of item bar
public newItembar() {
       waters = new ArrayList<>();
       foods = new ArrayList<>();
       kits = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            waters.add("water");
            foods.add("food");
            kits.add("kit");
        }
    }

KeyboardInput

  • KeyboardPlayerInputComponent.java: Responsible for control the use of item.

      press J to use health-kit
    
case Keys.J:
        newItembar.usekit();
        if(entity.getComponent(CombatStatsComponent.class).getHealth() < 100){
          entity.getComponent(CombatStatsComponent.class).addHealth(10);
        }
        return true;
    press L to use food
      case Keys.L:
        newItembar.usefood();
        FoodDisplay.addOrRemoveImage(1);
        return true;
    press K to use water
      case Keys.K:
        newItembar.usewater();
        WaterDisplay.addOrRemoveImage(1);
        return true;

UI Components

  • ItemBarDisplay.java: Responsible for displays the itembar UI on the screen.
/* Listen to itembar events*/
entity.getEvents().addListener("updateitembar", this::updateItemBarUI);
    /**
     * Creates reusable ui styles and adds actors to the stage.
     */
    @Override
    public void create() {
        super.create();
        addActors();
        entity.getEvents().addListener("updateitembar", this::updateItemBarUI);
    }
        public void updateItemBarUI() {
        CharSequence text = bar.getcounts();
        countlabel.setText(text);
    }
@Override
    public void dispose() {
        super.dispose();
        countlabel.remove();
        counttable.remove();
    }

UML Diagrams

UML class diagram

For displaying itembar.
uml

Sequence diagram - add kit

sequence-addkit

Sequence diagram - use kit

usekit

Sequence diagram - use water

usewater

Sequence diagram - use food

usefood

⚠️ **GitHub.com Fallback** ⚠️