Last active
October 10, 2019 16:37
-
-
Save Jordan-Cottle/03a982c6feccd004a585866358de0eab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.util.Scanner; | |
public class ATest{ | |
private static final int WORLD_WIDTH = 800; | |
private static final int WORLD_HEIGHT = 650; | |
private static World w; | |
private static Turtle t; | |
private static Scanner in = new Scanner(System.in); | |
private static boolean bold = false; | |
private static int size = 1; | |
private static int level = 1; | |
public static void main(String[] args) { | |
newWorld(); | |
for (int letter = 1; letter <= 4;){ | |
Color c = new Color((float)Math.random(), (float)Math.random(),(float) Math.random()); | |
System.out.println("" + c + " " + bold + " " + size); | |
lineWrap(size); | |
switch(letter){ | |
case 1: | |
drawLetter1(c, bold, size); | |
break; | |
case 2: | |
drawLetter2(c, bold, size); | |
break; | |
case 3: | |
drawLetter3(c, bold, size); | |
break; | |
case 4: | |
drawLetter4(c, bold, size); | |
break; | |
default: | |
System.out.println("" + letter + " not recognized!"); | |
} | |
System.out.println("Enter 'f', 'r', 'c', 'b', 's', 'l' or nothing to continue: "); | |
String choice = in.nextLine().toLowerCase(); // Wait for user to press enter | |
if (choice.length() > 0){ | |
for(char option: choice.toCharArray()){ | |
switch(option){ | |
case 'f': | |
letter = wrap(letter+1, 1, 4); | |
break; | |
case 'l': | |
level = wrap(level+1, 1, 3); | |
break; | |
case 'b': | |
bold = !bold; | |
break; | |
case 's': | |
size = wrap(size+1, 1, 3); | |
break; | |
case 'c': | |
newWorld(); | |
break; | |
case 'r': | |
letter = (int) (Math.random()*4) + 1; | |
bold = Math.random() < .5; | |
size = (int) (Math.random() * 3) + 1; | |
break; | |
} | |
} | |
} | |
} | |
System.out.println("All done!"); | |
} | |
private static int wrap(int num, int min, int max){ | |
int delta = max-min + 1; | |
num = (num-min) % delta; | |
return num + min; | |
} | |
private static void lineWrap(int size){ | |
int width = size * 80; | |
int xPos = t.getXPos(); | |
int yPos = t.getYPos(); | |
if (xPos + width > w.getWidth()){ | |
if (yPos + 300 > w.getHeight()){ | |
newWorld(); | |
}else{ | |
t.penUp(); | |
t.moveTo(10, yPos + 310); | |
} | |
} | |
} | |
private static void newWorld(){ | |
w = new World(WORLD_WIDTH, WORLD_HEIGHT); | |
t = new Turtle(10, 300, w); | |
} | |
private static void moveToRandomSpot(){ | |
t.penUp(); | |
int x = (int) (Math.random() * (w.getWidth() - 300)) + 10; | |
int y = (int) (Math.random() * (w.getHeight()-300)); | |
t.moveTo(x, y); | |
} | |
private static void drawLetter1(Color c, boolean bold, int size){ | |
switch(level){ | |
case 1: | |
t.draw1(c); | |
break; | |
case 2: | |
t.draw1Bold(c, bold); | |
break; | |
case 3: | |
t.draw1BoldSize(c, bold, size); | |
break; | |
default: | |
System.err.println("Level " + level + " not recognized!"); | |
} | |
} | |
private static void drawLetter2(Color c, boolean bold, int size){ | |
switch(level){ | |
case 1: | |
t.draw2(c); | |
break; | |
case 2: | |
t.draw2Bold(c, bold); | |
break; | |
case 3: | |
t.draw2BoldSize(c, bold, size); | |
break; | |
default: | |
System.err.println("Level " + level + " not recognized!"); | |
} | |
} | |
private static void drawLetter3(Color c, boolean bold, int size){ | |
switch(level){ | |
case 1: | |
t.draw3(c); | |
break; | |
case 2: | |
t.draw3Bold(c, bold); | |
break; | |
case 3: | |
t.draw3BoldSize(c, bold, size); | |
break; | |
default: | |
System.err.println("Level " + level + " not recognized!"); | |
} | |
} | |
private static void drawLetter4(Color c, boolean bold, int size){ | |
switch(level){ | |
case 1: | |
t.draw4(c); | |
break; | |
case 2: | |
t.draw4Bold(c, bold); | |
break; | |
case 3: | |
t.draw4BoldSize(c, bold, size); | |
break; | |
default: | |
System.err.println("Level " + level + " not recognized!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment