fork download
  1. package world;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.awt.geom.Point2D;
  7. import java.awt.image.BufferedImage;
  8.  
  9. import main.Render;
  10.  
  11. public class Chunk implements ScreenComponent{
  12. private final Point loc;
  13.  
  14. private volatile Village village;
  15.  
  16. private volatile int biome, resources;
  17. public static final int BIOME_BARREN = 0, BIOME_FOREST = 1;
  18. public static final int RSRCE_NOTHING = 0, RSRCE_WOOD = 1;
  19. public static final int NUM_RSRCE_TYPES = 1, NUM_BIOMES = 2;
  20. /** stores the resource type associated with a specific biome */
  21. private static final int[] biomeRsrceType = {RSRCE_NOTHING, RSRCE_WOOD};
  22.  
  23. /** the length of the chunk in buildings. ie. the number of buildings per chunk*/
  24. public static final int lengthOfChunk = 16;
  25.  
  26. public Chunk(int biome, int initResources, Point loc) {
  27. this.loc = loc;
  28. this.setBiome(biome);
  29. this.setResources(initResources);
  30. }
  31.  
  32. public void addVillage(Village v)
  33. {
  34. this.village = v;
  35. }
  36.  
  37. public void update()
  38. {
  39.  
  40. }
  41.  
  42. @Override
  43. public BufferedImage draw()
  44. {
  45. BufferedImage image = new BufferedImage(Chunk.getPixelLength(), Chunk.getPixelLength(), BufferedImage.TYPE_INT_ARGB);
  46. Graphics2D gI = image.createGraphics();
  47. if (Render.drawChunkBoundaries)
  48. {
  49. if (village == null)
  50. {
  51. gI.setColor(Color.black);
  52. }
  53. else
  54. {
  55. gI.setColor(Village.chunkBoundColor);
  56. }
  57. gI.drawRect(0, 0, Chunk.getPixelLength()-1, Chunk.getPixelLength()-1);
  58. }
  59.  
  60. if (village != null)
  61. {
  62. gI.drawImage(village.draw((int)(getX()-village.getX()+village.getRelativeChunkCenter().getX()), (int)(getY()-village.getY()+village.getRelativeChunkCenter().getY())), 0, 0, Chunk.getPixelLength(), Chunk.getPixelLength(), null);
  63. }
  64. return image;
  65. }
  66.  
  67. public void setResources(int resources) {this.resources = resources;}
  68.  
  69. public int getBiome() {return biome;}
  70. public void setBiome(int biome) {this.biome = biome;}
  71.  
  72. public int getRsrceType() {return biomeRsrceType[this.getBiome()];}
  73.  
  74. public int getNumRsrces() {return resources;}
  75.  
  76. public static int getPixelLength(){return lengthOfChunk*Building.lengthOfBuilding;}
  77.  
  78. public void harvest(int quantity, Villager villager)
  79. {
  80. resources -= quantity;
  81. villager.getProffession().setRsrceQuantity(villager.getProffession().getRsrceQuantity() + quantity);
  82. }
  83.  
  84. public boolean hasVillage() { return village != null; }
  85. public Village getVillage() { return village; }
  86.  
  87. /**
  88. * returns the coordinates of this chunk relative to the origin (measured in chunks
  89. * @return the coordinates of this chunk
  90. */
  91. public Point getCoords() { return loc; }
  92. public int getX() { return loc.x; }
  93. public int getY() { return loc.y; }
  94. }
  95.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:11: error: class Chunk is public, should be declared in a file named Chunk.java
public class Chunk implements ScreenComponent{
       ^
Main.java:9: error: package main does not exist
import main.Render;
           ^
Main.java:11: error: cannot find symbol
public class Chunk implements ScreenComponent{
                              ^
  symbol: class ScreenComponent
Main.java:14: error: cannot find symbol
	private volatile Village village;
	                 ^
  symbol:   class Village
  location: class Chunk
Main.java:32: error: cannot find symbol
	public void addVillage(Village v)
	                       ^
  symbol:   class Village
  location: class Chunk
Main.java:78: error: cannot find symbol
	public void harvest(int quantity, Villager villager)
	                                  ^
  symbol:   class Villager
  location: class Chunk
Main.java:85: error: cannot find symbol
	public Village getVillage() { return village; }
	       ^
  symbol:   class Village
  location: class Chunk
Main.java:42: error: method does not override or implement a method from a supertype
	@Override
	^
Main.java:47: error: cannot find symbol
		if (Render.drawChunkBoundaries)
		    ^
  symbol:   variable Render
  location: class Chunk
Main.java:47: error: illegal start of type
		if (Render.drawChunkBoundaries)
		   ^
Main.java:55: error: cannot find symbol
				gI.setColor(Village.chunkBoundColor);
				            ^
  symbol:   variable Village
  location: class Chunk
Main.java:76: error: cannot find symbol
	public static int getPixelLength(){return lengthOfChunk*Building.lengthOfBuilding;}
	                                                        ^
  symbol:   variable Building
  location: class Chunk
12 errors
stdout
Standard output is empty