Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

PlantUML Macro
interface GridProvider {
    public int getGridWidth()
    public int getGridHeight()
    public Object getGridElement(int x, int y)
    public void addGridListener(GridListener gridListener)
    public void removeGridListener(GridListener gridListener)
}

interface GridListener {
    void gridChanged(GridProvider grid, int x, int y, int w, int h)
}

class DinRutenettklasse {
}

GridProvider <|-- DinRutenettklasse
DinRutenettklasse --> "*" GridListener: gridListeners
Code Block
languagejava
collapsetrue
public interface GridProvider {
    
    /**
     * Gets the width (number of columns) of the grid
     * @return the width of the grid
     */
    public int getGridWidth();
    /**
     * Gets the height (number of rows) of the grid
     * @return the height of the grid
     */
    public int getGridHeight();
    /**
     * Gets the element at the specified x (column) and y (row) position 
     * @param x the x-coordinate of the element
     * @param y the y-coordinate of the element
     * @return the object at the specified position
     */
    public Object getGridElement(int x, int y);
    /**
     * Adds the listener, so it will be notified when the grid changes
     * @param gridListener the listener to add
     */
    public void addGridListener(GridListener gridListener);
    /**
     * Removes the listener, so it no longer will be notified when the grid changes
     * @param gridListener the listener to remove
     */
    public void removeGridListener(GridListener gridListener);
}

public interface GridListener {
    /**
     * Notifies the listener that the grid has changed. The changed region is a rectangle at x,y with dimensions w,h.
     * @param grid the grid that has changed
     * @param x the x coordinate of the changed rectangle
     * @param y the y coordinate of the changed rectangle
     * @param w the width of the changed rectangle
     * @param h the height of the changed rectangle
     */
    public void gridChanged(GridProvider grid, int x, int y, int w, int h);
}

Metodene i GridProvider er som følger:

  • int getGridWidth() - returnerer bredden eller antall kolonner i rutenettet, f.eks. 3 for standard Tic Tac Toe
  • int getGridHeight() - returnerer høyden eller antall rader i rutenettet, f.eks. 3 for standard Tic Tac Toe
  • Object getGridElement(int x, int y) - returnerer objektet som er lagret i en bestemt rute angitt med x,y-koordinater (altså kolonne,rad). Dette kan være noe så enkelt som et tegn, f.eks. 'x', 'o' eller ' ' for Tic Tac Toe, eller noe mer komplisert for Sudoku. Object brukes som returtype, for å kunne håndtere alle type spill og implementasjoner.
  • void addGridListener(GridListener) - registrere en lytter skal skal få beskjed hver gang rutenettet endres
  • void removeGridListener(GridListener) - avregistrere en lytter som tidligere er registrert med addGridListener

 

...