Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1.  
  2. class Game extends GridContainer {
  3.     private World world = new World(this);
  4.     private HUD hud = new HUD(this);
  5.    
  6.     public Game() {
  7.         add(world, 0, 0);
  8.         add(hud, 0, 1);
  9.     }
  10. }
  11.  
  12. class World extends GridContainer {
  13.     private final Game game;
  14.    
  15.     private UnitManager unitManager = new UnitManager();
  16.     private ResourceManager resourceManager = new ResourceManager();
  17.     private LandManager landManager = new LandManager();
  18.    
  19.     public World(Game game) {
  20.         this.game = game;
  21.        
  22.         //add land from land manager; logic still being worked out
  23.     }
  24. }
  25.  
  26. class HUD extends GridContainer {
  27.     private final Game game;
  28.    
  29.     //CurrentLandBox landBox;
  30.     //ActionBox actionBox;
  31.     //...
  32.    
  33.     public HUD(Game game) {
  34.         this.game = game;
  35.         //add boxes
  36.     }
  37. }
  38.  
  39. class LandManager {
  40.     //similar to UnitManager
  41. }
  42.  
  43. class ResourceManager {
  44.     //similar to UnitManager
  45. }
  46.  
  47. class UnitManager {
  48.     private ArrayList<Explorer> explorers = new ArrayList<>();
  49.     private ArrayList<Inspector> inspectors = new ArrayList<>();
  50.    
  51.     public void update() {
  52.         explorers.forEach(explorer -> {
  53.             explorer.update();
  54.         });
  55.         inspectors.forEach(inspector -> {
  56.             inspector.update();
  57.         });
  58.     }
  59. }
  60.  
  61. class Land extends VComponent {
  62.     private HashSet<Resource> resources = new HashSet<>();
  63.     private LandType type;
  64.    
  65.     public void update() {
  66.         //update resources
  67.     }
  68.    
  69.     public void render(Graphics g) {
  70.         g.setColor(type.color);
  71.         g.fillRect(getX(), getY(), getWidth(), getHeight());
  72.     }
  73.    
  74.     public static enum LandType {
  75.         UNIDENTIFIED(Color.LIGHT_GREY),
  76.         FLATLAND(Color.GREEN);
  77.        
  78.         public final Color color;
  79.        
  80.         LandType(Color color) {
  81.             this.color = color;
  82.         }
  83.     }
  84. }
  85.  
  86. abstract class VComponent {
  87.     private int x, y, width, height;
  88.    
  89.     protected final void setBounds(int x, int y, int width, int height) { }
  90.     protected final void setSize(int width, int height) { }
  91.     protected final void setLocation(int x, int y) { }
  92.    
  93.     public int getWidth() {
  94.         return width;
  95.     }
  96.    
  97.     public int getHeight() {
  98.         return height;
  99.     }
  100.    
  101.     public int getX() {
  102.         return x;
  103.     }
  104.    
  105.     public int getY() {
  106.         return y;
  107.     }
  108.    
  109.     public abstract void update();
  110.     public abstract void render(Graphics g);
  111. }
  112.  
  113. abstract class VContainer extends VComponent {
  114.     protected ArrayList<VComponent> components = new ArrayList<>();
  115.    
  116.     public void update() {
  117.         components.forEach(comp -> {
  118.             comp.update();
  119.         });
  120.     }
  121.    
  122.     public final void render(Graphics g) {
  123.         components.forEach(comp -> {
  124.             comp.render(g);
  125.         });
  126.     }
  127.    
  128.     public abstract void add(VComponent comp);
  129. }
  130.  
  131. class GridContainer extends VContainer {
  132.     public void add(VComponent comp) {
  133.         //default; loops through list, find empty space, placeComponent
  134.     }
  135.    
  136.     public void add(VComponent comp, int x, int y) {
  137.         add(comp, x, y, 1, 1);
  138.     }
  139.    
  140.     public void add(VComponent comp, int x, int y, int rowSpan, int colSpan) {
  141.         //logic to find placement
  142.     }
  143.    
  144.     private void placeComponent(VComponent comp, int x, int y, int rowSpan, int colSpan) {
  145.         //places component in a wrapped instance containing grid properties
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement