Class World

  • All Implemented Interfaces:
    java.awt.event.KeyListener, java.util.EventListener

    public class World
    extends java.lang.Object
    implements java.awt.event.KeyListener
    The world map, containing all regions, cities and cables.
    Author:
    Juno Veenstra
    • Constructor Summary

      Constructors 
      Constructor Description
      World​(sag.SAGPanel panel, Region[] regions)
      Create, move and scale regions and city to be centered on the map
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearCityHighlights()
      Clear all city highlighting
      void clearRegionHighlights()
      Clear all region highlighting
      void highlightCities​(java.lang.String cityA)
      Highlights one city
      void highlightCities​(java.lang.String cityA, java.lang.String cityB)
      Highlights two cities
      void highlightCitiesWeak​(java.util.Vector<City> cities, boolean clearFirst)
      Highlights an array of cities dimly, used for showing cities in range
      void highlightRegion​(java.lang.String regionName)
      Highlight the given region.
      void keyPressed​(java.awt.event.KeyEvent e)
      Register key presses for navigation
      void keyReleased​(java.awt.event.KeyEvent e)  
      void keyTyped​(java.awt.event.KeyEvent e)  
      void moveScreen​(float x, float y)
      Move every city and polygon by a specific amount
      World onCityClick​(java.util.function.Consumer<GCity> action)
      This event is triggered when a city is clicked
      void placeCable​(City a, City b, CableConfig c, java.awt.Color color, java.lang.String name, int amount)
      Create a cable to be placed in the map
      void removeRangeCircles()
      Method for removing/resetting the range circles by deleting each circle
      void resetScreenTransform()
      Method for setting the screen scaling and position to the default state where the entire map is visible and centered
      void scaleScreen​(float scale)
      Scale all layers by a certain factor
      void showRangeCircles​(float x, float y, int cableCount, float cableRange, float maxRange)
      Method for creating circles around a city depicting the range at which you can build
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • World

        public World​(sag.SAGPanel panel,
                     Region[] regions)
        Create, move and scale regions and city to be centered on the map
        Parameters:
        panel - SAGPanel to be draw
        regions - Array of regions
    • Method Detail

      • moveScreen

        public void moveScreen​(float x,
                               float y)
        Move every city and polygon by a specific amount
        Parameters:
        x - X movement
        y - Y movement
      • scaleScreen

        public void scaleScreen​(float scale)
        Scale all layers by a certain factor
        Parameters:
        scale - The scaling to be applied
      • resetScreenTransform

        public void resetScreenTransform()
        Method for setting the screen scaling and position to the default state where the entire map is visible and centered
      • placeCable

        public void placeCable​(City a,
                               City b,
                               CableConfig c,
                               java.awt.Color color,
                               java.lang.String name,
                               int amount)
        Create a cable to be placed in the map
        Parameters:
        a - Start City
        b - End City
        c - Cable type
        color - Player color
        name - Player name
        amount - Amount of cables used (reflected in the amount of icons used in the cable)
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent e)
        Register key presses for navigation
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Parameters:
        e - the event to be processed
      • showRangeCircles

        public void showRangeCircles​(float x,
                                     float y,
                                     int cableCount,
                                     float cableRange,
                                     float maxRange)
        Method for creating circles around a city depicting the range at which you can build
        Parameters:
        x - The x position around which the circles get drawn
        y - The y position around which the circles get drawn
        cableCount - The amount of cables of this type in the players inventory, more cables mean more range
        cableRange - The range a single cable can go
        maxRange - The maximum range cables can go combined
      • removeRangeCircles

        public void removeRangeCircles()
        Method for removing/resetting the range circles by deleting each circle
      • highlightRegion

        public void highlightRegion​(java.lang.String regionName)
        Highlight the given region. (Dims every other region)
        Parameters:
        regionName - Region to be highlighted
      • highlightCities

        public void highlightCities​(java.lang.String cityA)
        Highlights one city
        Parameters:
        cityA - First city to be highlighted
      • highlightCities

        public void highlightCities​(java.lang.String cityA,
                                    java.lang.String cityB)
        Highlights two cities
        Parameters:
        cityA - First city to be highlighted
        cityB - Second city to be highlighted
      • highlightCitiesWeak

        public void highlightCitiesWeak​(java.util.Vector<City> cities,
                                        boolean clearFirst)
        Highlights an array of cities dimly, used for showing cities in range
        Parameters:
        cities - Cities to be highlighted
        clearFirst - Whether to clear previous highlights first, which can cause issues when highlightCities(String) is called first
      • clearRegionHighlights

        public void clearRegionHighlights()
        Clear all region highlighting
      • clearCityHighlights

        public void clearCityHighlights()
        Clear all city highlighting
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent e)
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
      • keyReleased

        public void keyReleased​(java.awt.event.KeyEvent e)
        Specified by:
        keyReleased in interface java.awt.event.KeyListener
      • onCityClick

        public World onCityClick​(java.util.function.Consumer<GCity> action)
        This event is triggered when a city is clicked
        Parameters:
        action - The action to be taken when a player clicks a city
        Returns:
        The World (for chaining methods)