-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeiferGenerator.java
More file actions
127 lines (107 loc) · 4.45 KB
/
HeiferGenerator.java
File metadata and controls
127 lines (107 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.lang.reflect.Constructor;
import java.io.FileFilter;
import java.io.File;
public class HeiferGenerator
{
static class HeiferFilter implements FileFilter
{
public boolean accept(File path)
{
String filename = path.getName();
try
{
return filename.substring(filename.lastIndexOf(".") + 1).toLowerCase().equals("cow");
}
catch (Exception e)
{
return false;
}
}
}
public static Cow[] getFileCows()
{
if (fileCows == null)
{
File[] fileCowList = new File("cows").listFiles(new HeiferFilter());
fileCows = new Cow[fileCowList.length];
// Add file cows
for (int index = 0; index < fileCows.length; index++)
{
String filename = fileCowList[index].getName();
String cowName = filename.substring(0, filename.lastIndexOf("."));
fileCows[index] = new FileCow(cowName, "cows" + File.separator + filename);
}
}
return fileCows;
}
public static Cow[] getCows()
{
if (cows == null)
{
cows = new Cow[cowNames.length + dragonNames.length];
// Add the "regular" cows
for (int index = 0; index < cowNames.length; index++)
{
cows[index] = new Cow(cowNames[index]);
cows[index].setImage(quoteLines + cowImages[index]);
}
// Add the dragons
for (int offset = cowNames.length, index = 0; index < dragonNames.length; index++)
{
try
{
@SuppressWarnings("unchecked")
Constructor<Cow> constructor = dragonTypes[index].getConstructor(String.class, String.class);
cows[offset + index] = constructor.newInstance(dragonNames[index], quoteLines + dragonImage);
}
catch (Exception ignored) { }
}
}
return cows;
}
public static void addCow(Cow newMoo)
{
Cow[] oldCows = cows;
if (oldCows == null)
cows = new Cow[1];
else
cows = new Cow[oldCows.length + 1];
for (int index = 0; index < oldCows.length; index++)
cows[index] = oldCows[index];
cows[oldCows.length] = newMoo;
}
// Hard-coded values for some of the cows
private static String[] cowNames = { "heifer", "kitteh" };
private static String quoteLines = " \\\n" +
" \\\n" +
" \\\n";
private static String[] cowImages = { " ^__^\n" +
" (oo)\\_______\n" +
" (__)\\ )\\/\\\n" +
" ||----w |\n" +
" || ||\n",
" (\"`-' '-/\") .___..--' ' \"`-._\n" +
" ` *_ * ) `-. ( ) .`-.__. `)\n" +
" (_Y_.) ' ._ ) `._` ; `` -. .-'\n" +
" _.. `--'_..-_/ /--' _ .' ,4\n" +
" ( i l ),-'' ( l i),' ( ( ! .-'\n"
};
private static String[] dragonNames = { "dragon", "ice-dragon" };
private static Class[] dragonTypes = { Dragon.class, IceDragon.class };
private static String dragonImage = " |\\___/| /\\ //|\\\\\n" +
" /0 0 \\__ / \\// | \\ \\\n" +
" / / \\/_ / // | \\ \\\n" +
" \\_^_\\'/ \\/_ // | \\ \\\n" +
" //_^_/ \\/_ // | \\ \\\n" +
" ( //) | \\ // | \\ \\\n" +
" ( / /) _|_ / ) // | \\ _\\\n" +
" ( // /) '/,_ _ _/ ( ; -. | _ _\\.-~ .-~~~^-.\n" +
" (( / / )) ,-{ _ `.|.-~-. .~ `.\n" +
"(( // / )) '/\\ / ~-. _.-~ .-~^-. \\\n" +
"(( /// )) `. { } / \\ \\\n" +
" (( / )) .----~-.\\ \\-' .~ \\ `. __\n" +
" ///.----..> \\ _ -~ `. ^-` \\\n" +
" ///-._ _ _ _ _ _ _}^ - - - - ~ `-----'\n";
private static Cow[] cows = null;
private static Cow[] fileCows = null;
}