All pastes #171092 Raw Edit

Logi

public java v1 · immutable
·published 2006-09-15 00:48 UTC
rendered paste body
import becker.robots.*;class WriterBot extends RobotSE {        public WriterBot(City aCity, int aStreet, int anAvenue, Direction aDirection, int numThings){                super(aCity, aStreet, anAvenue, aDirection, numThings);        }        private void uRight(){                this.turnRight();                this.move();                this.turnRight();        }        private void uRight(int howWide){                this.turnRight();                this.move(howWide);                this.turnRight();        }        private void uLeft(){                this.turnLeft();                this.move();                this.turnLeft();        }        private void uLeft(int howWide){                this.turnLeft();                this.move(howWide);                this.turnLeft();        }        private void moveBack(){                this.move();                this.turnLeft();                this.move(4);                this.turnRight();                this.move();        }        private void writeLine(int[] inputLine, boolean rev){                if (rev == true){                        for (int i = (inputLine.length - 1); i > -1; i--){                                if ((inputLine[i] == 1) && (i == 0)){                                        this.putThing();                                }                                else if ((inputLine[i] == 1) && (i > 0)){                                        this.putThing();                                        this.move();                                }                                else if ((inputLine[i] == 0) && (i > 0)){                                        this.move();                                }                                else continue;                        }                }                else if (rev == false){                        for (int i = 0; i < inputLine.length; i++){                                if ((inputLine[i] == 1) && (i == 4)){                                        this.putThing();                                }                                else if ((inputLine[i] == 1) && (i < 4)){                                        this.putThing();                                        this.move();                                }                                else if ((inputLine[i] == 0) && (i < 4)){                                        this.move();                                }                                else continue;                        }                }        }        public void writeLetter(char letter){                int selectedLetter = (letter != ' ') ? (((int) letter) - 'A') : 26;                                int letterGridMatrix[][][] = {                        {{0,1,1,1,0}, {1,0,0,0,1}, {1,1,1,1,1}, {1,0,0,0,1}, {1,0,0,0,1}}, // A                        {{1,1,1,1,0}, {1,0,0,0,1}, {1,1,1,1,0}, {1,0,0,0,1}, {1,1,1,1,0}}, // B                        {{1,1,1,1,1}, {1,0,0,0,0}, {1,0,0,0,0}, {1,0,0,0,0}, {1,1,1,1,1}}, // C                        {{1,1,1,1,0}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {1,1,1,1,0}}, // D                        {{1,1,1,1,1}, {1,0,0,0,0}, {1,1,1,1,0}, {1,0,0,0,0}, {1,1,1,1,1}}, // E                        {{1,1,1,1,1}, {1,0,0,0,0}, {1,1,1,0,0}, {1,0,0,0,0}, {1,0,0,0,0}}, // F                        {{1,1,1,1,0}, {1,0,0,0,0}, {1,0,0,1,1}, {1,0,0,0,1}, {1,1,1,1,1}}, // G                        {{1,0,0,0,1}, {1,0,0,0,1}, {1,1,1,1,1}, {1,0,0,0,1}, {1,0,0,0,1}}, // H                        {{1,1,1,1,1}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}, {1,1,1,1,1}}, // I                        {{0,0,0,1,1}, {0,0,0,0,1}, {0,0,0,0,1}, {1,0,0,0,1}, {1,1,1,1,1}}, // J                        {{1,0,0,0,1}, {1,0,0,1,0}, {1,1,1,0,0}, {1,0,0,1,0}, {1,0,0,0,1}}, // K                        {{1,0,0,0,0}, {1,0,0,0,0}, {1,0,0,0,0}, {1,0,0,0,0}, {1,1,1,1,1}}, // L                        {{1,0,0,0,1}, {1,1,0,1,1}, {1,0,1,0,1}, {1,0,0,0,1}, {1,0,0,0,1}}, // M                        {{1,0,0,0,1}, {1,1,0,0,1}, {1,0,1,0,1}, {1,0,0,1,1}, {1,0,0,0,1}}, // N                        {{1,1,1,1,1}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {1,1,1,1,1}}, // O                        {{1,1,1,1,0}, {1,0,0,0,1}, {1,1,1,1,0}, {1,0,0,0,0}, {1,0,0,0,0}}, // P                        {{1,1,1,1,0}, {1,0,0,1,0}, {1,0,0,1,0}, {1,1,1,1,0}, {0,0,0,0,1}}, // Q                        {{1,1,1,1,0}, {1,0,0,0,1}, {1,1,1,1,0}, {1,0,0,1,0}, {1,0,0,0,1}}, // R                        {{0,1,1,1,1}, {1,0,0,0,0}, {0,1,1,1,0}, {0,0,0,0,1}, {1,1,1,1,0}}, // S                        {{1,1,1,1,1}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}}, // T                        {{1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {0,1,1,1,0}}, // U                        {{1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {0,1,0,1,0}, {0,0,1,0,0}}, // V                        {{1,0,0,0,1}, {1,0,0,0,1}, {1,0,1,0,1}, {1,1,0,1,1}, {1,0,0,0,1}}, // W                        {{1,0,0,0,1}, {0,1,0,1,0}, {0,0,1,0,0}, {0,1,0,1,0}, {1,0,0,0,1}}, // X                        {{1,0,0,0,1}, {0,1,0,1,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}}, // Y                        {{1,1,1,1,1}, {0,0,0,1,0}, {0,0,1,0,0}, {0,1,0,0,0}, {1,1,1,1,1}}, // Z                        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}  // SPACE                };                                                for (int i = 0; i < letterGridMatrix[selectedLetter].length; i++){                        if (i % 2 == 0){                                this.writeLine(letterGridMatrix[selectedLetter][i], false);                                if (i == (letterGridMatrix[selectedLetter].length - 1)){                                        this.moveBack();                                }                                else this.uRight();                        }                        else if (i % 2 != 0){                                this.writeLine(letterGridMatrix[selectedLetter][i], true);                                this.uLeft();                        }                        else continue;                }        }}public class HomeworkLab2 {        public static void main(String args[]){                City columbia = new City();                WriterBot robot1 = new WriterBot(columbia, 0, 0, Direction.EAST, 500);                /*for (char i = 'A'; i <= 'Z'; i++){                        robot1.writeLetter(i);                }*/                robot1.writeLetter('M');                robot1.writeLetter('W');                robot1.writeLetter('C');                }}