import java.awt.*; public class SuperTetrisBuggle extends TetrisBuggle { // There are many ways to break down the patterns. /*************************************** * Auxiliary Methods for moving TetrisBuggles around ***************************************/ public void moveRight () { this.right(); this.forward(); } public void moveLeft () { this.left(); this.forward(); } public void moveBack () { this.right(); this.right(); this.forward(); } public void scootRight () { this.right(); this.forward(); this.left(); } public void scootLeft () { this.left(); this.forward(); this.right(); } public void scootRight (int n) { this.right(); this.forward(n); this.left(); } public void scootLeft (int n) { this.left(); this.forward(n); this.right(); } /*************************************** * Ways to create a 2 by 4 grid of color. * Assumes buggle starts at bottom left corner and * finishes at the same place. ***************************************/ public void doubleO () { this.O(); this.forward(2); this.O(); this.backward(2); } public void doubleI () { this.I(); this.scootLeft(); this.I(); this.scootRight(); } public void doubleJ () { this.forward(3); this.moveBack(); this.J(); this.scootRight(); this.forward(2); this.moveBack(); this.J(); this.scootRight(); this.backward(); } public void doubleL () { this.forward(); this.L(); this.scootLeft(); this.forward(2); this.moveBack(); this.L(); this.scootLeft(); this.moveBack(); this.backward(3); } /*************************************** * Ways to create 4 by 4 grids of color. * Assumes buggle starts at bottom left corner and * finishes at the same place. ***************************************/ public void cyanBlock () { this.doubleI(); this.scootLeft(2); this.doubleI(); this.scootRight(2); } public void grayBlock () { this.doubleO(); this.scootLeft(2); this.doubleO(); this.scootRight(2); } public void blueBlock () { this.doubleJ(); this.scootLeft(2); this.doubleJ(); this.scootRight(2); } public void yellowBlock () { this.left(); this.T(); this.nextT(); this.T(); this.nextT(); this.T(); this.nextT(); this.T(); this.nextT(); this.right(); } public void nextT () { this.forward(3); this.right(); } public void fourColorBlock () { this.I(); this.moveLeft(); this.J(); this.scootRight(); this.right(); this.O(); this.forward(2); this.left(); this.L(); this.backward(); this.right(); this.backward(3); } // a 2x10 gray line public void grayLine () { this.doubleO(); this.forward(4); this.doubleO(); this.forward(4); this.O(); this.backward(8); } /*************************************** * Methods for creating TetrisWorld1 * Strategy: * 1) Divide pattern into two "half patterns" and * the gray line in the middle * 2) Each "half pattern" is repeating a quarter pattern twice * 3) Each quarter pattern is a yellow block and an "I" ***************************************/ public void tetrisworld1 () { this.halfTetrisWorld1(); // draw first half this.left(); // move to start next half this.forward(9); this.left(); this.halfTetrisWorld1(); // draw second half this.left(); // move to draw gray line this.forward(5); this.left(); this.grayLine(); // draw gray line } public void halfTetrisWorld1 () { this.quarterTetrisWorld1(); this.forward(); this.quarterTetrisWorld1(); } public void quarterTetrisWorld1 () { this.yellowBlock(); this.forward(4); this.left(); this.I(); this.right(); } /*************************************** * Methods for creating TetrisWorld2 * Strategy: * 1) Divide pattern into two "half patterns" and * the gray line in the middle * 2) Each "half pattern" is a blue block, a double L, * and a cyan block. ***************************************/ public void tetrisworld2 () { this.halfTetrisWorld2(); // draw left half the world this.forward(6); // move to position to draw other half this.halfTetrisWorld2(); // draw right half of world this.backward(); // move to position to draw gray line this.left(); // turn to draw gray line this.grayLine(); // draw gray line } public void halfTetrisWorld2 () { this.blueBlock(); this.scootLeft(4); this.doubleL(); this.scootLeft(2); this.cyanBlock(); this.scootRight(6); } /*************************************** * Methods for creating TetrisWorld3 * Strategy: * 1) Divide pattern into two "half patterns" and * the gray line in the middle * 2) Each "half pattern" is a four color block and a three * color pattern which we will call "diamond" * 3) Each "diamond" can be divided into two halves (bottom * and top) which are identical but rotated. ***************************************/ public void tetrisworld3 () { this.halfTetrisWorld3(); this.forward(6); this.halfTetrisWorld3(); this.backward(); this.left(); this.grayLine(); } public void halfTetrisWorld3 () { this.fourColorBlock(); this.scootLeft(4); this.diamond(); this.scootRight(4); } public void diamond () { this.halfDiamond(); // bottom half this.forward(2); this.O(); // center of diamond this.forward(3); this.left(); this.backward(); this.halfDiamond(); // top half this.forward(5); // steps to go back to initial position this.left(); this.backward(); } public void halfDiamond () { this.forward(); this.left(); this.S(); this.scootRight(); this.Z(); } }