Advertisement
Guest User

block

a guest
Oct 17th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. package robot.ascii.impl;
  2.  
  3. import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame;
  4.  
  5. public class Block implements Drawable
  6. {
  7. private int xpos;
  8. private int ypos;
  9. private int blockHeight;
  10.  
  11.  
  12.  
  13. public Block(int blockHeight, int xpos, int ypos) {
  14. this.xpos = xpos; //the 'x' values
  15. this.ypos = ypos; //the 'y' values
  16. this.blockHeight = blockHeight;
  17. }
  18.  
  19. @Override
  20. public void draw(SwingTerminalFrame terminalFrame)
  21. {
  22. int MaxBlockRow = terminalFrame.getTerminalSize().getRows()-1;
  23.  
  24. if(blockHeight == 1) {
  25. terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
  26. terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
  27. }
  28.  
  29. if(blockHeight == 2) {
  30. terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
  31. terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
  32. }
  33.  
  34. if(blockHeight == 3) {
  35. terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
  36. terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
  37. }
  38. if(blockHeight > 3) {
  39. terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
  40. terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
  41. }
  42. //looping through all blockHeights and assigning characters
  43. for (int star = 0; star < blockHeight; star++) {
  44. terminalFrame.setCursorPosition(xpos, MaxBlockRow- ypos - star);
  45. terminalFrame.putCharacter('+');
  46.  
  47. }
  48.  
  49. }
  50.  
  51. //positioning of x
  52. public int getX() {
  53. return xpos;
  54. }
  55. //positioning of y
  56. public int getY() {
  57. return ypos;
  58. }
  59. public int getHeight() {
  60. return blockHeight;
  61. }
  62.  
  63. public int getTop() {
  64. return ypos + blockHeight;
  65. }
  66. public void up() {
  67. ypos++;
  68. }
  69. public void down() {
  70. ypos--;
  71. }
  72. public void left() {
  73. xpos--;
  74. }
  75. public void right() {
  76. xpos++;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement