BenitoDannes

uas-brickbreaker-mapgenerator

Jun 6th, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.awt.Graphics2D;
  2. import java.awt.Color;
  3. import java.awt.BasicStroke;
  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.  
  15. for (int i = 0; i < map.length; i++)
  16. {
  17. for (int j = 0; j < map[0].length; j++)
  18. {
  19. map[i][j] =1;
  20. }
  21. }
  22.  
  23. brickWidth = 540/col;
  24. brickHeight = 150/row;
  25. }
  26.  
  27. public void draw (Graphics2D g)
  28. {
  29. for (int i = 0; i < map.length; i++)
  30. {
  31. for (int j = 0; j < map[0].length; j++)
  32. {
  33. if (map[i][j] > 0)
  34. {
  35. g.setColor (Color.white);
  36. g.fillRect (j * brickWidth + 80, i * brickHeight + 50, brickWidth, brickHeight);
  37.  
  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. }
Advertisement
Add Comment
Please, Sign In to add comment