001: package example;
002:
003: import com.caucho.util.L10N;
004: import java.util.logging.Logger;
005: import java.util.logging.Level;
006:
007: import java.util.Random;
008: import java.util.HashMap;
009:
010: /**
011: * Professor Trelawney's magic 8 ball.
012: * The magic 8 ball will return a prophecy with getProphecy().
013: *
014: * <p>The default prophet is Professor Trelawney (of course). If you wish to
015: * change the prophet that provides the answer, use
016: * setProphet(name), where name is one of "trelawney", "classic", or "kingwu".
017: */
018: public class Magic8Ball {
019: static protected final Logger log = Logger
020: .getLogger(Magic8Ball.class.getName());
021: static final L10N L = new L10N(Magic8Ball.class);
022:
023: private final static String DEFAULT_PROPHET = "trelawney";
024:
025: private Random _random = new Random();
026:
027: private String _prophet = DEFAULT_PROPHET;
028:
029: private HashMap _prophets = new HashMap();
030:
031: public Magic8Ball() {
032: _prophets.put("trelawney", new String[] {
033: "The future for you is very dire",
034: "Within a fortnight you will surely die",
035: "Grave trouble awaits you",
036: "You must not leave the room",
037: "The stars are aligned for grave injury", });
038: _prophets.put("classic",
039: new String[] {
040:
041: "Signs point to yes", "Yes", "Reply hazy, try again",
042: "Without a doubt", "My sources say no",
043: "As I see it, yes", "You may rely on it",
044: "Concentrate and ask again",
045: "Outlook not so good", "It is decidedly so",
046: "Better not tell you now", "Very doubtful",
047: "Yes - definitely", "It is certain",
048: "Cannot predict now", "Most likely",
049: "Ask again later", "My reply is no",
050: "Outlook good", "Don't count on it", });
051: _prophets
052: .put(
053: "kingwu",
054: new String[] {
055: "THE CREATIVE works sublime success, Furthering through perseverance.",
056: "THE RECEPTIVE brings about sublime success, Furthering through the perseverance of a mare. If the superior man undertakes something and tries to lead, He goes astray; But if he follows, he finds guidance. It is favorable to find friends in the west and south, To forego friends in the east and north. Quiet perseverance brings good fortune.",
057: "DIFFICULTY AT THE BEGINNING works supreme success, Furthering through perseverance. Nothing should be undertaken. It furthers one to appoint helpers.",
058: "YOUTHFUL FOLLY has success. It is not I who seek the young fool; The young fool seeks me. At the first oracle I inform him. If he asks two or three times, it is importunity. If he importunes, I give him no information. Perseverance furthers.",
059: "WAITING. If you are sincere, You have light and success. Perseverance brings good fortune. It furthers one to cross the great water.",
060: "CONFLICT. You are sincere And are being obstructed. A cautious halt halfway brings good fortune. Going through to the end brings misfortune. It furthers one to see the great man. It does not further one to cross the great water.",
061: "THE ARMY. The army needs perseverance And a strong man. Good fortune without blame.",
062: "HOLDING TOGETHER brings good fortune. Inquire of the oracle once again Whether you possess sublimity, constancy, and perseverance; Then there is no blame. Those who are uncertain gradually join. Whoever come too late Meets with misfortune.",
063: "THE TAMING POWER OF THE SMALL Has success. Dense clouds, no rain from our western region. ",
064: "TREADING. Treading upon the tail of the tiger. It does not bite the man. Success.",
065: "PEACE. The small departs, The great approaches. Good fortune. Success.",
066: "STANDSTILL. Evil people do not further The perseverance of the superior man. The great departs; the small approaches.",
067: "FELLOWSHIP WITH MEN in the open. Success. It furthers one to cross the great water. The perseverance of the superior man furthers.",
068: "POSSESSION IN GREAT MEASURE. Supreme success.",
069: "MODESTY creates success. The superior man carries things through.",
070: "ENTHUSIASM. It furthers one to install helpers And to set armies marching.",
071: "FOLLOWING has supreme success. Perseverance furthers. No blame.",
072: "WORK ON WHAT HAS BEEN SPOILED Has supreme success. It furthers one to cross the great water. Before the starting point, three days. After the starting point, three days.",
073: "APPROACH has supreme success. Perseverance furthers. When the eighth month comes, There will be misfortune.",
074: "CONTEMPLATION. The ablution has been made, But not yet the offering. Full of trust they look up to him.",
075: "BITING THROUGH has success. It is favorable to let justice be administered.",
076: "GRACE has success. In small matters It is favorable to undertake something.",
077: "SPLITTING APART. IT does not further one To go anywhere.",
078: "RETURN. Success. Going out and coming in without error. Friends come without blame. To and fro goes the way. On the seventh day comes return. It furthers one to have somewhere to go.",
079: "INNOCENCE. Supreme success. Perseverance furthers. If someone is not as he should be, He has misfortune, And it does not further him To undertake anything.",
080: "THE TAMING POWER OF THE GREAT. Perseverance furthers. Not eating at home brings good fortune. It furthers one to cross the great water.",
081: "THE CORNERS OF THE MOUTH. Perseverance brings good fortune. Pay heed to the providing of nourishment And to what a man seeks To fill his own mouth with.",
082: "PREPONDERANCE OF THE GREAT. The ridgepole sags to the breaking point. It furthers one to have somewhere to go. Success.",
083: "The Abysmal repeated. If you are sincere, you have success in your heart, And whatever you do succeeds.",
084: "THE CLINGING. Perseverance furthers. It brings success. Care of the cow brings good fortune.",
085: "Influence. Success. Perseverance furthers. To take a maiden to wife brings good fortune.",
086: "DURATION. Success. No blame. Perseverance furthers. It furthers one to have somewhere to go.",
087: "RETREAT. Success. In what is small, perseverance furthers.",
088: "THE POWER OF THE GREAT. Perseverance furthers. ",
089: "PROGRESS. The powerful prince Is honored with horses in large numbers. In a single day he is granted audience three times.",
090: "DARKENING OF THE LIGHT. In adversity It furthers one to be persevering.",
091: "THE FAMILY. The perseverance of the woman furthers. ",
092: "OPPOSITION. In small matters, good fortune.",
093: "OBSTRUCTION. The southwest furthers. The northeast does not further. It furthers one to see the great man. Perseverance brings good fortune.",
094: "DELIVERANCE. The southwest furthers. If there is no longer anything where one has to go, Return brings good fortune. If there is still something where one has to go, Hastening brings good fortune.",
095: "DECREASE combined with sincerity Brings about supreme good fortune Without blame. One may be persevering in this. It furthers one to undertake something. How is this to be carried out? One may use two small bowls for the sacrifice.",
096: "INCREASE. It furthers one To undertake something. It furthers one to cross the great water.",
097: "BREAK-THROUGH. One must resolutely make the matter known At the court of the king. It must be announced truthfully. Danger. It is necessary to notify one's own city. It does not further to resort to arms. It furthers one to undertake something.",
098: "COMING TO MEET. The maiden is powerful. One should not marry such a maiden.",
099: "GATHERING TOGETHER. Success. The king approaches his temple. It furthers one to see the great man. This brings success. Perseverance furthers. To bring great offerings creates good fortune. It furthers one to undertake something.",
100: "PUSHING UPWARD has supreme success. One must see the great man. Fear not. Departure toward the south Brings good fortune.",
101: "OPPRESSION. Success. Perseverance. The great man brings about good fortune. No blame. When one has something to say, It is not believed.",
102: "THE WELL. The town may be changed, But the well cannot be changed. It neither decreases nor increases. They come and go and draw from the well. If one gets down almost to the water And the rope does not go all the way, Or the jug breaks, it brings misfortune.",
103: "REVOLUTION. On your own day You are believed. Supreme success, Furthering through perseverance. Remorse disappears.",
104: "THE CALDRON. Supreme good fortune. Success.",
105: "SHOCK brings success. Shock comes-oh, oh! Laughing words -ha, ha! The shock terrifies for a hundred miles, And he does not let fall the sacrificial spoon and chalice.",
106: "KEEPING STILL. Keeping his back still So that he no longer feels his body. He goes into his courtyard And does not see his people. No blame.",
107: "DEVELOPMENT. The maiden Is given in marriage. Good fortune. Perseverance furthers.",
108: "THE MARRYING MAIDEN. Undertakings bring misfortune. Nothing that would further.",
109: "ABUNDANCE has success. The king attains abundance. Be not sad. Be like the sun at midday.",
110: "THE WANDERER. Success through smallness. Perseverance brings good fortune To the wanderer.",
111: "THE GENTLE. Success through what is small. It furthers one to have somewhere to go. It furthers one to see the great man.",
112: "THE JOYOUS. Success. Perseverance is favorable.",
113: "DISPERSION. Success. The king approaches his temple. It furthers one to cross the great water. Perseverance furthers.",
114: "LIMITATION. Success. Galling limitation must not be persevered in.",
115: "INNER TRUTH. Pigs and fishes. Good fortune. It furthers one to cross the great water. Perseverance furthers.",
116: "PREPONDERANCE OF THE SMALL. Success. Perseverance furthers. Small things may be done; great things should not be done. The flying bird brings the message: It is not well to strive upward, It is well to remain below. Great good fortune.",
117: "AFTER COMPLETION. Success in small matters. Perseverance furthers. At the beginning good fortune. At the end disorder.",
118: "BEFORE COMPLETION. Success. But if the little fox, after nearly completing the crossing, Gets his tail in the water, There is nothing that would further.", });
119: }
120:
121: /**
122: * Set the prophet to use.
123: */
124: public void setProphet(String prophet) {
125: if (prophet == null)
126: _prophet = DEFAULT_PROPHET;
127: else
128: _prophet = prophet;
129: }
130:
131: /**
132: * Get the prophet that will be used.
133: */
134: public String getProphet() {
135: return _prophet;
136: }
137:
138: /**
139: * Get a prophecy.
140: */
141: public String getProphecy() {
142: String[] prophecies = (String[]) _prophets.get(_prophet);
143:
144: if (prophecies == null) {
145: return "a false prophet is never wise";
146: } else {
147: int i = _random.nextInt(prophecies.length);
148: return prophecies[i];
149: }
150: }
151: }
|