Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package robot.ascii.impl;
- import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame;
- public class Block implements Drawable
- {
- private int xpos;
- private int ypos;
- private int blockHeight;
- public Block(int blockHeight, int xpos, int ypos) {
- this.xpos = xpos; //the 'x' values
- this.ypos = ypos; //the 'y' values
- this.blockHeight = blockHeight;
- }
- @Override
- public void draw(SwingTerminalFrame terminalFrame)
- {
- int MaxBlockRow = terminalFrame.getTerminalSize().getRows()-1;
- if(blockHeight == 1) {
- terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
- terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
- }
- if(blockHeight == 2) {
- terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
- terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
- }
- if(blockHeight == 3) {
- terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
- terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
- }
- if(blockHeight > 3) {
- terminalFrame.setForegroundColor(Drawable.BLOCK_COLORS_FG[blockHeight - 1]);
- terminalFrame.setBackgroundColor(Drawable.BLOCK_COLORS_BG[blockHeight - 1]);
- }
- //looping through all blockHeights and assigning characters
- for (int star = 0; star < blockHeight; star++) {
- terminalFrame.setCursorPosition(xpos, MaxBlockRow- ypos - star);
- terminalFrame.putCharacter('+');
- }
- }
- //positioning of x
- public int getX() {
- return xpos;
- }
- //positioning of y
- public int getY() {
- return ypos;
- }
- public int getHeight() {
- return blockHeight;
- }
- public int getTop() {
- return ypos + blockHeight;
- }
- public void up() {
- ypos++;
- }
- public void down() {
- ypos--;
- }
- public void left() {
- xpos--;
- }
- public void right() {
- xpos++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement