Guest User

Untitled

a guest
Jan 20th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Graphics2D;
  4.  
  5. public class MapGenerator
  6. {
  7. public int map[][];
  8. public int brickWidth;
  9. public int brickHeight;
  10.  
  11. public MapGenerator (int row, int col)
  12. {
  13. map = new int[row][col];
  14. for(int i = 0; i<map.length; i++)
  15. {
  16. for(int j =0; j<map[0].length; j++)
  17. {
  18. map[i][j] = 1;
  19. }
  20. }
  21.  
  22. brickWidth = 540/col;
  23. brickHeight = 150/row;
  24. }
  25.  
  26. public void draw(Graphics2D g)
  27. {
  28. for(int i = 0; i<map.length; i++)
  29. {
  30. for(int j =0; j<map[0].length; j++)
  31. {
  32. if(map[i][j] > 0)
  33. {
  34. g.setColor(Color.white);
  35. g.fillRect(j * brickWidth + 80, i * brickHeight + 50, brickWidth, brickHeight);
  36.  
  37. // this is just to show separate brick, game can still run without it
  38. g.setStroke(new BasicStroke(3));
  39. g.setColor(Color.black);
  40. g.drawRect(j * brickWidth + 80, i * brickHeight + 50, brickWidth, brickHeight);
  41. }
  42. }
  43. }
  44. }
  45.  
  46. public void setBrickValue(int value, int row, int col)
  47. {
  48. map[row][col] = value;
  49. }
  50. }
Add Comment
Please, Sign In to add comment