/********************************************************************* / Wheel.java / Written by Timothy M. Bailey / Started: March 31, 1998 / Updated: May 13, 1998 / / Wheel of Fortune applet for cs406 class with Dr. Roger Webster / ********************************/ import java.awt.*; import java.applet.*; import java.net.*; import java.util.*; public class Wheel extends Applet implements Runnable { TitlePanel titlePanel; PuzzlePanel puzzlePanel; PlayerPanel playerPanel; ButtonPanel buttonPanel; CardPanel cardPanel; SpinPanel spinPanel; public static final int DONE = 0; public static final int SPIN = 1; int num_puzzles = 88; int num_amounts = 30; int puzzle1, puzzle2, puzzle3, puzzle4, current_puzzle; int vowel_count, letter_count, state, vowel_bell, intro_clip; int curr_spin, gameMoney, matchMoney; int intAmount[] = new int[num_amounts]; Image titleImage, noiseImage, grayImage, pointer, guessx, guesso; Image letters[] = new Image[27]; Image Amount[] = new Image[num_amounts]; Image puzzle_images[][] = new Image[8][15]; char puzzle[][] = new char[8][15]; String puzzles[] = new String[num_puzzles]; String type[] = new String[num_puzzles]; String playerName = new String(""); AudioClip ding, wrong, start, intro, vowel, bankrupt, solve, spin; PuzzleDialog pd; Thread th; Random rand = new Random(), rand2 = new Random(); Frame f = new Frame(""); public void init() { int i, j; LoadSounds(); intro_clip = 0; intro.play(); LoadImages(); GetPuzzles(); this.setBackground(new Color(11,111,20)); LoginWindow login = new LoginWindow(f, "Wheel of Treasures", this); // pop up a window requesting the player's name titlePanel = new TitlePanel(titleImage); puzzlePanel = new PuzzlePanel(puzzle_images); playerPanel = new PlayerPanel(guessx, guesso, playerName); buttonPanel = new ButtonPanel(); cardPanel = new CardPanel(); spinPanel = new SpinPanel(Amount[0], pointer); this.add(titlePanel); this.add(puzzlePanel); this.add(playerPanel); this.add(buttonPanel); this.add(spinPanel); this.add(cardPanel); this.show(); this.repaint(); matchMoney = 0; // set the match money to $0 playerPanel.setMatchMoney(matchMoney); state = DONE; current_puzzle = puzzle1; SetupPuzzle(current_puzzle); } public void start() { // start the thread so that we are able to sleep when we need to if (th == null) { th = new Thread(this); th.start(); } } public void destroy() { // this is supposed to get rid of any windows if they happen to be around try { if (pd.isVisible()) { pd.hide(); pd.dispose(); } } catch (NullPointerException ex) {} } public void run() { } public void paint (Graphics g) { titlePanel.repaint(); puzzlePanel.repaint(); playerPanel.repaint(); buttonPanel.repaint(); cardPanel.repaint(); spinPanel.repaint(); } public void LoadImages() { int i, j; char ch; URL docBase; docBase = getDocumentBase(); MediaTracker tracker = new MediaTracker(this); titleImage = getImage(docBase, "./images/logo2.jpg"); tracker.addImage(titleImage,0); noiseImage = getImage(docBase, "./images/noise.jpg"); tracker.addImage(noiseImage,0); grayImage = getImage(docBase, "./images/gray.jpg"); tracker.addImage(grayImage,0); pointer = getImage(docBase, "./images/pointer.jpg"); tracker.addImage(pointer,0); guessx = getImage(docBase, "./images/guessx.jpg"); tracker.addImage(guessx,0); guesso = getImage(docBase, "./images/guesso.jpg"); tracker.addImage(guesso,0); // load the wheel images Amount[0] = getImage(docBase, "./images/100.jpg"); intAmount[0] = 100; Amount[1] = getImage(docBase, "./images/200.jpg"); intAmount[1] = 200; Amount[2] = getImage(docBase, "./images/250.jpg"); intAmount[2] = 250; Amount[3] = getImage(docBase, "./images/300.jpg"); intAmount[3] = 300; Amount[4] = getImage(docBase, "./images/350.jpg"); intAmount[4] = 350; Amount[5] = getImage(docBase, "./images/400.jpg"); intAmount[5] = 400; Amount[6] = getImage(docBase, "./images/450.jpg"); intAmount[6] = 450; Amount[7] = getImage(docBase, "./images/500.jpg"); intAmount[7] = 500; Amount[8] = getImage(docBase, "./images/750.jpg"); intAmount[8] = 750; Amount[9] = getImage(docBase, "./images/1000.jpg"); intAmount[9] = 1000; Amount[10] = getImage(docBase, "./images/1250.jpg"); intAmount[10] = 1250; Amount[11] = getImage(docBase, "./images/1500.jpg"); intAmount[11] = 1500; Amount[12] = getImage(docBase, "./images/2000.jpg"); intAmount[12] = 2000; Amount[13] = getImage(docBase, "./images/2500.jpg"); intAmount[13] = 2500; Amount[14] = getImage(docBase, "./images/bankrupt.jpg"); intAmount[14] = -1; Amount[15] = getImage(docBase, "./images/lose_a_turn.jpg"); intAmount[15] = 0; // the next few lines adds more aof the lower amounts into the array of amounts. // this improves the probablitity of gettting the lower dollar amounts Amount[16] = Amount[0]; intAmount[16] = intAmount[0]; Amount[17] = Amount[0]; intAmount[17] = intAmount[0]; Amount[18] = Amount[1]; intAmount[18] = intAmount[1]; Amount[19] = Amount[1]; intAmount[19] = intAmount[1]; Amount[20] = Amount[2]; intAmount[20] = intAmount[2]; Amount[21] = Amount[2]; intAmount[21] = intAmount[2]; Amount[22] = Amount[3]; intAmount[22] = intAmount[3]; Amount[23] = Amount[3]; intAmount[23] = intAmount[3]; Amount[24] = Amount[4]; intAmount[24] = intAmount[4]; Amount[25] = Amount[5]; intAmount[25] = intAmount[5]; Amount[26] = Amount[6]; intAmount[26] = intAmount[6]; Amount[27] = Amount[7]; intAmount[27] = intAmount[7]; Amount[28] = Amount[14]; intAmount[28] = intAmount[14]; Amount[29] = Amount[15]; intAmount[29] = intAmount[15]; for (i=0; i<=15; i++) { tracker.addImage(Amount[i],0); } for (ch='a', i=0; ch<='z'; ch++, i++) { letters[i] = getImage(docBase, "./images/"+ch+".jpg"); tracker.addImage(letters[i], 0); } letters[i] = getImage(docBase, "./images/apos.jpg"); tracker.addImage(letters[i], 0); try { tracker.waitForID(0); } catch(InterruptedException e) { e.printStackTrace(); } } public void LoadSounds() { ding = getAudioClip(getCodeBase(), "./sounds/letter.au"); wrong = getAudioClip(getCodeBase(), "./sounds/wrong.au"); intro = getAudioClip(getCodeBase(), "./sounds/intro.au"); start = getAudioClip(getCodeBase(), "./sounds/start.au"); vowel = getAudioClip(getCodeBase(), "./sounds/vowel.au"); bankrupt = getAudioClip(getCodeBase(), "./sounds/bankrupt.au"); solve = getAudioClip(getCodeBase(), "./sounds/solve.au"); spin = getAudioClip(getCodeBase(), "./sounds/spin.au"); } public void GetPuzzles() { // if this game were being done on a server, these puzzles could be in a flat // file. The random routine could also be done there, with only the selected // puzzles being sent to the client. puzzles[0] = "game over hit shift and reload to start a new game."; type[0] = "Phrase"; puzzles[1] = "all roads lead to rome."; type[1] = "Phrase"; puzzles[2] = "most likely to succeed."; type[2] = "Phrase"; puzzles[3] = "christmas dinner with all the trimmings."; type[3] = "Phrase"; puzzles[4] = "six to one half a dozen to the other."; type[4] = "Phrase"; puzzles[5] = "throwing the baby out with the bath water."; type[5] = "Phrase"; puzzles[6] = "counting your chickens before they've hatched."; type[6] = "Phrase"; puzzles[7] = "as the crow flies."; type[7] = "Phrase"; puzzles[8] = "beating a dead horse."; type[8] = "Phrase"; puzzles[9] = "comparing apples and oranges."; type[9] = "Phrase"; puzzles[10] = "politics makes for strange bedfellows."; type[10] = "Phrase"; puzzles[11] = "indiana jones and the last crusade."; type[11] = "Title"; puzzles[12] = "doctor jekyll and mister hyde."; type[12] = "Title"; puzzles[13] = "the hunchback of notre dame."; type[13] = "Title"; puzzles[14] = "late night with david letterman."; type[14] = "Title"; puzzles[15] = "a christmas carol."; type[15] = "Title"; puzzles[16] = "the three musketeers."; type[16] = "Title"; puzzles[17] = "the gift of the magi."; type[17] = "Title"; puzzles[18] = "monty python and the holy grail."; type[18] = "Title"; puzzles[19] = "the adventures of huckleberry finn."; type[19] = "Title"; puzzles[20] = "the catcher in the rye."; type[20] = "Title"; puzzles[21] = "college dormitory."; type[21] = "Place"; puzzles[22] = "international airport."; type[22] = "Place"; puzzles[23] = "seattle washington."; type[23] = "Place"; puzzles[24] = "notre dame university."; type[24] = "Place"; puzzles[25] = "showboat casino in atlantic city."; type[25] = "Place"; puzzles[26] = "madison square garden."; type[26] = "Place"; puzzles[27] = "london england."; type[27] = "Place"; puzzles[28] = "mount rushmore."; type[28] = "Place"; puzzles[29] = "the canary islands."; type[29] = "Place"; puzzles[30] = "the sea of tranquility."; type[30] = "Place"; puzzles[31] = "country singer garth brooks."; type[31] = "Person"; puzzles[32] = "philadelphia flyers."; type[32] = "People"; puzzles[33] = "chevy chase."; type[33] = "Person"; puzzles[34] = "the people's court judge ed koch."; type[34] = "Person"; puzzles[35] = "gossip columnist liz smith."; type[35] = "Person"; puzzles[36] = "winston churchill."; type[36] = "Person"; puzzles[37] = "ernest hemingway."; type[37] = "Person"; puzzles[38] = "tarzan king of the apes."; type[38] = "Person"; puzzles[39] = "king henry the eighth."; type[39] = "Person"; puzzles[40] = "carly simon and garfunkle."; type[40] = "Before & After"; puzzles[41] = "chemistry teacher."; type[41] = "Occupation"; puzzles[42] = "washington monument."; type[42] = "Landmark"; puzzles[43] = "bottled water under the bridge."; type[43] = "Before & After"; puzzles[44] = "periodic table manners."; type[44] = "Before & After"; puzzles[45] = "children of the corn tortillas."; type[45] = "Before & After"; puzzles[46] = "greco roman wrestling."; type[46] = "Event"; puzzles[47] = "papal bull fighter."; type[47] = "Before & After"; puzzles[48] = "give me liberty or give me death."; type[48] = "Quotation"; puzzles[49] = "pat and daniel boone."; type[49] = "Same Name"; puzzles[50] = "lookout point of no return."; type[50] = "Before & After"; puzzles[51] = "pumpkin pie with whipped cream."; type[51] = "Things"; puzzles[52] = "apple macintosh computer."; type[52] = "Thing"; puzzles[53] = "chevrolet cavalier."; type[53] = "Thing"; puzzles[54] = "three piece suit."; type[54] = "Thing"; puzzles[55] = "four leaf clover."; type[55] = "Thing"; puzzles[56] = "the loch ness monster."; type[56] = "Thing"; puzzles[57] = "ninety mile an hour fastball."; type[57] = "Thing"; puzzles[58] = "internal combustion engine."; type[58] = "Thing"; puzzles[59] = "the great wall of china."; type[59] = "Thing"; puzzles[60] = "the stanley cup."; type[60] = "Thing"; puzzles[61] = "beggars can't be choosers."; type[61] = "Phrase"; puzzles[62] = "the only thing we have to fear is fear itself."; type[62] = "Quotation"; puzzles[63] = "oh my god the cubs win the pennant."; type[63] = "Quotation"; puzzles[64] = "four score and seven years ago."; type[64] = "Quotation"; puzzles[65] = "winona ryder truck."; type[65] = "Before & After"; puzzles[66] = "filing for bankruptcy."; type[66] = "Event"; puzzles[67] = "gold rush limbaugh."; type[67] = "Before & After"; puzzles[68] = "bud abbott and lou costello."; type[68] = "People"; puzzles[69] = "to be or not to be that is the question."; type[69] = "Quotation"; puzzles[70] = "go ahead make my day."; type[70] = "Quotation"; puzzles[71] = "stuck between a rock and a hard place."; type[71] = "Phrase"; puzzles[72] = "stuck in the middle with you."; type[72] = "Title"; puzzles[73] = "i get by with a little help from my friends."; type[73] = "Quotation"; puzzles[74] = "frankly scarlett i don't give a damn."; type[74] = "Quotation"; puzzles[75] = "little shop of horrors."; type[75] = "Title"; puzzles[76] = "supermodel kathy ireland."; type[76] = "Person"; puzzles[77] = "to bite off your nose to spite your face."; type[77] = "Phrase"; puzzles[78] = "can't see the forest for the trees."; type[78] = "Phrase"; puzzles[79] = "whipped cream of wheat."; type[79] = "Before & After"; puzzles[80] = "wealth of nations."; type[80] = "Title"; puzzles[81] = "communist manifesto."; type[81] = "Title"; puzzles[82] = "gone with the wind."; type[82] = "Title"; puzzles[83] = "a coney island hot dog."; type[83] = "Thing"; puzzles[84] = "falling asleep on the job."; type[84] = "Phrase"; puzzles[85] = "one flew over the cuckoo's nest."; type[85] = "Title"; puzzles[86] = "alfred hitchcock."; type[86] = "Person"; puzzles[87] = "twenty thousand leagues under the sea."; type[87] = "Title"; int nextPuzzle; // do random selection here. nextPuzzle = rand2.nextInt() % num_puzzles; // if the random number is negative, invert it if (nextPuzzle < 0) { nextPuzzle *= -1; } // if the puzzle is 0, pick another -- 0 is for the end of the game while (nextPuzzle == 0) { nextPuzzle = rand2.nextInt() % num_puzzles; if (nextPuzzle < 0) { nextPuzzle *= -1; } } puzzle1 = nextPuzzle; nextPuzzle = rand2.nextInt() % num_puzzles; if (nextPuzzle < 0) { nextPuzzle *= -1; } // if the puzzle is 0 or the same as the first, pick another while ((nextPuzzle == puzzle1) || (nextPuzzle == 0)) { nextPuzzle = rand2.nextInt() % num_puzzles; if (nextPuzzle < 0) { nextPuzzle *= -1; } } puzzle2 = nextPuzzle; nextPuzzle = rand2.nextInt() % num_puzzles; if (nextPuzzle < 0) { nextPuzzle *= -1; } // if the puzzle is 0, or the same as puzzle1 or puzzle2, pick another while ((nextPuzzle == puzzle1) || (nextPuzzle == puzzle2) || (nextPuzzle == 0)) { nextPuzzle = rand2.nextInt() % num_puzzles; if (nextPuzzle < 0) { nextPuzzle *= -1; } } puzzle3 = nextPuzzle; puzzle4 = 0; } public void SetupPuzzle(int puzzle_number) { char ch, word[] = new char[15]; int len, temp_count; int i, j, x, y; // clear the player panel of any garbage and reset the count playerPanel.spinWorth = ""; playerPanel.letterCount = ""; playerPanel.resetGuess(); playerPanel.repaint(); // if this is the first puzzle, make sure intro won't play anymore if (intro_clip == 0) { try { th.sleep(17000); intro_clip = 1; } catch (InterruptedException e) {} } // turn all letters into noise images to "clear" board for (i=0; i<8; i++) { for (j=0; j<15; j++) { puzzle_images[i][j] = noiseImage; puzzle[i][j] = ' '; } } puzzlePanel.repaint(); vowel_count = 0; letter_count = 0; vowel_bell = 0; // show the type of puzzle puzzlePanel.puzzleType = type[puzzle_number]; // layout the puzzle -- no words spanning 2 lines, etc. semi-complex algorithm x = 0; y = 0; temp_count = 0; len = puzzles[puzzle_number].length(); for (i=0; i (15-x)) { x = 0; y++; } for (int w=x; w 5) { count = 5; } repaint(); return count; } void resetGuess() { // start of new puzzle, therefore five new chances count = 0; } } /********************************************************************* / ButtonPanel / Written by Timothy M. Bailey / / draws four buttons: spin, show letters, show vowels, and solve / ********************************/ class ButtonPanel extends Panel { Button spinButton, letterButton, vowelButton, solveButton; public ButtonPanel() { this.setLayout(new GridLayout(4,1)); spinButton = new Button("Spin"); letterButton = new Button("Show Letters"); vowelButton = new Button("Show Vowels"); solveButton = new Button("Solve"); spinButton.setBackground(Color.yellow); letterButton.setBackground(Color.yellow); vowelButton.setBackground(Color.yellow); solveButton.setBackground(Color.yellow); this.add(spinButton); this.add(letterButton); this.add(vowelButton); this.add(solveButton); this.show(); } public void paint (Graphics g) { this.reshape(10, 425, 100, 150); } } /********************************************************************* / SpinPanel / Written by Timothy M. Bailey / / draws the image of the wheel / ********************************/ class SpinPanel extends Panel { Image amount, pointer; public SpinPanel(Image fore, Image point) { this.amount = fore; this.pointer = point; } public void destroy() { // i don't think this quite works amount = null; pointer = null; this.repaint(); } public void paint (Graphics g) { this.reshape(140, 425, 123, 110); g.drawImage(pointer, 0, 0, 123, 10, this); g.drawImage(amount, 0, 10, 123, 100, this); this.show(); } public void spin(Image fore) { this.amount = fore; this.repaint(); } } /********************************************************************* / CardPanel / Written by Timothy M. Bailey / / this panel contains three cards: letters, vowels, and solve. / since the player can only do one of these three things at / a time, cardLayout seemed the best option. / ********************************/ class CardPanel extends Panel { public Panel cards; CardLayout cardLayout; public Panel spinWheel, chooseVowel, solvePuzzle; TextField solveField; Label solveLabel; Button solve; Button b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y, z; Button a, e, i, o, u; public CardPanel() { this.setLayout(new BorderLayout()); cards = new Panel(); cardLayout = new CardLayout(); cards.setLayout(cardLayout); spinWheel = new Panel(); spinWheel.setLayout(new GridLayout(3, 7)); b = new Button("B"); c = new Button("C"); d = new Button("D"); f = new Button("F"); g = new Button("G"); h = new Button("H"); j = new Button("J"); k = new Button("K"); l = new Button("L"); m = new Button("M"); n = new Button("N"); p = new Button("P"); q = new Button("Q"); r = new Button("R"); s = new Button("S"); t = new Button("T"); v = new Button("V"); w = new Button("W"); x = new Button("X"); y = new Button("Y"); z = new Button("Z"); b.setBackground(Color.yellow); c.setBackground(Color.yellow); d.setBackground(Color.yellow); f.setBackground(Color.yellow); g.setBackground(Color.yellow); h.setBackground(Color.yellow); j.setBackground(Color.yellow); k.setBackground(Color.yellow); l.setBackground(Color.yellow); m.setBackground(Color.yellow); n.setBackground(Color.yellow); p.setBackground(Color.yellow); q.setBackground(Color.yellow); r.setBackground(Color.yellow); s.setBackground(Color.yellow); t.setBackground(Color.yellow); v.setBackground(Color.yellow); w.setBackground(Color.yellow); x.setBackground(Color.yellow); y.setBackground(Color.yellow); z.setBackground(Color.yellow); spinWheel.add(b); spinWheel.add(c); spinWheel.add(d); spinWheel.add(f); spinWheel.add(g); spinWheel.add(h); spinWheel.add(j); spinWheel.add(k); spinWheel.add(l); spinWheel.add(m); spinWheel.add(n); spinWheel.add(p); spinWheel.add(q); spinWheel.add(r); spinWheel.add(s); spinWheel.add(t); spinWheel.add(v); spinWheel.add(w); spinWheel.add(x); spinWheel.add(y); spinWheel.add(z); cards.add("Spin", spinWheel); chooseVowel = new Panel(); chooseVowel.setLayout(new GridLayout(1,5)); a = new Button("A"); e = new Button("E"); i = new Button("I"); o = new Button("O"); u = new Button("U"); a.setBackground(Color.yellow); e.setBackground(Color.yellow); i.setBackground(Color.yellow); o.setBackground(Color.yellow); u.setBackground(Color.yellow); chooseVowel.add(a); chooseVowel.add(e); chooseVowel.add(i); chooseVowel.add(o); chooseVowel.add(u); cards.add("Vowel", chooseVowel); solvePuzzle = new Panel(); solvePuzzle.setLayout(new BorderLayout()); solveLabel = new Label("Solve the puzzle:", Label.CENTER); solveLabel.setFont(new Font("TimesRoman", Font.BOLD, 18)); solvePuzzle.add("North", solveLabel); solve = new Button("Click Here When Done"); solvePuzzle.add("South", solve); solveField = new TextField("", 50); solveField.setFont(new Font("TimesRoman", Font.PLAIN, 18)); solvePuzzle.add("Center", solveField); cards.add("Solve", solvePuzzle); this.add("Center", cards); } public void paint (Graphics g) { this.reshape(300, 425, 500, 150); } } /********************************************************************* / PuzzleDialog / Written by Timothy M. Bailey / / This class is used for popping up a dialog box with info that is / pertinant to the game. / ********************************/ class PuzzleDialog extends Dialog { protected Button close; public PuzzleDialog(Frame parent, String title, String mesg) { //Instantiate variables super(parent, title, true); Label return_message = new Label(mesg); this.add("Center", return_message); Panel panelButton = new Panel(); close = new Button("OK"); panelButton.add(close); this.add("South", panelButton); //Size window to preferred size this.pack(); this.reshape(300, 425, 400, 150); this.move(300, 425); } //end PuzzleDialog(Frame, String, String) public boolean action(Event e, Object arg){ if(e.target == close){ this.hide(); this.dispose(); return true; } else { return false; } } //end action(Event, Object) }//end class definition